From f479ea6d8e7ce704ac59aca8b08bd25e978fcc7f Mon Sep 17 00:00:00 2001 From: erwin mombay Date: Mon, 2 Nov 2020 14:44:25 -0800 Subject: [PATCH] Turn on esm tests (#28336) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * temp * temp * add conditional to the css removal * add travis entry * add esm-tests.js file * minor fix to add coverage * remove compiled to test * add compiled back in * Revert "🏗♻️ Consolidate all `babel` configs into `babel.config.js` (#27576)" This reverts commit f801a93c2f079ae439e9a819b09bde0f028f3028. * temp * temp * reset this to be close to master * temp * temp * temp * temp * for non dev builds (compiled, rtv) take into account the module build for regex replace * temp * remove debuggers * temp * apply recs * remove runner.js * apply recs * add --esm flag to integration run * download dist output as we need f.js/integration.js from dist nomodule * allow cors explicitly for mjs files GET requests * add flag to overwrite when unzipping * fix test type inference * apply recs --- .travis.yml | 4 ++ build-system/pr-check/esm-tests.js | 74 ++++++++++++++++++++++++ build-system/pr-check/utils.js | 2 +- build-system/server/app.js | 8 ++- build-system/tasks/integration.js | 2 +- build-system/tasks/presubmit-checks.js | 1 + build-system/tasks/report-test-status.js | 6 +- 7 files changed, 93 insertions(+), 4 deletions(-) create mode 100644 build-system/pr-check/esm-tests.js diff --git a/.travis.yml b/.travis.yml index c9c31b3f59d6..c35ffe0fcbb0 100644 --- a/.travis.yml +++ b/.travis.yml @@ -84,6 +84,10 @@ jobs: name: 'End to End Tests' script: - unbuffer node build-system/pr-check/e2e-tests.js + - stage: test + name: 'ESM Tests' + script: + - unbuffer node build-system/pr-check/esm-tests.js - stage: experiment name: 'Experiment A Tests' script: diff --git a/build-system/pr-check/esm-tests.js b/build-system/pr-check/esm-tests.js new file mode 100644 index 000000000000..de721219e8e0 --- /dev/null +++ b/build-system/pr-check/esm-tests.js @@ -0,0 +1,74 @@ +/** + * Copyright 2020 The AMP HTML Authors. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS-IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +'use strict'; + +/** + * @fileoverview + * This script builds and tests the AMP runtime in esm mode. + * This is run during the CI stage = test; job = esm tests. + */ + +const colors = require('ansi-colors'); +const { + printChangeSummary, + startTimer, + stopTimer, + timedExecOrDie: timedExecOrDieBase, + downloadEsmDistOutput, + downloadDistOutput, +} = require('./utils'); +const {determineBuildTargets} = require('./build-targets'); +const {isTravisPullRequestBuild} = require('../common/travis'); + +const FILENAME = 'esm-tests.js'; +const FILELOGPREFIX = colors.bold(colors.yellow(`${FILENAME}:`)); +const timedExecOrDie = (cmd, unusedFileName) => + timedExecOrDieBase(cmd, FILENAME); + +function main() { + const startTime = startTimer(FILENAME, FILENAME); + + if (!isTravisPullRequestBuild()) { + downloadDistOutput(FILENAME); + downloadEsmDistOutput(FILENAME); + timedExecOrDie('gulp update-packages'); + timedExecOrDie('gulp integration --nobuild --compiled --headless --esm'); + } else { + printChangeSummary(FILENAME); + const buildTargets = determineBuildTargets(FILENAME); + if ( + buildTargets.has('RUNTIME') || + buildTargets.has('FLAG_CONFIG') || + buildTargets.has('INTEGRATION_TEST') + ) { + downloadDistOutput(FILENAME); + downloadEsmDistOutput(FILENAME); + timedExecOrDie('gulp update-packages'); + timedExecOrDie('gulp integration --nobuild --compiled --headless --esm'); + } else { + console.log( + `${FILELOGPREFIX} Skipping`, + colors.cyan('ESM Tests'), + 'because this commit does not affect the runtime, flag configs,', + 'or integration tests.' + ); + } + } + + stopTimer(FILENAME, FILENAME, startTime); +} + +main(); diff --git a/build-system/pr-check/utils.js b/build-system/pr-check/utils.js index 5367605e9a4a..f55d4392a4bd 100644 --- a/build-system/pr-check/utils.js +++ b/build-system/pr-check/utils.js @@ -239,7 +239,7 @@ function downloadOutput_(functionName, outputFileName, outputDirs) { ); exec('echo travis_fold:start:unzip_results && echo'); dirsToUnzip.forEach((dir) => { - execOrDie(`unzip ${outputFileName} '${dir.replace('/', '/*')}'`); + execOrDie(`unzip -o ${outputFileName} '${dir.replace('/', '/*')}'`); }); exec('echo travis_fold:end:unzip_results'); diff --git a/build-system/server/app.js b/build-system/server/app.js index 6af668225cfa..3c8410e08797 100644 --- a/build-system/server/app.js +++ b/build-system/server/app.js @@ -1205,6 +1205,12 @@ app.get('/adzerk/*', (req, res) => { }); }); +app.get('/dist/*.mjs', (req, res, next) => { + // Allow CORS access control explicitly for mjs files + cors.enableCors(req, res); + next(); +}); + /* * Serve extension scripts and their source maps. */ @@ -1339,7 +1345,7 @@ app.get('/dist/rtv/9[89]*/*.(m?js)', (req, res, next) => { setTimeout(() => { // Cause a delay, to show the "stale-while-revalidate" - if (req.path.includes('v0.js')) { + if (req.path.includes('v0.js') || req.path.includes('v0.mjs')) { const path = req.path.replace(/rtv\/\d+/, ''); return fs.promises .readFile(pc.cwd() + path, 'utf8') diff --git a/build-system/tasks/integration.js b/build-system/tasks/integration.js index 67a9645ddf14..a569dda6852a 100644 --- a/build-system/tasks/integration.js +++ b/build-system/tasks/integration.js @@ -113,7 +113,7 @@ integration.flags = { ' Allow debug statements by auto opening devtools. NOTE: This only ' + 'works in non headless mode.', 'edge': ' Runs tests on Edge', - 'esm': ' Runs against module/nomodule build', + 'esm': ' Runs against module(esm) build', 'firefox': ' Runs tests on Firefox', 'files': ' Runs tests for specific files', 'grep': ' Runs tests that match the pattern', diff --git a/build-system/tasks/presubmit-checks.js b/build-system/tasks/presubmit-checks.js index e5447e6fdee9..b6535eeb0f29 100644 --- a/build-system/tasks/presubmit-checks.js +++ b/build-system/tasks/presubmit-checks.js @@ -122,6 +122,7 @@ const forbiddenTerms = { 'build-system/pr-check/dist-bundle-size.js', 'build-system/pr-check/dist-tests.js', 'build-system/pr-check/module-dist-bundle-size.js', + 'build-system/pr-check/esm-tests.js', 'build-system/pr-check/experiment-tests.js', 'build-system/pr-check/e2e-tests.js', 'build-system/pr-check/local-tests.js', diff --git a/build-system/tasks/report-test-status.js b/build-system/tasks/report-test-status.js index 4235fc5bc3d5..1bb03842c253 100644 --- a/build-system/tasks/report-test-status.js +++ b/build-system/tasks/report-test-status.js @@ -30,9 +30,10 @@ const IS_GULP_E2E = argv._[0] === 'e2e'; const IS_LOCAL_CHANGES = !!argv.local_changes; const IS_DIST = !!argv.compiled; +const IS_ESM = !!argv.esm; const TEST_TYPE_SUBTYPES = new Map([ - ['integration', ['local', 'minified']], + ['integration', ['local', 'minified', 'esm']], ['unit', ['local', 'local-changes']], ['e2e', ['local']], ]); @@ -59,6 +60,9 @@ function inferTestType() { if (IS_LOCAL_CHANGES) { return `${type}/local-changes`; } else if (IS_DIST) { + if (IS_ESM) { + return `${type}/esm`; + } return `${type}/minified`; } else { return `${type}/local`;