build(docs-infra): switch the `example-e2e` script to ESM (#42921)

Switch the JS script used for running the docs examples tests from
CommonJS to ESM format. This is necessary for upgrading the `globby`
dependency to [version 12.0.0][1] in a subsequent commit.

[1]: https://github.com/sindresorhus/globby/releases/v12.0.0

PR Close #42921
This commit is contained in:
George Kalpakas 2021-07-22 16:37:34 +03:00 committed by Dylan Hunn
parent 662addb355
commit 19da73741d
9 changed files with 25 additions and 19 deletions

View File

@ -2,7 +2,7 @@
* This example project is special in that it is not a cli app. To run tests appropriate for this * This example project is special in that it is not a cli app. To run tests appropriate for this
* project, the test command is overwritten in `aio/content/examples/observables/example-config.json`. * project, the test command is overwritten in `aio/content/examples/observables/example-config.json`.
* *
* This is an empty placeholder file to ensure that `aio/tools/examples/run-example-e2e.js` runs * This is an empty placeholder file to ensure that `aio/tools/examples/run-example-e2e.mjs` runs
* tests for this project. * tests for this project.
* *
* TODO: Fix our infrastructure/tooling, so that this hack is not necessary. * TODO: Fix our infrastructure/tooling, so that this hack is not necessary.

View File

@ -2,7 +2,7 @@
* This example project is special in that it is not a cli app. To run tests appropriate for this * This example project is special in that it is not a cli app. To run tests appropriate for this
* project, the test command is overwritten in `aio/content/examples/observables-in-angular/example-config.json`. * project, the test command is overwritten in `aio/content/examples/observables-in-angular/example-config.json`.
* *
* This is an empty placeholder file to ensure that `aio/tools/examples/run-example-e2e.js` runs * This is an empty placeholder file to ensure that `aio/tools/examples/run-example-e2e.mjs` runs
* tests for this project. * tests for this project.
* *
* TODO: Fix our infrastructure/tooling, so that this hack is not necessary. * TODO: Fix our infrastructure/tooling, so that this hack is not necessary.

View File

@ -2,7 +2,7 @@
* This example project is special in that it is not a cli app. To run tests appropriate for this * This example project is special in that it is not a cli app. To run tests appropriate for this
* project, the test command is overwritten in `aio/content/examples/observables/example-config.json`. * project, the test command is overwritten in `aio/content/examples/observables/example-config.json`.
* *
* This is an empty placeholder file to ensure that `aio/tools/examples/run-example-e2e.js` runs * This is an empty placeholder file to ensure that `aio/tools/examples/run-example-e2e.mjs` runs
* tests for this project. * tests for this project.
* *
* TODO: Fix our infrastructure/tooling, so that this hack is not necessary. * TODO: Fix our infrastructure/tooling, so that this hack is not necessary.

View File

@ -2,7 +2,7 @@
* This example project is special in that it is not a cli app. To run tests appropriate for this * This example project is special in that it is not a cli app. To run tests appropriate for this
* project, the test command is overwritten in `aio/content/examples/practical-observable-usage/example-config.json`. * project, the test command is overwritten in `aio/content/examples/practical-observable-usage/example-config.json`.
* *
* This is an empty placeholder file to ensure that `aio/tools/examples/run-example-e2e.js` runs * This is an empty placeholder file to ensure that `aio/tools/examples/run-example-e2e.mjs` runs
* tests for this project. * tests for this project.
* *
* TODO: Fix our infrastructure/tooling, so that this hack is not necessary. * TODO: Fix our infrastructure/tooling, so that this hack is not necessary.

View File

@ -2,7 +2,7 @@
* This example project is special in that it is not a cli app. To run tests appropriate for this * This example project is special in that it is not a cli app. To run tests appropriate for this
* project, the test command is overwritten in `aio/content/examples/rx-libary/example-config.json`. * project, the test command is overwritten in `aio/content/examples/rx-libary/example-config.json`.
* *
* This is an empty placeholder file to ensure that `aio/tools/examples/run-example-e2e.js` runs * This is an empty placeholder file to ensure that `aio/tools/examples/run-example-e2e.mjs` runs
* tests for this project. * tests for this project.
* *
* TODO: Fix our infrastructure/tooling, so that this hack is not necessary. * TODO: Fix our infrastructure/tooling, so that this hack is not necessary.

View File

@ -39,7 +39,7 @@
"test-a11y-score-localhost": "run-p --race \"~~light-server -s dist -p 4200 --quiet\" \"test-a11y-score http://localhost:4200\" --", "test-a11y-score-localhost": "run-p --race \"~~light-server -s dist -p 4200 --quiet\" \"test-a11y-score http://localhost:4200\" --",
"test-pwa-score": "run-s \"~~audit-web-app {1} all:0,pwa:{2} {3}\" --", "test-pwa-score": "run-s \"~~audit-web-app {1} all:0,pwa:{2} {3}\" --",
"test-pwa-score-localhost": "run-p --race \"~~light-server -s dist -p 4200 --quiet\" \"test-pwa-score http://localhost:4200 {1} {2}\" --", "test-pwa-score-localhost": "run-p --race \"~~light-server -s dist -p 4200 --quiet\" \"test-pwa-score http://localhost:4200 {1} {2}\" --",
"example-e2e": "yarn example-check-local && node ./tools/examples/run-example-e2e", "example-e2e": "yarn example-check-local && node ./tools/examples/run-example-e2e.mjs",
"example-lint": "tslint --config \"content/examples/tslint.json\" \"content/examples/**/*.ts\" --exclude \"content/examples/styleguide/**/*.avoid.ts\"", "example-lint": "tslint --config \"content/examples/tslint.json\" \"content/examples/**/*.ts\" --exclude \"content/examples/styleguide/**/*.avoid.ts\"",
"example-use-local": "node tools/ng-packages-installer overwrite ./tools/examples/shared --debug --force", "example-use-local": "node tools/ng-packages-installer overwrite ./tools/examples/shared --debug --force",
"example-use-npm": "node tools/ng-packages-installer restore ./tools/examples/shared", "example-use-npm": "node tools/ng-packages-installer restore ./tools/examples/shared",

View File

@ -33,7 +33,7 @@ This `examples` tool folder contains three utilities:
* example-boilerplate.js - install/remove the npm dependencies and boilerplate files into/from each of the * example-boilerplate.js - install/remove the npm dependencies and boilerplate files into/from each of the
examples' subfolders. examples' subfolders.
* run-example-e2e.js - run the e2e tests for one or more examples * run-example-e2e.mjs - run the e2e tests for one or more examples
* create-example.js - create a new example from the `example-scaffold/` directory or by importing files from a CLI project. * create-example.js - create a new example from the `example-scaffold/` directory or by importing files from a CLI project.
See the [README.md](examples/README.md) for more details. See the [README.md](examples/README.md) for more details.

View File

@ -135,9 +135,9 @@ It will remove all files that are not tracked by git, **including any new files
So, be sure to commit your work before removing the boilerplate. So, be sure to commit your work before removing the boilerplate.
### `run-example-e2e.js` ### `run-example-e2e.mjs`
The [run-example-e2e.js](./run-example-e2e.js) script will find and run the e2e tests for all examples. The [run-example-e2e.mjs](./run-example-e2e.mjs) script will find and run the e2e tests for all examples.
Although it only runs e2e tests by default, it can be configured to run any test command (for CLI-based examples) by using the `tests` property of the [example-config.json](#example-config) file. Although it only runs e2e tests by default, it can be configured to run any test command (for CLI-based examples) by using the `tests` property of the [example-config.json](#example-config) file.
It is named `*-e2e` for historical reasons, but it is not limited to running e2e tests. It is named `*-e2e` for historical reasons, but it is not limited to running e2e tests.

View File

@ -1,16 +1,22 @@
const path = require('canonical-path'); import path from 'canonical-path';
const fs = require('fs-extra'); import {spawn} from 'cross-spawn';
const argv = require('yargs').argv; import findFreePort from 'find-free-port';
const globby = require('globby'); import fs from 'fs-extra';
const xSpawn = require('cross-spawn'); import globby from 'globby';
const treeKill = require('tree-kill'); import puppeteer from 'puppeteer';
const shelljs = require('shelljs'); import shelljs from 'shelljs';
const findFreePort = require('find-free-port'); import treeKill from 'tree-kill';
import {fileURLToPath} from 'url';
import yargs from 'yargs';
import {hideBin} from 'yargs/helpers'
shelljs.set('-e'); shelljs.set('-e');
// Set `CHROME_BIN` as an environment variable for Karma to pick up in unit tests. // Set `CHROME_BIN` as an environment variable for Karma to pick up in unit tests.
process.env.CHROME_BIN = require('puppeteer').executablePath(); process.env.CHROME_BIN = puppeteer.executablePath();
const __dirname = path.dirname(fileURLToPath(import.meta.url));
const {argv} = yargs(hideBin(process.argv));
const AIO_PATH = path.join(__dirname, '../../'); const AIO_PATH = path.join(__dirname, '../../');
const EXAMPLES_PATH = path.join(AIO_PATH, './content/examples/'); const EXAMPLES_PATH = path.join(AIO_PATH, './content/examples/');
@ -340,7 +346,7 @@ function spawnExt(
let processOutput = ''; let processOutput = '';
printMessage(`running: ${descr}\n`); printMessage(`running: ${descr}\n`);
try { try {
proc = xSpawn.spawn(command, args, options); proc = spawn(command, args, options);
} catch (e) { } catch (e) {
console.log(e); console.log(e);
reject(e); reject(e);