mirror of
https://github.com/microsoft/playwright.git
synced 2025-06-26 21:40:17 +00:00
fix(test runner): report beforeAll timeout instead of hanging (#8529)
We used to not report fatal error and hang forever because worker did not run any tests but also did not report any errors. Also properly show stack-less errors.
This commit is contained in:
parent
60b0f46b60
commit
37a897c9b4
@ -239,6 +239,9 @@ function formatError(error: TestError, file?: string) {
|
||||
}
|
||||
tokens.push('');
|
||||
tokens.push(colors.dim(preamble.length > 0 ? stack.substring(preamble.length + 1) : stack));
|
||||
} else if (error.message) {
|
||||
tokens.push('');
|
||||
tokens.push(error.message);
|
||||
} else {
|
||||
tokens.push('');
|
||||
tokens.push(error.value);
|
||||
|
@ -18,6 +18,7 @@ import fs from 'fs';
|
||||
import path from 'path';
|
||||
import rimraf from 'rimraf';
|
||||
import util from 'util';
|
||||
import colors from 'colors/safe';
|
||||
import { EventEmitter } from 'events';
|
||||
import { monotonicTime, DeadlineRunner, raceAgainstDeadline, serializeError, sanitizeForFilePath } from './util';
|
||||
import { TestBeginPayload, TestEndPayload, RunPayload, TestEntry, DonePayload, WorkerInitParams, StepBeginPayload, StepEndPayload } from './ipc';
|
||||
@ -375,10 +376,14 @@ export class WorkerRunner extends EventEmitter {
|
||||
setCurrentTestInfo(null);
|
||||
|
||||
if (isFailure) {
|
||||
if (test._type === 'test')
|
||||
if (test._type === 'test') {
|
||||
this._failedTestId = testId;
|
||||
else if (!this._fatalError)
|
||||
this._fatalError = testInfo.error;
|
||||
} else if (!this._fatalError) {
|
||||
if (testInfo.status === 'timedOut')
|
||||
this._fatalError = { message: colors.red(`Timeout of ${testInfo.timeout}ms exceeded in ${test._type} hook.`) };
|
||||
else
|
||||
this._fatalError = testInfo.error;
|
||||
}
|
||||
this.stop();
|
||||
}
|
||||
}
|
||||
|
@ -210,3 +210,19 @@ test('should print flaky timeouts', async ({ runInlineTest }) => {
|
||||
expect(result.flaky).toBe(1);
|
||||
expect(stripAscii(result.output)).toContain('Timeout of 1000ms exceeded.');
|
||||
});
|
||||
|
||||
test('should print stack-less errors', async ({ runInlineTest }) => {
|
||||
const result = await runInlineTest({
|
||||
'a.spec.ts': `
|
||||
const { test } = pwt;
|
||||
test('foobar', async ({}) => {
|
||||
const e = new Error('Hello');
|
||||
delete e.stack;
|
||||
throw e;
|
||||
});
|
||||
`
|
||||
});
|
||||
expect(result.exitCode).toBe(1);
|
||||
expect(result.failed).toBe(1);
|
||||
expect(result.output).toContain('Hello');
|
||||
});
|
||||
|
@ -420,3 +420,76 @@ test('afterAll error should not mask beforeAll', async ({ runInlineTest }) => {
|
||||
expect(result.failed).toBe(1);
|
||||
expect(result.output).toContain('from beforeAll');
|
||||
});
|
||||
|
||||
test('beforeAll timeout should be reported', async ({ runInlineTest }) => {
|
||||
const result = await runInlineTest({
|
||||
'a.test.js': `
|
||||
const { test } = pwt;
|
||||
test.beforeAll(async () => {
|
||||
console.log('\\n%%beforeAll');
|
||||
await new Promise(f => setTimeout(f, 5000));
|
||||
});
|
||||
test.afterAll(() => {
|
||||
console.log('\\n%%afterAll');
|
||||
});
|
||||
test('skipped', () => {
|
||||
console.log('\\n%%test');
|
||||
});
|
||||
`,
|
||||
}, { timeout: 1000 });
|
||||
expect(result.exitCode).toBe(1);
|
||||
expect(result.failed).toBe(1);
|
||||
expect(result.output.split('\n').filter(line => line.startsWith('%%'))).toEqual([
|
||||
'%%beforeAll',
|
||||
'%%afterAll',
|
||||
]);
|
||||
expect(result.output).toContain('Timeout of 1000ms exceeded in beforeAll hook.');
|
||||
});
|
||||
|
||||
test('afterAll timeout should be reported', async ({ runInlineTest }) => {
|
||||
const result = await runInlineTest({
|
||||
'a.test.js': `
|
||||
const { test } = pwt;
|
||||
test.afterAll(async () => {
|
||||
console.log('\\n%%afterAll');
|
||||
await new Promise(f => setTimeout(f, 5000));
|
||||
});
|
||||
test('runs', () => {
|
||||
console.log('\\n%%test');
|
||||
});
|
||||
`,
|
||||
}, { timeout: 1000 });
|
||||
expect(result.exitCode).toBe(1);
|
||||
expect(result.passed).toBe(1);
|
||||
expect(result.output.split('\n').filter(line => line.startsWith('%%'))).toEqual([
|
||||
'%%test',
|
||||
'%%afterAll',
|
||||
]);
|
||||
expect(result.output).toContain('Timeout of 1000ms exceeded in afterAll hook.');
|
||||
});
|
||||
|
||||
test('beforeAll and afterAll timeouts at the same time should be reported', async ({ runInlineTest }) => {
|
||||
const result = await runInlineTest({
|
||||
'a.test.js': `
|
||||
const { test } = pwt;
|
||||
test.beforeAll(async () => {
|
||||
console.log('\\n%%beforeAll');
|
||||
await new Promise(f => setTimeout(f, 5000));
|
||||
});
|
||||
test.afterAll(async () => {
|
||||
console.log('\\n%%afterAll');
|
||||
await new Promise(f => setTimeout(f, 5000));
|
||||
});
|
||||
test('skipped', () => {
|
||||
console.log('\\n%%test');
|
||||
});
|
||||
`,
|
||||
}, { timeout: 1000 });
|
||||
expect(result.exitCode).toBe(1);
|
||||
expect(result.failed).toBe(1);
|
||||
expect(result.output.split('\n').filter(line => line.startsWith('%%'))).toEqual([
|
||||
'%%beforeAll',
|
||||
'%%afterAll',
|
||||
]);
|
||||
expect(result.output).toContain('Timeout of 1000ms exceeded in beforeAll hook.');
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user