Skip to content

Commit

Permalink
Turn on esm tests (#28336)
Browse files Browse the repository at this point in the history
* 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 f801a93.

* 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
  • Loading branch information
erwinmombay committed Nov 2, 2020
1 parent 9308f9f commit f479ea6
Show file tree
Hide file tree
Showing 7 changed files with 93 additions and 4 deletions.
4 changes: 4 additions & 0 deletions .travis.yml
Expand Up @@ -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:
Expand Down
74 changes: 74 additions & 0 deletions 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();
2 changes: 1 addition & 1 deletion build-system/pr-check/utils.js
Expand Up @@ -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');

Expand Down
8 changes: 7 additions & 1 deletion build-system/server/app.js
Expand Up @@ -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.
*/
Expand Down Expand Up @@ -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')
Expand Down
2 changes: 1 addition & 1 deletion build-system/tasks/integration.js
Expand Up @@ -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',
Expand Down
1 change: 1 addition & 0 deletions build-system/tasks/presubmit-checks.js
Expand Up @@ -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',
Expand Down
6 changes: 5 additions & 1 deletion build-system/tasks/report-test-status.js
Expand Up @@ -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']],
]);
Expand All @@ -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`;
Expand Down

0 comments on commit f479ea6

Please sign in to comment.