fix(test runner): do not mask uncaught error in beforeEach (#9764)
This commit is contained in:
parent
ada7f4be23
commit
13ed1dee50
|
|
@ -435,8 +435,12 @@ export class WorkerRunner extends EventEmitter {
|
||||||
if (testInfo.status === 'passed')
|
if (testInfo.status === 'passed')
|
||||||
testInfo.status = 'skipped';
|
testInfo.status = 'skipped';
|
||||||
} else {
|
} else {
|
||||||
testInfo.status = 'failed';
|
if (testInfo.status === 'passed')
|
||||||
testInfo.error = serializeError(error);
|
testInfo.status = 'failed';
|
||||||
|
// Do not overwrite any uncaught error that happened first.
|
||||||
|
// This is typical if you have some expect() that fails in beforeEach.
|
||||||
|
if (!('error' in testInfo))
|
||||||
|
testInfo.error = serializeError(error);
|
||||||
}
|
}
|
||||||
// Continue running afterEach hooks even after the failure.
|
// Continue running afterEach hooks even after the failure.
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,7 @@
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { test, expect } from './playwright-test-fixtures';
|
import { test, expect, stripAscii } from './playwright-test-fixtures';
|
||||||
|
|
||||||
test('hooks should work with fixtures', async ({ runInlineTest }) => {
|
test('hooks should work with fixtures', async ({ runInlineTest }) => {
|
||||||
const { results } = await runInlineTest({
|
const { results } = await runInlineTest({
|
||||||
|
|
@ -517,3 +517,29 @@ test('afterEach should get the test status right away', async ({ runInlineTest }
|
||||||
'%%timing out: timedOut',
|
'%%timing out: timedOut',
|
||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('uncaught error in beforeEach should not be masked by another error', async ({ runInlineTest }) => {
|
||||||
|
const result = await runInlineTest({
|
||||||
|
'a.test.js': `
|
||||||
|
const test = pwt.test.extend({
|
||||||
|
foo: async ({}, use) => {
|
||||||
|
let cb;
|
||||||
|
await use(new Promise((f, r) => cb = r));
|
||||||
|
cb(new Error('Oh my!'));
|
||||||
|
},
|
||||||
|
});
|
||||||
|
test.beforeEach(async ({ foo }, testInfo) => {
|
||||||
|
setTimeout(() => {
|
||||||
|
expect(1).toBe(2);
|
||||||
|
}, 0);
|
||||||
|
await foo;
|
||||||
|
});
|
||||||
|
test('passing', () => {
|
||||||
|
});
|
||||||
|
`,
|
||||||
|
});
|
||||||
|
expect(result.exitCode).toBe(1);
|
||||||
|
expect(result.failed).toBe(1);
|
||||||
|
expect(stripAscii(result.output)).toContain('Expected: 2');
|
||||||
|
expect(stripAscii(result.output)).toContain('Received: 1');
|
||||||
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue