fix(testrunner): report unhandled rejection ones, allow retry (#3686)

This commit is contained in:
Pavel Feldman 2020-08-28 18:25:09 -07:00 committed by GitHub
parent abb50a79bd
commit c47af2d4f3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 39 additions and 1 deletions

View File

@ -78,11 +78,14 @@ export class TestRunner extends EventEmitter {
unhandledError(error: Error | any) {
if (this._testResult) {
this._testResult.status = 'failed';
this._testResult.error = serializeError(error);
this._failedTestId = this._testId;
this.emit('testEnd', {
id: this._testId,
result: this._testResult
});
this._testResult = null;
} else if (!this._loaded) {
// No current test - fatal error.
this._fatalError = serializeError(error);
@ -197,7 +200,10 @@ export class TestRunner extends EventEmitter {
result.error = serializeError(error);
}
result.duration = Date.now() - startTime;
this.emit('testEnd', { id, result });
if (this._testResult) {
// We could have reported end due to an unhandled exception.
this.emit('testEnd', { id, result });
}
if (result.status !== 'passed')
this._failedTestId = this._testId;
this._testResult = null;

View File

@ -0,0 +1,23 @@
/**
* Copyright (c) Microsoft Corporation.
*
* 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.
*/
require('../../');
it('unhandled rejection', async () => {
setTimeout(() => {
throw new Error('Unhandled rejection in the test');
});
await new Promise(f => setTimeout(f, 20));
});

View File

@ -162,6 +162,15 @@ it('should respect nested skip', async () => {
expect(skipped).toBe(1);
});
it('should retry unhandled rejection', async () => {
const result = await runTest('unhandled-rejection.js', { retries: 2 });
expect(result.exitCode).toBe(1);
expect(result.passed).toBe(0);
expect(result.failed).toBe(1);
expect(result.output.split('\n')[0]).toBe(colors.red('F').repeat(3));
expect(result.output).toContain('Unhandled rejection');
});
async function runTest(filePath: string, params: any = {}) {
const outputDir = path.join(__dirname, 'test-results');
const reportFile = path.join(outputDir, 'results.json');