fix(runner): globalTeardown without globalSetup should work (#15814)

This commit is contained in:
Dmitry Gozman 2022-07-20 12:41:35 -07:00 committed by GitHub
parent b117ad826c
commit f954891491
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 34 additions and 6 deletions

View File

@ -473,12 +473,17 @@ export class Runner {
}
// The do global setup.
if (!sigintWatcher.hadSignal() && config.globalSetup) {
const hook = await this._loader.loadGlobalHook(config.globalSetup, 'globalSetup');
await Promise.race([
Promise.resolve().then(() => hook(this._loader.fullConfig())).then((r: any) => globalSetupResult = r || '<noop>'),
sigintWatcher.promise(),
]);
if (!sigintWatcher.hadSignal()) {
if (config.globalSetup) {
const hook = await this._loader.loadGlobalHook(config.globalSetup, 'globalSetup');
await Promise.race([
Promise.resolve().then(() => hook(this._loader.fullConfig())).then((r: any) => globalSetupResult = r || '<noop>'),
sigintWatcher.promise(),
]);
} else {
// Make sure we run globalTeardown.
globalSetupResult = '<noop>';
}
}
}, result);

View File

@ -48,6 +48,29 @@ test('globalSetup and globalTeardown should work', async ({ runInlineTest }) =>
expect(output).toContain('teardown=42');
});
test('standalone globalTeardown should work', async ({ runInlineTest }) => {
const { results, output } = await runInlineTest({
'playwright.config.ts': `
import * as path from 'path';
module.exports = {
globalTeardown: './globalTeardown.ts',
};
`,
'globalTeardown.ts': `
module.exports = async () => {
console.log('got my teardown');
};
`,
'a.test.js': `
const { test } = pwt;
test('should work', async ({}, testInfo) => {
});
`,
});
expect(results[0].status).toBe('passed');
expect(output).toContain('got my teardown');
});
test('globalTeardown runs after failures', async ({ runInlineTest }) => {
const { results, output } = await runInlineTest({
'playwright.config.ts': `