From 76104f395ffd9f456fd7a7fdf2c76789a4c3a3e0 Mon Sep 17 00:00:00 2001 From: George Kalpakas Date: Thu, 10 Jan 2019 22:14:04 +0200 Subject: [PATCH] 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 --- aio/tools/examples/run-example-e2e.js | 28 ++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/aio/tools/examples/run-example-e2e.js b/aio/tools/examples/run-example-e2e.js index 43c56b134a..f63ca4968d 100644 --- a/aio/tools/examples/run-example-e2e.js +++ b/aio/tools/examples/run-example-e2e.js @@ -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.