mirror of
https://github.com/microsoft/playwright.git
synced 2025-06-26 21:40:17 +00:00
fix(test runner): report unhandled rejections during worker teardown (#8592)
This commit is contained in:
parent
fd5c10e5d7
commit
900362ec0b
@ -74,7 +74,7 @@ process.on('message', async message => {
|
|||||||
workerIndex = initParams.workerIndex;
|
workerIndex = initParams.workerIndex;
|
||||||
startProfiling();
|
startProfiling();
|
||||||
workerRunner = new WorkerRunner(initParams);
|
workerRunner = new WorkerRunner(initParams);
|
||||||
for (const event of ['testBegin', 'testEnd', 'stepBegin', 'stepEnd', 'done'])
|
for (const event of ['testBegin', 'testEnd', 'stepBegin', 'stepEnd', 'done', 'teardownError'])
|
||||||
workerRunner.on(event, sendMessageToParent.bind(null, event));
|
workerRunner.on(event, sendMessageToParent.bind(null, event));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -76,8 +76,10 @@ export class WorkerRunner extends EventEmitter {
|
|||||||
await this._fixtureRunner.teardownScope('test');
|
await this._fixtureRunner.teardownScope('test');
|
||||||
await this._fixtureRunner.teardownScope('worker');
|
await this._fixtureRunner.teardownScope('worker');
|
||||||
})(), this._deadline());
|
})(), this._deadline());
|
||||||
if (result.timedOut)
|
if (result.timedOut && !this._fatalError)
|
||||||
throw new Error(`Timeout of ${this._project.config.timeout}ms exceeded while shutting down environment`);
|
this._fatalError = { message: colors.red(`Timeout of ${this._project.config.timeout}ms exceeded while shutting down environment`) };
|
||||||
|
if (this._fatalError)
|
||||||
|
this.emit('teardownError', { error: this._fatalError });
|
||||||
}
|
}
|
||||||
|
|
||||||
unhandledError(error: Error | any) {
|
unhandledError(error: Error | any) {
|
||||||
@ -502,6 +504,7 @@ export class WorkerRunner extends EventEmitter {
|
|||||||
fatalError: this._fatalError,
|
fatalError: this._fatalError,
|
||||||
};
|
};
|
||||||
this.emit('done', donePayload);
|
this.emit('done', donePayload);
|
||||||
|
this._fatalError = undefined;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -382,3 +382,18 @@ test('test.skip should define a skipped test', async ({ runInlineTest }) => {
|
|||||||
expect(result.skipped).toBe(1);
|
expect(result.skipped).toBe(1);
|
||||||
expect(result.output).not.toContain('%%dontseethis');
|
expect(result.output).not.toContain('%%dontseethis');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('should report unhandled rejection during worker shutdown', async ({ runInlineTest }) => {
|
||||||
|
const result = await runInlineTest({
|
||||||
|
'a.test.ts': `
|
||||||
|
const { test } = pwt;
|
||||||
|
test('unhandled rejection', async () => {
|
||||||
|
new Promise((f, r) => r(new Error('Unhandled')));
|
||||||
|
});
|
||||||
|
`,
|
||||||
|
});
|
||||||
|
expect(result.exitCode).toBe(1);
|
||||||
|
expect(result.passed).toBe(1);
|
||||||
|
expect(result.output).toContain('Error: Unhandled');
|
||||||
|
expect(result.output).toContain('a.test.ts:7:33');
|
||||||
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user