test(ivy): enable more docs examples e2e tests (#28688)

PR Close #28688
This commit is contained in:
Marc Laval 2019-02-13 14:37:43 +01:00 committed by Miško Hevery
parent 73f9db53c2
commit 6a7fd70ddf

View File

@ -15,11 +15,25 @@ const PROTRACTOR_CONFIG_FILENAME = path.join(__dirname, './shared/protractor.con
const SJS_SPEC_FILENAME = 'e2e-spec.ts'; const SJS_SPEC_FILENAME = 'e2e-spec.ts';
const CLI_SPEC_FILENAME = 'e2e/src/app.e2e-spec.ts'; const CLI_SPEC_FILENAME = 'e2e/src/app.e2e-spec.ts';
const EXAMPLE_CONFIG_FILENAME = 'example-config.json'; const EXAMPLE_CONFIG_FILENAME = 'example-config.json';
const IGNORED_EXAMPLES = [ // temporary ignores const IGNORED_EXAMPLES = [
// temporary ignores
'quickstart', 'quickstart',
'setup', 'setup',
]; ];
const fixmeIvyExamples = [
// fixmeIvy('unknown') version value goes undefined when clicking Major button after clicking
// Minor button twice
'component-interaction',
// fixmeIvy('unknown') failed content projection and applied styles
'component-styles',
// fixmeIvy('unknown') ERROR Error: Unable to find context associated with [object
// HTMLInputElement]
'http',
// fixmeIvy('unknown') app fails at runtime due to missing external service (goog is undefined)
'i18n'
];
/** /**
* Run Protractor End-to-End Tests for Doc Samples * Run Protractor End-to-End Tests for Doc Samples
* *
@ -58,7 +72,8 @@ function runE2e() {
if (status.failed.length > 0) { if (status.failed.length > 0) {
return Promise.reject('Some test suites failed'); return Promise.reject('Some test suites failed');
} }
}).catch(function (e) { })
.catch(function(e) {
console.log(e); console.log(e);
process.exitCode = 1; process.exitCode = 1;
}); });
@ -67,7 +82,6 @@ function runE2e() {
// Finds all of the *e2e-spec.tests under the examples folder along with the corresponding apps // Finds all of the *e2e-spec.tests under the examples folder along with the corresponding apps
// that they should run under. Then run each app/spec collection sequentially. // that they should run under. Then run each app/spec collection sequentially.
function findAndRunE2eTests(filter, outputFile, shard) { function findAndRunE2eTests(filter, outputFile, shard) {
const shardParts = shard ? shard.split('/') : [0, 1]; const shardParts = shard ? shard.split('/') : [0, 1];
const shardModulo = parseInt(shardParts[0], 10); const shardModulo = parseInt(shardParts[0], 10);
const shardDivider = parseInt(shardParts[1], 10); const shardDivider = parseInt(shardParts[1], 10);
@ -93,7 +107,9 @@ function findAndRunE2eTests(filter, outputFile, shard) {
console.log(`E2e specs for shard ${shardParts.join('/')}:`); console.log(`E2e specs for shard ${shardParts.join('/')}:`);
logSpecs(e2eSpecPaths); logSpecs(e2eSpecPaths);
return e2eSpecPaths.systemjs.reduce((promise, specPath) => { return e2eSpecPaths.systemjs
.reduce(
(promise, specPath) => {
return promise.then(() => { return promise.then(() => {
const examplePath = path.dirname(specPath); const examplePath = path.dirname(specPath);
return runE2eTestsSystemJS(examplePath, outputFile).then(ok => { return runE2eTestsSystemJS(examplePath, outputFile).then(ok => {
@ -101,7 +117,8 @@ function findAndRunE2eTests(filter, outputFile, shard) {
arr.push(examplePath); arr.push(examplePath);
}); });
}); });
}, Promise.resolve()) },
Promise.resolve())
.then(() => { .then(() => {
return e2eSpecPaths.cli.reduce((promise, specPath) => { return e2eSpecPaths.cli.reduce((promise, specPath) => {
return promise.then(() => { return promise.then(() => {
@ -152,12 +169,13 @@ function runProtractorSystemJS(prepPromise, appDir, appRunSpawnInfo, outputFile)
// Start protractor. // Start protractor.
console.log(`\n\n=========== Running aio example tests for: ${appDir}`); console.log(`\n\n=========== Running aio example tests for: ${appDir}`);
const spawnInfo = spawnExt('yarn', ['protractor', const spawnInfo = spawnExt(
PROTRACTOR_CONFIG_FILENAME, 'yarn',
`--specs=${specFilename}`, [
'--params.appDir=' + appDir, 'protractor', PROTRACTOR_CONFIG_FILENAME, `--specs=${specFilename}`,
'--params.outputFile=' + outputFile '--params.appDir=' + appDir, '--params.outputFile=' + outputFile
], { cwd: SHARED_PATH }); ],
{cwd: SHARED_PATH});
spawnInfo.proc.stderr.on('data', function(data) { spawnInfo.proc.stderr.on('data', function(data) {
transpileError = transpileError || /npm ERR! Exit status 100/.test(data.toString()); transpileError = transpileError || /npm ERR! Exit status 100/.test(data.toString());
@ -173,8 +191,7 @@ function runProtractorSystemJS(prepPromise, appDir, appRunSpawnInfo, outputFile)
}) })
.then( .then(
function() { return finish(appRunSpawnInfo.proc.pid, true); }, function() { return finish(appRunSpawnInfo.proc.pid, true); },
function () { return finish(appRunSpawnInfo.proc.pid, false); } function() { return finish(appRunSpawnInfo.proc.pid, false); });
);
} }
function finish(spawnProcId, ok) { function finish(spawnProcId, ok) {
@ -206,7 +223,11 @@ function runE2eTestsCLI(appDir, outputFile) {
console.log(`\n\n=========== Running aio example tests for: ${appDir}`); console.log(`\n\n=========== Running aio example tests for: ${appDir}`);
// `--no-webdriver-update` is needed to preserve the ChromeDriver version already installed. // `--no-webdriver-update` is needed to preserve the ChromeDriver version already installed.
const config = loadExampleConfig(appDir); const config = loadExampleConfig(appDir);
<<<<<<< HEAD
const commands = config.e2e || [{cmd: 'yarn', args: ['e2e', '--no-webdriver-update']}]; const commands = config.e2e || [{cmd: 'yarn', args: ['e2e', '--no-webdriver-update']}];
=======
const commands = config.e2e || [{cmd: 'yarn', args: ['e2e', '--prod', '--no-webdriver-update']}];
>>>>>>> c8a0ce7388... test(ivy): enable more docs examples e2e tests (#28688)
const e2eSpawnPromise = commands.reduce((prevSpawnPromise, {cmd, args}) => { const e2eSpawnPromise = commands.reduce((prevSpawnPromise, {cmd, args}) => {
return prevSpawnPromise.then(() => { return prevSpawnPromise.then(() => {
@ -218,25 +239,27 @@ function runE2eTestsCLI(appDir, outputFile) {
}, Promise.resolve()); }, Promise.resolve());
return e2eSpawnPromise.then( return e2eSpawnPromise.then(
() => { fs.appendFileSync(outputFile, `Passed: ${appDir}\n\n`); return true; }, () => {
() => { fs.appendFileSync(outputFile, `Failed: ${appDir}\n\n`); return false; }); fs.appendFileSync(outputFile, `Passed: ${appDir}\n\n`);
return true;
},
() => {
fs.appendFileSync(outputFile, `Failed: ${appDir}\n\n`);
return false;
});
} }
// Report final status. // Report final status.
function reportStatus(status, outputFile) { function reportStatus(status, outputFile) {
let log = ['']; let log = [''];
log.push('Suites passed:'); log.push('Suites passed:');
status.passed.forEach(function (val) { status.passed.forEach(function(val) { log.push(' ' + val); });
log.push(' ' + val);
});
if (status.failed.length == 0) { if (status.failed.length == 0) {
log.push('All tests passed'); log.push('All tests passed');
} else { } else {
log.push('Suites failed:'); log.push('Suites failed:');
status.failed.forEach(function (val) { status.failed.forEach(function(val) { log.push(' ' + val); });
log.push(' ' + val);
});
} }
log.push('\nElapsed time: ' + status.elapsedTime + ' seconds'); log.push('\nElapsed time: ' + status.elapsedTime + ' seconds');
log = log.join('\n'); log = log.join('\n');
@ -257,12 +280,8 @@ function spawnExt(command, args, options, ignoreClose = false) {
reject(e); reject(e);
return {proc: null, promise}; return {proc: null, promise};
} }
proc.stdout.on('data', function (data) { proc.stdout.on('data', function(data) { process.stdout.write(data.toString()); });
process.stdout.write(data.toString()); proc.stderr.on('data', function(data) { process.stdout.write(data.toString()); });
});
proc.stderr.on('data', function (data) {
process.stdout.write(data.toString());
});
proc.on('close', function(returnCode) { proc.on('close', function(returnCode) {
console.log(`completed: ${descr} \n`); console.log(`completed: ${descr} \n`);
// Many tasks (e.g., tsc) complete but are actually errors; // Many tasks (e.g., tsc) complete but are actually errors;
@ -281,42 +300,45 @@ function spawnExt(command, args, options, ignoreClose = false) {
function getE2eSpecs(basePath, filter) { function getE2eSpecs(basePath, filter) {
let specs = {}; let specs = {};
return getE2eSpecsFor(basePath, SJS_SPEC_FILENAME, filter).then(sjsPaths => { return getE2eSpecsFor(basePath, SJS_SPEC_FILENAME, filter)
specs.systemjs = sjsPaths; .then(sjsPaths => { specs.systemjs = sjsPaths; })
}).then(() => { .then(() => {
return getE2eSpecsFor(basePath, CLI_SPEC_FILENAME, filter).then(cliPaths => { return getE2eSpecsFor(basePath, CLI_SPEC_FILENAME, filter).then(cliPaths => {
return cliPaths.map(p => { return cliPaths.map(p => { return p.replace(`${CLI_SPEC_FILENAME}`, ''); });
return p.replace(`${CLI_SPEC_FILENAME}`, '');
}); });
}); })
}).then(cliPaths => { .then(cliPaths => { specs.cli = cliPaths; })
specs.cli = cliPaths; .then(() => specs);
}).then(() => specs);
} }
// Find all e2e specs in a given example folder. // Find all e2e specs in a given example folder.
function getE2eSpecsFor(basePath, specFile, filter) { function getE2eSpecsFor(basePath, specFile, filter) {
// Only get spec file at the example root. // Only get spec file at the example root.
<<<<<<< HEAD
const e2eSpecGlob = `${filter ? ` * ${filter} * ` : '*'}/${specFile}`; const e2eSpecGlob = `${filter ? ` * ${filter} * ` : '*'}/${specFile}`;
return globby(e2eSpecGlob, {cwd: basePath, nodir: true}) return globby(e2eSpecGlob, {cwd: basePath, nodir: true})
.then(paths => paths .then(
.filter(file => !IGNORED_EXAMPLES.some(ignored => file.startsWith(ignored))) paths => paths.filter(file => !IGNORED_EXAMPLES.some(ignored => file.startsWith(ignored)))
.map(file => path.join(basePath, file)) .map(file => path.join(basePath, file)));
); =======
const e2eSpecGlob = `${filter ? '*' + filter + '*' : '*'}/${specFile}`;
return globby(e2eSpecGlob, {cwd: basePath, nodir: true})
.then(
paths => paths.filter(file => !IGNORED_EXAMPLES.some(ignored => file.startsWith(ignored)))
.map(file => path.join(basePath, file)));
>>>>>>> c8a0ce7388... test(ivy): enable more docs examples e2e tests (#28688)
} }
// Load configuration for an example. Used for SystemJS // Load configuration for an example. Used for SystemJS
function loadExampleConfig(exampleFolder) { function loadExampleConfig(exampleFolder) {
// Default config. // Default config.
let config = { let config = {build: 'build', run: 'serve:e2e'};
build: 'build',
run: 'serve:e2e'
};
try { try {
const exampleConfig = fs.readJsonSync(`${exampleFolder}/${EXAMPLE_CONFIG_FILENAME}`); const exampleConfig = fs.readJsonSync(`${exampleFolder}/${EXAMPLE_CONFIG_FILENAME}`);
Object.assign(config, exampleConfig); Object.assign(config, exampleConfig);
} catch (e) { } } catch (e) {
}
return config; return config;
} }