diff --git a/aio/content/examples/comparing-observables/e2e/src/app.e2e-spec.ts b/aio/content/examples/comparing-observables/e2e/src/app.e2e-spec.ts index ac89f882d0..1902bcde0a 100644 --- a/aio/content/examples/comparing-observables/e2e/src/app.e2e-spec.ts +++ b/aio/content/examples/comparing-observables/e2e/src/app.e2e-spec.ts @@ -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. diff --git a/aio/content/examples/observables-in-angular/e2e/src/app.e2e-spec.ts b/aio/content/examples/observables-in-angular/e2e/src/app.e2e-spec.ts index 83740c7123..2a0938c99b 100644 --- a/aio/content/examples/observables-in-angular/e2e/src/app.e2e-spec.ts +++ b/aio/content/examples/observables-in-angular/e2e/src/app.e2e-spec.ts @@ -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. diff --git a/aio/content/examples/observables/e2e/src/app.e2e-spec.ts b/aio/content/examples/observables/e2e/src/app.e2e-spec.ts index ac89f882d0..1902bcde0a 100644 --- a/aio/content/examples/observables/e2e/src/app.e2e-spec.ts +++ b/aio/content/examples/observables/e2e/src/app.e2e-spec.ts @@ -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. diff --git a/aio/content/examples/practical-observable-usage/e2e/src/app.e2e-spec.ts b/aio/content/examples/practical-observable-usage/e2e/src/app.e2e-spec.ts index af10979040..83714788db 100644 --- a/aio/content/examples/practical-observable-usage/e2e/src/app.e2e-spec.ts +++ b/aio/content/examples/practical-observable-usage/e2e/src/app.e2e-spec.ts @@ -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. diff --git a/aio/content/examples/rx-library/e2e/src/app.e2e-spec.ts b/aio/content/examples/rx-library/e2e/src/app.e2e-spec.ts index 015034d09e..aad3cbca2f 100644 --- a/aio/content/examples/rx-library/e2e/src/app.e2e-spec.ts +++ b/aio/content/examples/rx-library/e2e/src/app.e2e-spec.ts @@ -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. diff --git a/aio/package.json b/aio/package.json index 5d8c4db672..bcbc767b5d 100644 --- a/aio/package.json +++ b/aio/package.json @@ -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", diff --git a/aio/tools/README.md b/aio/tools/README.md index 1a949daea4..90402cd543 100644 --- a/aio/tools/README.md +++ b/aio/tools/README.md @@ -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. diff --git a/aio/tools/examples/README.md b/aio/tools/examples/README.md index 0ab8b40cde..cc78b5824a 100644 --- a/aio/tools/examples/README.md +++ b/aio/tools/examples/README.md @@ -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. diff --git a/aio/tools/examples/run-example-e2e.js b/aio/tools/examples/run-example-e2e.mjs similarity index 96% rename from aio/tools/examples/run-example-e2e.js rename to aio/tools/examples/run-example-e2e.mjs index 95793c3bb6..f53fe21502 100644 --- a/aio/tools/examples/run-example-e2e.js +++ b/aio/tools/examples/run-example-e2e.mjs @@ -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);