chore: drop the legacy global setup mode (#13803)

This commit is contained in:
Pavel Feldman 2022-04-27 17:01:37 -08:00 committed by GitHub
parent c70324d0c0
commit a01b65bedd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 280 additions and 298 deletions

View file

@ -149,13 +149,6 @@ export class Runner {
this._reporter = await this._createReporter(!!options.listOnly);
const config = this._loader.fullConfig();
let legacyGlobalTearDown: (() => Promise<void>) | undefined;
if (process.env.PW_TEST_LEGACY_GLOBAL_SETUP_MODE) {
legacyGlobalTearDown = await this._performGlobalSetup(config);
if (!legacyGlobalTearDown)
return { status: 'failed' };
}
const result = await raceAgainstTimeout(() => this._run(!!options.listOnly, options.filePatternFilter || [], options.projectFilter), config.globalTimeout);
let fullResult: FullResult;
if (result.timedOut) {
@ -165,7 +158,6 @@ export class Runner {
fullResult = result.result;
}
await this._reporter.onEnd?.(fullResult);
await legacyGlobalTearDown?.();
// Calling process.exit() might truncate large stdout/stderr output.
// See https://github.com/nodejs/node/issues/6456.
@ -379,12 +371,9 @@ export class Runner {
}
// 13. Run Global setup.
let globalTearDown: (() => Promise<void>) | undefined;
if (!process.env.PW_TEST_LEGACY_GLOBAL_SETUP_MODE) {
globalTearDown = await this._performGlobalSetup(config);
const globalTearDown = await this._performGlobalSetup(config);
if (!globalTearDown)
return { status: 'failed' };
}
const result: FullResult = { status: 'passed' };

View file

@ -16,10 +16,6 @@
import { test, expect, stripAnsi } from './playwright-test-fixtures';
for (const mode of ['legacy', 'default']) {
test.describe(`${mode} mode`, () => {
const env = { PW_TEST_LEGACY_GLOBAL_SETUP_MODE: mode === 'legacy' ? '1' : undefined };
test('globalSetup and globalTeardown should work', async ({ runInlineTest }) => {
const { results, output } = await runInlineTest({
'playwright.config.ts': `
@ -47,7 +43,7 @@ for (const mode of ['legacy', 'default']) {
expect(process.env.FOO).toBe('42');
});
`,
}, undefined, env);
});
expect(results[0].status).toBe('passed');
expect(output).toContain('teardown=42');
});
@ -79,13 +75,12 @@ for (const mode of ['legacy', 'default']) {
expect(process.env.FOO).toBe('43');
});
`,
}, undefined, env);
});
expect(results[0].status).toBe('failed');
expect(output).toContain('teardown=42');
});
test('globalTeardown does not run when globalSetup times out', async ({ runInlineTest }) => {
test.skip(!!env.PW_TEST_LEGACY_GLOBAL_SETUP_MODE);
const result = await runInlineTest({
'playwright.config.ts': `
import * as path from 'path';
@ -110,7 +105,7 @@ for (const mode of ['legacy', 'default']) {
test('should not run', async ({}, testInfo) => {
});
`,
}, undefined, env);
});
// We did not run tests, so we should only have 1 skipped test.
expect(result.skipped).toBe(1);
expect(result.passed).toBe(0);
@ -139,7 +134,7 @@ for (const mode of ['legacy', 'default']) {
expect(value).toEqual({ foo: 'bar' });
});
`,
}, undefined, env);
});
expect(passed).toBe(1);
});
@ -166,7 +161,7 @@ for (const mode of ['legacy', 'default']) {
console.log('this test ran');
});
`,
}, { reporter: 'line' }, env);
}, { reporter: 'line' });
expect(stripAnsi(output)).not.toContain('this test ran');
expect(passed).toBe(0);
@ -188,7 +183,7 @@ for (const mode of ['legacy', 'default']) {
test('should work', async ({}) => {
});
`,
}, undefined, env);
});
expect(output).toContain(`globalSetup.ts: globalSetup file must export a single function.`);
});
@ -216,7 +211,7 @@ for (const mode of ['legacy', 'default']) {
test('should work', async ({}) => {
});
`,
}, undefined, env);
});
expect(passed).toBe(1);
expect(exitCode).toBe(0);
expect(output).toContain(`%%setup: 42`);
@ -244,7 +239,7 @@ for (const mode of ['legacy', 'default']) {
expect(process.env.FOO).toBe('42');
});
`,
}, undefined, env);
});
expect(results[0].status).toBe('passed');
});
@ -290,7 +285,7 @@ for (const mode of ['legacy', 'default']) {
};
test('globalSetup should work for auth', async ({ runInlineTest }) => {
const result = await runInlineTest(authFiles, undefined, env);
const result = await runInlineTest(authFiles);
expect(result.exitCode).toBe(0);
expect(result.passed).toBe(1);
});
@ -299,5 +294,3 @@ for (const mode of ['legacy', 'default']) {
const result = await runTSC(authFiles);
expect(result.exitCode).toBe(0);
});
});
}