mirror of
https://github.com/microsoft/playwright.git
synced 2025-06-26 21:40:17 +00:00
fix(test-fail): allow unhandled expects in test.fail (#11850)
Previously, we would consider this a worker error, but we make an exception for "expect()" calls.
This commit is contained in:
parent
72424dc904
commit
d9a8bb057d
@ -94,7 +94,11 @@ export class WorkerRunner extends EventEmitter {
|
||||
// a test runner. In the latter case, the worker state could be messed up,
|
||||
// and continuing to run tests in the same worker is problematic. Therefore,
|
||||
// we turn this into a fatal error and restart the worker anyway.
|
||||
if (this._currentTest && this._currentTest._test._type === 'test' && this._currentTest.expectedStatus !== 'failed') {
|
||||
// The only exception is the expect() error that we still consider ok.
|
||||
const isExpectError = (error instanceof Error) && !!(error as any).matcherResult;
|
||||
const isCurrentTestExpectedToFail = this._currentTest?.expectedStatus === 'failed';
|
||||
const shouldConsiderAsTestError = isExpectError || !isCurrentTestExpectedToFail;
|
||||
if (this._currentTest && this._currentTest._test._type === 'test' && shouldConsiderAsTestError) {
|
||||
this._currentTest._failWithError(serializeError(error), true /* isHardError */);
|
||||
} else {
|
||||
// No current test - fatal error.
|
||||
|
||||
@ -426,3 +426,19 @@ test('should not reuse worker after unhandled rejection in test.fail', async ({
|
||||
expect(result.output).toContain(`Error: Oh my!`);
|
||||
expect(result.output).not.toContain(`Did not teardown test scope`);
|
||||
});
|
||||
|
||||
test('should allow unhandled expects in test.fail', async ({ runInlineTest }) => {
|
||||
const result = await runInlineTest({
|
||||
'a.spec.ts': `
|
||||
const { test } = pwt;
|
||||
test('failing1', async ({}) => {
|
||||
test.fail();
|
||||
Promise.resolve().then(() => expect(1).toBe(2));
|
||||
await new Promise(f => setTimeout(f, 100));
|
||||
});
|
||||
`
|
||||
});
|
||||
expect(result.exitCode).toBe(0);
|
||||
expect(result.passed).toBe(1);
|
||||
expect(result.output).not.toContain(`Error: expect`);
|
||||
});
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user