mirror of
https://github.com/microsoft/playwright.git
synced 2024-10-26 21:33:38 +03:00
fix(runner): skip global hooks in --list mode (#9480)
This commit is contained in:
parent
e4056d3c83
commit
e827bde1c2
@ -180,7 +180,7 @@ export class Runner {
|
||||
|
||||
const webServer = (!list && config.webServer) ? await WebServer.create(config.webServer) : undefined;
|
||||
let globalSetupResult: any;
|
||||
if (config.globalSetup)
|
||||
if (config.globalSetup && !list)
|
||||
globalSetupResult = await (await this._loader.loadGlobalHook(config.globalSetup, 'globalSetup'))(this._loader.fullConfig());
|
||||
try {
|
||||
for (const file of allTestFiles)
|
||||
@ -326,7 +326,7 @@ export class Runner {
|
||||
} finally {
|
||||
if (globalSetupResult && typeof globalSetupResult === 'function')
|
||||
await globalSetupResult(this._loader.fullConfig());
|
||||
if (config.globalTeardown)
|
||||
if (config.globalTeardown && !list)
|
||||
await (await this._loader.loadGlobalHook(config.globalTeardown, 'globalTeardown'))(this._loader.fullConfig());
|
||||
await webServer?.kill();
|
||||
}
|
||||
|
@ -64,3 +64,44 @@ test('should not list tests to stdout when JSON reporter is used', async ({ runI
|
||||
expect(result.report.suites[0].specs.length).toBe(2);
|
||||
expect(result.report.suites[0].specs.map(spec => spec.title)).toStrictEqual(['example1', 'example2']);
|
||||
});
|
||||
|
||||
test('globalSetup and globalTeardown should not run', async ({ runInlineTest }) => {
|
||||
const result = await runInlineTest({
|
||||
'playwright.config.ts': `
|
||||
import * as path from 'path';
|
||||
module.exports = {
|
||||
globalSetup: './globalSetup',
|
||||
globalTeardown: './globalTeardown.ts',
|
||||
};
|
||||
`,
|
||||
'globalSetup.ts': `
|
||||
module.exports = () => {
|
||||
console.log('Running globalSetup');
|
||||
};
|
||||
`,
|
||||
'globalTeardown.ts': `
|
||||
module.exports = () => {
|
||||
console.log('Running globalTeardown');
|
||||
};
|
||||
`,
|
||||
'a.test.js': `
|
||||
const { test } = pwt;
|
||||
test('should work 1', async ({}, testInfo) => {
|
||||
console.log('Running test 1');
|
||||
});
|
||||
`,
|
||||
'b.test.js': `
|
||||
const { test } = pwt;
|
||||
test('should work 2', async ({}, testInfo) => {
|
||||
console.log('Running test 2');
|
||||
});
|
||||
`,
|
||||
}, { 'list': true });
|
||||
expect(result.exitCode).toBe(0);
|
||||
expect(result.output).toContain([
|
||||
`Listing tests:`,
|
||||
` a.test.js:6:7 › should work 1`,
|
||||
` b.test.js:6:7 › should work 2`,
|
||||
`Total: 2 tests in 2 files`,
|
||||
].join('\n'));
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user