Skip to content

Commit

Permalink
add mocha-junit-reporter for e2e tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rileyajones committed Apr 9, 2021
1 parent edc4fb3 commit 2f01eca
Show file tree
Hide file tree
Showing 9 changed files with 156 additions and 17 deletions.
19 changes: 10 additions & 9 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ commands:
name: 'Fail Fast'
when: on_fail
command: ./.circleci/fail_fast.sh
save_artifacts:
store_test_output:
steps:
- store_artifacts:
path: result-reports
Expand Down Expand Up @@ -175,7 +175,7 @@ jobs:
- run:
name: 'Validator Tests'
command: node build-system/pr-check/validator-tests.js
- save_artifacts
- store_test_output
- fail_fast
- teardown_vm
'Visual Diff Tests':
Expand All @@ -188,7 +188,7 @@ jobs:
- run:
name: 'Visual Diff Tests'
command: node build-system/pr-check/visual-diff-tests.js
- save_artifacts
- store_test_output
- fail_fast
- teardown_vm
'Unit Tests':
Expand All @@ -201,7 +201,7 @@ jobs:
- run:
name: 'Unit Tests'
command: node build-system/pr-check/unit-tests.js
- save_artifacts
- store_test_output
- fail_fast
- teardown_vm
'Unminified Tests':
Expand All @@ -214,7 +214,7 @@ jobs:
- run:
name: 'Unminified Tests'
command: node build-system/pr-check/unminified-tests.js
- save_artifacts
- store_test_output
- fail_fast
- teardown_vm
'Nomodule Tests':
Expand All @@ -232,7 +232,7 @@ jobs:
- run:
name: 'Nomodule Tests (<< parameters.config >>)'
command: node build-system/pr-check/nomodule-tests.js --config=<< parameters.config >>
- save_artifacts
- store_test_output
- fail_fast
- teardown_vm
'Module Tests':
Expand All @@ -250,7 +250,7 @@ jobs:
- run:
name: 'Module Tests (<< parameters.config >>)'
command: node build-system/pr-check/module-tests.js --config=<< parameters.config >>
- save_artifacts
- store_test_output
- fail_fast
- teardown_vm
'End-to-End Tests':
Expand All @@ -263,7 +263,7 @@ jobs:
- run:
name: 'End-to-End Tests'
command: node build-system/pr-check/e2e-tests.js
- save_artifacts
- store_test_output
- fail_fast
- teardown_vm
'Performance Tests':
Expand All @@ -276,7 +276,7 @@ jobs:
- run:
name: 'Performance Tests'
command: node build-system/pr-check/performance-tests.js
- save_artifacts
- store_test_output
- fail_fast
- teardown_vm
'Experiment Build':
Expand Down Expand Up @@ -310,6 +310,7 @@ jobs:
- run:
name: 'Experiment << parameters.exp >> Tests'
command: node build-system/pr-check/experiment-tests.js --experiment=experiment<< parameters.exp >>
- store_test_output
- fail_fast
- teardown_vm

Expand Down
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ out/**
test/coverage/**
.babel-cache/**
.css-cache/**
result-reports/**

# Code directories
build-system/tasks/visual-diff/snippets/*.js
Expand Down
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@
**/dist.3p/**
**/dist.tools/**
extensions/**/dist/**
result-reports/**
20 changes: 17 additions & 3 deletions build-system/tasks/e2e/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,18 @@ const fs = require('fs');
const glob = require('glob');
const http = require('http');
const Mocha = require('mocha');
const MochaJUnitReporter = require('mocha-junit-reporter');
const path = require('path');
const {
createCtrlcHandler,
exitCtrlcHandler,
} = require('../../common/ctrlcHandler');
const {buildRuntime, getFilesFromArgv} = require('../../common/utils');
const {createMultiplexedReporter} = require('./mocha-report-multiplexer');
const {cyan} = require('kleur/colors');
const {execOrDie} = require('../../common/exec');
const {HOST, PORT, startServer, stopServer} = require('../serve');
const {isCiBuild} = require('../../common/ci');
const {isCiBuild, isCircleciBuild} = require('../../common/ci');
const {log} = require('../../common/logging');
const {maybePrintCoverageMessage} = require('../helpers');
const {reportTestStarted} = require('../report-test-status');
Expand Down Expand Up @@ -86,14 +88,26 @@ function createMocha_() {
reporter = dotsReporter;
}

return new Mocha({
const options = {
// e2e tests have a different standard for when a test is too slow,
// so we set a non-default threshold.
slow: SLOW_TEST_THRESHOLD_MS,
reporter,
retries: TEST_RETRIES,
fullStackTrace: true,
});
};

if (isCircleciBuild()) {
options.reporter = createMultiplexedReporter([
options.reporter,
MochaJUnitReporter,
]);
options.reporterOptions = {
mochaFile: 'result-reports/e2e.xml',
};
}

return new Mocha(options);
}

/**
Expand Down
48 changes: 48 additions & 0 deletions build-system/tasks/e2e/mocha-report-multiplexer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/**
* Copyright 2021 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.
*/
const Mocha = require('mocha');
const {Base} = Mocha.reporters;

/**
* Creates a custom Mocha reporter which runs many reporters at once.
* @param {Base[]} reporters
* @return {Function<*,MochaReportMultiplexer>}
*/
function createMultiplexedReporter(reporters) {
return class DynamicReportMultiplexer extends Base {
/**
* @param {*} runner
* @param {Mocha.Runner.options} options
*/
constructor(runner, options) {
super(runner);
// If there are too many reporters listening to events on the runner a
// warning will be displayed about a potential emitter leak. This should
// allow each reporter to listen to every event without exceeding the max.
// The default max listeners is 10.
const potentialEvents = Object.keys(Mocha.Runner.constants);
runner.setMaxListeners(potentialEvents.length * reporters.length);

this.reporters = reporters.map(
(reporter) => new reporter(runner, options)
);
}
};
}

module.exports = {
createMultiplexedReporter,
};
5 changes: 4 additions & 1 deletion build-system/tasks/runtime-test/runtime-test-base.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,10 @@ function updateReporters(config) {

if (isCircleciBuild()) {
config.reporters.push('junit');
config.junitReporter.outputFile = `result-reports/${config.testType}.xml`;
config.junitReporter = {
outputFile: `result-reports/${config.testType}.xml`,
useBrowserName: false,
};
}

if (argv.coverage) {
Expand Down
4 changes: 0 additions & 4 deletions build-system/test-configs/karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,6 @@ module.exports = {
},
},

junitReporter: {
useBrowserName: false,
},

port: 9876,

colors: true,
Expand Down
74 changes: 74 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@
"minimatch": "3.0.4",
"minimist": "1.2.5",
"mocha": "8.3.2",
"mocha-junit-reporter": "2.0.0",
"mocha-silent-reporter": "1.0.0",
"morgan": "1.10.0",
"multer": "1.4.2",
Expand Down

0 comments on commit 2f01eca

Please sign in to comment.