mirror of
https://github.com/microsoft/playwright.git
synced 2025-06-26 21:40:17 +00:00
fix(testrunner): report unhandled rejection ones, allow retry (#3686)
This commit is contained in:
parent
abb50a79bd
commit
c47af2d4f3
@ -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;
|
||||
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;
|
||||
|
23
test-runner/test/assets/unhandled-rejection.js
Normal file
23
test-runner/test/assets/unhandled-rejection.js
Normal 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));
|
||||
});
|
@ -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');
|
||||
|
Loading…
x
Reference in New Issue
Block a user