From 15735101871f960fa109249332e81d654350d499 Mon Sep 17 00:00:00 2001 From: Pete Bacon Darwin Date: Mon, 19 Apr 2021 14:31:45 +0100 Subject: [PATCH] refactor(docs-infra): tidy up systemjs boilerplate for upgrade examples (#41689) The ngUpgrade examples mostly rely upon SystemJS configuration. This commit tidies up how these examples are built and tested so that it will be easier to migrate them to work with Angular 11.2.x PR Close #41689 --- .../tsconfig.json | 26 ------------------- .../upgrade-phonecat-2-hybrid/tsconfig.json | 25 ------------------ .../upgrade-phonecat-3-final/tsconfig.json | 25 ------------------ aio/tools/examples/README.md | 6 ++--- aio/tools/examples/run-example-e2e.js | 10 +------ .../shared/boilerplate/systemjs/package.json | 8 +++--- .../systemjs}/protractor.config.js | 25 +++++++----------- .../systemjs/{src => }/tsconfig.json | 0 8 files changed, 15 insertions(+), 110 deletions(-) delete mode 100644 aio/content/examples/upgrade-phonecat-1-typescript/tsconfig.json delete mode 100644 aio/content/examples/upgrade-phonecat-2-hybrid/tsconfig.json delete mode 100644 aio/content/examples/upgrade-phonecat-3-final/tsconfig.json rename aio/tools/examples/shared/{ => boilerplate/systemjs}/protractor.config.js (84%) rename aio/tools/examples/shared/boilerplate/systemjs/{src => }/tsconfig.json (100%) diff --git a/aio/content/examples/upgrade-phonecat-1-typescript/tsconfig.json b/aio/content/examples/upgrade-phonecat-1-typescript/tsconfig.json deleted file mode 100644 index a89a619231..0000000000 --- a/aio/content/examples/upgrade-phonecat-1-typescript/tsconfig.json +++ /dev/null @@ -1,26 +0,0 @@ -{ - "compilerOptions": { - "target": "es5", - "module": "commonjs", - "moduleResolution": "node", - "sourceMap": true, - "emitDecoratorMetadata": true, - "experimentalDecorators": true, - "lib": [ - "es2015", - "dom" - ], - "noImplicitAny": true, - "skipLibCheck": true, - "suppressImplicitAnyIndexErrors": true, - "typeRoots": [ - "node_modules/@types" - ] - }, - "compileOnSave": true, - "exclude": [ - "node_modules/*", - "**/*-aot.ts", - "aot/**/*" - ] -} diff --git a/aio/content/examples/upgrade-phonecat-2-hybrid/tsconfig.json b/aio/content/examples/upgrade-phonecat-2-hybrid/tsconfig.json deleted file mode 100644 index d1f02feb5b..0000000000 --- a/aio/content/examples/upgrade-phonecat-2-hybrid/tsconfig.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "compilerOptions": { - "target": "es5", - "module": "commonjs", - "moduleResolution": "node", - "sourceMap": true, - "emitDecoratorMetadata": true, - "experimentalDecorators": true, - "lib": [ - "es2015", - "dom" - ], - "noImplicitAny": true, - "skipLibCheck": true, - "suppressImplicitAnyIndexErrors": true, - "typeRoots": [ - "node_modules/@types" - ] - }, - "compileOnSave": true, - "exclude": [ - "node_modules/*", - "**/*-aot.ts" - ] -} diff --git a/aio/content/examples/upgrade-phonecat-3-final/tsconfig.json b/aio/content/examples/upgrade-phonecat-3-final/tsconfig.json deleted file mode 100644 index d1f02feb5b..0000000000 --- a/aio/content/examples/upgrade-phonecat-3-final/tsconfig.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "compilerOptions": { - "target": "es5", - "module": "commonjs", - "moduleResolution": "node", - "sourceMap": true, - "emitDecoratorMetadata": true, - "experimentalDecorators": true, - "lib": [ - "es2015", - "dom" - ], - "noImplicitAny": true, - "skipLibCheck": true, - "suppressImplicitAnyIndexErrors": true, - "typeRoots": [ - "node_modules/@types" - ] - }, - "compileOnSave": true, - "exclude": [ - "node_modules/*", - "**/*-aot.ts" - ] -} diff --git a/aio/tools/examples/README.md b/aio/tools/examples/README.md index 1d5182f8fa..0ab8b40cde 100644 --- a/aio/tools/examples/README.md +++ b/aio/tools/examples/README.md @@ -118,12 +118,10 @@ This will be picked up by the default testing command (see the [example configur If you are using a custom test command, make sure e2e specs are picked up (if applicable). For SystemJS-based examples, create an `e2e-spec.ts` file inside the example root folder. -These apps will be tested with the following command: +These apps will be tested with the following command (and an optional `outputFile` to receive log messages): ```sh -yarn protractor aio/tools/examples/shared/protractor.config.js \ - --specs=/e2e-spec.ts \ - --params.appDir= +yarn protractor [--params.outputFile=path/to/logfile.txt] ``` diff --git a/aio/tools/examples/run-example-e2e.js b/aio/tools/examples/run-example-e2e.js index 1bba1afb46..2da2402823 100644 --- a/aio/tools/examples/run-example-e2e.js +++ b/aio/tools/examples/run-example-e2e.js @@ -13,9 +13,7 @@ shelljs.set('-e'); process.env.CHROME_BIN = require('puppeteer').executablePath(); const AIO_PATH = path.join(__dirname, '../../'); -const SHARED_PATH = path.join(__dirname, '/shared'); const EXAMPLES_PATH = path.join(AIO_PATH, './content/examples/'); -const PROTRACTOR_CONFIG_FILENAME = path.join(__dirname, './shared/protractor.config.js'); const SJS_SPEC_FILENAME = 'e2e-spec.ts'; const CLI_SPEC_FILENAME = 'e2e/src/app.e2e-spec.ts'; const EXAMPLE_CONFIG_FILENAME = 'example-config.json'; @@ -194,13 +192,7 @@ function runProtractorSystemJS(prepPromise, appDir, appRunSpawnInfo, outputFile) // Start protractor. console.log(`\n\n=========== Running aio example tests for: ${appDir}`); - const spawnInfo = spawnExt( - 'yarn', - [ - 'protractor', PROTRACTOR_CONFIG_FILENAME, `--specs=${specFilename}`, - '--params.appDir=' + appDir, '--params.outputFile=' + outputFile - ], - {cwd: SHARED_PATH}); + const spawnInfo = spawnExt('yarn', [ 'protractor', '--params.outputFile=' + outputFile ], {cwd: appDir}); spawnInfo.proc.stderr.on('data', function(data) { transpileError = transpileError || /npm ERR! Exit status 100/.test(data.toString()); diff --git a/aio/tools/examples/shared/boilerplate/systemjs/package.json b/aio/tools/examples/shared/boilerplate/systemjs/package.json index d7f606185e..9b1802a540 100644 --- a/aio/tools/examples/shared/boilerplate/systemjs/package.json +++ b/aio/tools/examples/shared/boilerplate/systemjs/package.json @@ -4,16 +4,14 @@ "description": "Example project from an angular.io guide.", "license": "MIT", "scripts": { - "build": "tsc -p src/", - "build:watch": "tsc -p src/ -w", - "build:e2e": "tsc -p e2e/", + "build": "tsc", + "build:watch": "tsc -w", "serve": "lite-server -c=bs-config.json", "serve:e2e": "lite-server -c=bs-config.e2e.json", "prestart": "npm run build", "start": "concurrently \"npm run build:watch\" \"npm run serve\"", - "pree2e": "webdriver-manager update && npm run build:e2e", "e2e": "concurrently \"npm run serve:e2e\" \"npm run protractor\" --kill-others --success first", - "protractor": "protractor protractor.config.js", + "protractor": "protractor protractor.config.js --specs=e2e-spec.ts", "pretest": "npm run build", "test": "concurrently \"npm run build:watch\" \"karma start karma.conf.js\"", "pretest:once": "npm run build", diff --git a/aio/tools/examples/shared/protractor.config.js b/aio/tools/examples/shared/boilerplate/systemjs/protractor.config.js similarity index 84% rename from aio/tools/examples/shared/protractor.config.js rename to aio/tools/examples/shared/boilerplate/systemjs/protractor.config.js index bb99ba637d..8d3ffa2492 100644 --- a/aio/tools/examples/shared/protractor.config.js +++ b/aio/tools/examples/shared/boilerplate/systemjs/protractor.config.js @@ -49,7 +49,7 @@ exports.config = { // debugging // console.log('browser.params:' + JSON.stringify(browser.params)); - jasmine.getEnv().addReporter(new Reporter( browser.params )); + jasmine.getEnv().addReporter(new Reporter(browser.params.outputFile)); }, jasmineNodeOpts: { @@ -68,12 +68,8 @@ exports.config = { }; // See https://jasmine.github.io/2.1/custom_reporter.html -function Reporter(options) { - var _defaultOutputFile = path.resolve(__dirname, '../../protractor-results.txt'); - options.outputFile = options.outputFile || _defaultOutputFile; - - var _root = { appDir: options.appDir, suites: [] }; - log('AppDir: ' + options.appDir, +1); +function Reporter(outputFile) { + var _root = { suites: [] }; var _currentSuite; this.suiteStarted = function(suite) { @@ -114,21 +110,18 @@ function Reporter(options) { } }; - this.jasmineDone = function() { - outputFile = options.outputFile; - //// Alternate approach - just stringify the _root - not as pretty - //// but might be more useful for automation. - // var output = JSON.stringify(_root, null, 2); - var output = formatOutput(_root); - fs.appendFileSync(outputFile, output); - }; + if (outputFile) { + this.jasmineDone = function() { + var output = formatOutput(_root); + fs.appendFileSync(outputFile, output); + }; + } // for output file output function formatOutput(output) { var indent = ' '; var pad = ' '; var results = []; - results.push('AppDir:' + output.appDir); output.suites.forEach(function(suite) { results.push(pad + 'Suite: ' + suite.description + ' -- ' + suite.status); pad+=indent; diff --git a/aio/tools/examples/shared/boilerplate/systemjs/src/tsconfig.json b/aio/tools/examples/shared/boilerplate/systemjs/tsconfig.json similarity index 100% rename from aio/tools/examples/shared/boilerplate/systemjs/src/tsconfig.json rename to aio/tools/examples/shared/boilerplate/systemjs/tsconfig.json