fix(runner): skip global hooks in --list mode (#9480)

This commit is contained in:
Yury Semikhatsky 2021-10-13 14:18:15 -07:00 committed by GitHub
parent e4056d3c83
commit e827bde1c2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 43 additions and 2 deletions

View File

@ -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();
}

View File

@ -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'));
});