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
* 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.
*
* 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
* 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.
*
* 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
* 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.
*
* 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
* 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.
*
* 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
* 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.
*
* 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-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}\" --",
"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-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",

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
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.
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.
### `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.
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');
const fs = require('fs-extra');
const argv = require('yargs').argv;
const globby = require('globby');
const xSpawn = require('cross-spawn');
const treeKill = require('tree-kill');
const shelljs = require('shelljs');
const findFreePort = require('find-free-port');
import path from 'canonical-path';
import {spawn} from 'cross-spawn';
import findFreePort from 'find-free-port';
import fs from 'fs-extra';
import globby from 'globby';
import puppeteer from 'puppeteer';
import shelljs from 'shelljs';
import treeKill from 'tree-kill';
import {fileURLToPath} from 'url';
import yargs from 'yargs';
import {hideBin} from 'yargs/helpers'
shelljs.set('-e');
// 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 EXAMPLES_PATH = path.join(AIO_PATH, './content/examples/');
@ -340,7 +346,7 @@ function spawnExt(
let processOutput = '';
printMessage(`running: ${descr}\n`);
try {
proc = xSpawn.spawn(command, args, options);
proc = spawn(command, args, options);
} catch (e) {
console.log(e);
reject(e);