test: print failed tests upon interrupt (#3316)

This commit is contained in:
Pavel Feldman 2020-08-05 17:31:13 -07:00 committed by GitHub
parent 5f7b5469b9
commit 0a5d340e8e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 0 deletions

View File

@ -20,6 +20,7 @@ const os = require('os');
const path = require('path');
const fs = require('fs');
const debug = require('debug');
const util = require('util');
const platform = process.env.REPORT_ONLY_PLATFORM || os.platform();
const GoldenUtils = require('../../utils/testrunner/GoldenUtils');
const {installCoverageHooks} = require('./coverage');
@ -170,6 +171,7 @@ class PlaywrightEnvironment extends NodeEnvironment {
if (event.name === 'test_start') {
const fn = event.test.fn;
this._lastTest = event.test;
event.test.fn = async () => {
if (reportOnly) {
if (fn.__fail)
@ -179,6 +181,9 @@ class PlaywrightEnvironment extends NodeEnvironment {
debug('pw:test')(`start "${testOrSuiteName(event.test)}"`);
try {
await this.fixturePool.resolveParametersAndRun(fn);
} catch(e) {
debug('pw:test')(`error "${testOrSuiteName(event.test)}"`, util.inspect(e));
throw e;
} finally {
await this.fixturePool.teardownScope('test');
debug('pw:test')(`finish "${testOrSuiteName(event.test)}"`);
@ -186,6 +191,9 @@ class PlaywrightEnvironment extends NodeEnvironment {
};
}
if (event.name === 'error')
debug('pw:test')(`error "${testOrSuiteName(this._lastTest)}"`, util.inspect(event.error));
if (event.name === 'test_fn_failure') {
await this.fixturePool.teardownScope('worker');
}

View File

@ -14,13 +14,31 @@
* limitations under the License.
*/
const colors = require('colors/safe');
const fs = require('fs');
const os = require('os');
const failures = [];
module.exports = function Reporter() {
this.onRunComplete = (test, runResults) => {
runResults.platform = process.env.REPORT_ONLY_PLATFORM || os.platform();
runResults.browserName = process.env.BROWSER || 'chromium';
fs.writeFileSync('jest-report.json', JSON.stringify(runResults, undefined, 2));
};
this.onTestCaseResult = (test, testCaseResult) => {
if (testCaseResult.status === 'failed')
failures.push([test, testCaseResult]);
}
}
process.on('SIGINT', async () => {
for (let i = 0; i < failures.length; ++i) {
const [test, testCaseResult] = failures[i];
const path = test.path.replace(/.*test/, 'test');
const name = colors.yellow(path) + ' — ' + colors.bold(colors.yellow(testCaseResult.fullName));
process.stderr.write(`\n${i + 1}) ${colors.red('[FAIL]')} ${name}\n\n`);
process.stderr.write(testCaseResult.failureMessages + '\n');
}
process.exit(130);
});