feat(docs-infra): add support for custom test commands in cli-based docs examples (#28020)

Previously, cli-based docs examples were tested using `yarn e2e ...`. In
some cases, it might make sense to run different or additional checks
for a docs example (when running `yarn example-e2e` in `aio/`).

Currently, the only option is to define a custom project type and
overwrite the `e2e` yarn script in `package.json`. Doing so (in addition
to being cumbersome and verbose) would also end up in the `.zip` archive
that users can download to run the example locally. This would be
confusing, if these custom tests are specific to our CI needs.

This commit adds support for defining a custom list of commands per
example. These commands (if specified) would be run instead of the
default `yarn e2e ...`, when testing the docs examples on CI (via
`yarn example-e2e`).

(This feature will be used to verify that the
`service-worker-getting-started` example is set up correctly in a
subsequent commit, but can be useful in other cases as well.)

PR Close #28020
This commit is contained in:
George Kalpakas 2019-01-10 22:14:04 +02:00 committed by Andrew Kushnir
parent 18ccfc6d73
commit 76104f395f
1 changed files with 15 additions and 13 deletions

View File

@ -204,20 +204,22 @@ function runProtractorAoT(appDir, outputFile) {
// CLI version
function runE2eTestsCLI(appDir, outputFile) {
console.log(`\n\n=========== Running aio example tests for: ${appDir}`);
// `--preserve-symlinks` is needed due the symlinked `node_modules/` in each example.
// `--no-webdriver-update` is needed to preserve the ChromeDriver version already installed.
const args = ['e2e', '--no-webdriver-update'];
const e2eSpawn = spawnExt('yarn', args, { cwd: appDir });
return e2eSpawn.promise.then(
function () {
fs.appendFileSync(outputFile, `Passed: ${appDir}\n\n`);
return finish(e2eSpawn.proc.pid, true);
},
function () {
fs.appendFileSync(outputFile, `Failed: ${appDir}\n\n`);
return finish(e2eSpawn.proc.pid, false);
}
);
const config = loadExampleConfig(appDir);
const commands = config.e2e || [{ cmd: 'yarn', args: ['e2e', '--no-webdriver-update'] }];
const e2eSpawnPromise = commands.reduce((prevSpawnPromise, { cmd, args }) => {
return prevSpawnPromise.then(() => {
const currSpawn = spawnExt(cmd, args, { cwd: appDir });
return currSpawn.promise.then(
() => Promise.resolve(finish(currSpawn.proc.pid, true)),
() => Promise.reject(finish(currSpawn.proc.pid, false)));
});
}, Promise.resolve());
return e2eSpawnPromise.then(
() => { fs.appendFileSync(outputFile, `Passed: ${appDir}\n\n`); return true; },
() => { fs.appendFileSync(outputFile, `Failed: ${appDir}\n\n`); return false; });
}
// Report final status.