fix: run reporter.onEnd after webserver teardown (#11712)

Fixes #11647
This commit is contained in:
Andrey Lushnikov 2022-01-31 07:19:33 -07:00 committed by GitHub
parent f0fc566004
commit b58b004f0f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 31 additions and 2 deletions

View File

@ -144,6 +144,8 @@ export class Runner {
else
this._reporter.onError?.(createStacklessError(`Timed out waiting ${config.globalTimeout / 1000}s for the entire test run`));
return actualResult;
} else if (this._didBegin) {
await this._reporter.onEnd?.(result.result);
}
return result.result;
} catch (e) {
@ -384,13 +386,11 @@ export class Runner {
if (sigint) {
const result: FullResult = { status: 'interrupted' };
await this._reporter.onEnd?.(result);
return result;
}
const failed = hasWorkerErrors || rootSuite.allTests().some(test => !test.ok());
const result: FullResult = { status: failed ? 'failed' : 'passed' };
await this._reporter.onEnd?.(result);
return result;
} finally {
if (globalSetupResult && typeof globalSetupResult === 'function')

View File

@ -176,6 +176,35 @@ test('should work without a file extension', async ({ runInlineTest }) => {
]);
});
test('should report onEnd after global teardown', async ({ runInlineTest }) => {
const result = await runInlineTest({
'reporter.ts': smallReporterJS,
'globalSetup.ts': `
module.exports = () => {
return () => console.log('\\n%%global teardown');
};
`,
'playwright.config.ts': `
module.exports = {
reporter: './reporter',
globalSetup: './globalSetup',
};
`,
'a.test.ts': `
const { test } = pwt;
test('pass', async ({}) => {
});
`
}, { reporter: '', workers: 1 });
expect(result.exitCode).toBe(0);
expect(result.output.split('\n').filter(line => line.startsWith('%%'))).toEqual([
'%%begin',
'%%global teardown',
'%%end',
]);
});
test('should load reporter from node_modules', async ({ runInlineTest }) => {
const result = await runInlineTest({
'node_modules/my-reporter/index.js': smallReporterJS,