mirror of
https://github.com/microsoft/playwright.git
synced 2025-06-26 21:40:17 +00:00
fix(runner): globalTeardown without globalSetup should work (#15814)
This commit is contained in:
parent
b117ad826c
commit
f954891491
@ -473,12 +473,17 @@ export class Runner {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// The do global setup.
|
// The do global setup.
|
||||||
if (!sigintWatcher.hadSignal() && config.globalSetup) {
|
if (!sigintWatcher.hadSignal()) {
|
||||||
|
if (config.globalSetup) {
|
||||||
const hook = await this._loader.loadGlobalHook(config.globalSetup, 'globalSetup');
|
const hook = await this._loader.loadGlobalHook(config.globalSetup, 'globalSetup');
|
||||||
await Promise.race([
|
await Promise.race([
|
||||||
Promise.resolve().then(() => hook(this._loader.fullConfig())).then((r: any) => globalSetupResult = r || '<noop>'),
|
Promise.resolve().then(() => hook(this._loader.fullConfig())).then((r: any) => globalSetupResult = r || '<noop>'),
|
||||||
sigintWatcher.promise(),
|
sigintWatcher.promise(),
|
||||||
]);
|
]);
|
||||||
|
} else {
|
||||||
|
// Make sure we run globalTeardown.
|
||||||
|
globalSetupResult = '<noop>';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}, result);
|
}, result);
|
||||||
|
|
||||||
|
|||||||
@ -48,6 +48,29 @@ test('globalSetup and globalTeardown should work', async ({ runInlineTest }) =>
|
|||||||
expect(output).toContain('teardown=42');
|
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 }) => {
|
test('globalTeardown runs after failures', async ({ runInlineTest }) => {
|
||||||
const { results, output } = await runInlineTest({
|
const { results, output } = await runInlineTest({
|
||||||
'playwright.config.ts': `
|
'playwright.config.ts': `
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user