chore: don't allow importing @playwright/test twice (#11218)

This commit is contained in:
Pavel Feldman 2022-01-06 09:29:05 -08:00 committed by GitHub
parent 2496355665
commit 373042ed89
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 18 additions and 7 deletions

View file

@ -25,6 +25,18 @@ import { prependToTestError } from './util';
export { expect } from './expect'; export { expect } from './expect';
export const _baseTest: TestType<{}, {}> = rootTestType.test; export const _baseTest: TestType<{}, {}> = rootTestType.test;
if ((process as any)['__pw_initiator__']) {
const originalStackTraceLimit = Error.stackTraceLimit;
Error.stackTraceLimit = 200;
try {
throw new Error('Requiring @playwright/test second time, \nFirst:\n' + (process as any)['__pw_initiator__'] + '\n\nSecond: ');
} finally {
Error.stackTraceLimit = originalStackTraceLimit;
}
} else {
(process as any)['__pw_initiator__'] = new Error().stack;
}
type TestFixtures = PlaywrightTestArgs & PlaywrightTestOptions & { type TestFixtures = PlaywrightTestArgs & PlaywrightTestOptions & {
_combinedContextOptions: BrowserContextOptions, _combinedContextOptions: BrowserContextOptions,
_setupContextOptionsAndArtifacts: void; _setupContextOptionsAndArtifacts: void;

View file

@ -16,7 +16,7 @@
import { test, TestType, Fixtures } from '@playwright/test'; import { test, TestType, Fixtures } from '@playwright/test';
import { commonFixtures, CommonFixtures } from './commonFixtures'; import { commonFixtures, CommonFixtures } from './commonFixtures';
import { serverTest } from './serverFixtures'; import { serverFixtures, ServerFixtures, ServerWorkerOptions } from './serverFixtures';
import { coverageTest } from './coverageFixtures'; import { coverageTest } from './coverageFixtures';
import { platformTest } from './platformFixtures'; import { platformTest } from './platformFixtures';
import { testModeTest } from './testModeFixtures'; import { testModeTest } from './testModeFixtures';
@ -34,7 +34,7 @@ export const baseTest = base
._extendTest(platformTest) ._extendTest(platformTest)
._extendTest(testModeTest) ._extendTest(testModeTest)
.extend<CommonFixtures>(commonFixtures) .extend<CommonFixtures>(commonFixtures)
._extendTest(serverTest) .extend<ServerFixtures, ServerWorkerOptions>(serverFixtures)
.extend<{}, { _snapshotSuffix: string }>({ .extend<{}, { _snapshotSuffix: string }>({
_snapshotSuffix: ['', { scope: 'worker' }], _snapshotSuffix: ['', { scope: 'worker' }],
}); });

View file

@ -14,7 +14,7 @@
* limitations under the License. * limitations under the License.
*/ */
import { test, Fixtures } from '@playwright/test'; import type { Fixtures } from '@playwright/test';
import path from 'path'; import path from 'path';
import socks from 'socksv5'; import socks from 'socksv5';
import { TestServer } from '../../utils/testserver'; import { TestServer } from '../../utils/testserver';
@ -22,6 +22,7 @@ import { TestProxy } from './proxy';
export type ServerWorkerOptions = { export type ServerWorkerOptions = {
loopback?: string; loopback?: string;
__servers: ServerFixtures & { socksServer: socks.SocksServer };
}; };
export type ServerFixtures = { export type ServerFixtures = {
@ -32,8 +33,7 @@ export type ServerFixtures = {
asset: (p: string) => string; asset: (p: string) => string;
}; };
export type ServersInternal = ServerFixtures & { socksServer: socks.SocksServer }; export const serverFixtures: Fixtures<ServerFixtures, ServerWorkerOptions> = {
export const serverFixtures: Fixtures<ServerFixtures, { __servers: ServersInternal } & ServerWorkerOptions> = {
loopback: [ undefined, { scope: 'worker', option: true } ], loopback: [ undefined, { scope: 'worker', option: true } ],
__servers: [ async ({ loopback }, run, workerInfo) => { __servers: [ async ({ loopback }, run, workerInfo) => {
const assetsPath = path.join(__dirname, '..', 'assets'); const assetsPath = path.join(__dirname, '..', 'assets');
@ -111,4 +111,3 @@ export const serverFixtures: Fixtures<ServerFixtures, { __servers: ServersIntern
}, },
}; };
export const serverTest = test.extend<ServerFixtures, ServerWorkerOptions & { __servers: ServersInternal }>(serverFixtures);

View file

@ -197,7 +197,7 @@ type Fixtures = {
export const test = base export const test = base
.extend<CommonFixtures>(commonFixtures) .extend<CommonFixtures>(commonFixtures)
.extend<ServerFixtures, ServerWorkerOptions>(serverFixtures as any) .extend<ServerFixtures, ServerWorkerOptions>(serverFixtures)
.extend<Fixtures>({ .extend<Fixtures>({
writeFiles: async ({}, use, testInfo) => { writeFiles: async ({}, use, testInfo) => {
await use(files => writeFiles(testInfo, files)); await use(files => writeFiles(testInfo, files));