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 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 & {
_combinedContextOptions: BrowserContextOptions,
_setupContextOptionsAndArtifacts: void;

View File

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

View File

@ -14,7 +14,7 @@
* limitations under the License.
*/
import { test, Fixtures } from '@playwright/test';
import type { Fixtures } from '@playwright/test';
import path from 'path';
import socks from 'socksv5';
import { TestServer } from '../../utils/testserver';
@ -22,6 +22,7 @@ import { TestProxy } from './proxy';
export type ServerWorkerOptions = {
loopback?: string;
__servers: ServerFixtures & { socksServer: socks.SocksServer };
};
export type ServerFixtures = {
@ -32,8 +33,7 @@ export type ServerFixtures = {
asset: (p: string) => string;
};
export type ServersInternal = ServerFixtures & { socksServer: socks.SocksServer };
export const serverFixtures: Fixtures<ServerFixtures, { __servers: ServersInternal } & ServerWorkerOptions> = {
export const serverFixtures: Fixtures<ServerFixtures, ServerWorkerOptions> = {
loopback: [ undefined, { scope: 'worker', option: true } ],
__servers: [ async ({ loopback }, run, workerInfo) => {
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
.extend<CommonFixtures>(commonFixtures)
.extend<ServerFixtures, ServerWorkerOptions>(serverFixtures as any)
.extend<ServerFixtures, ServerWorkerOptions>(serverFixtures)
.extend<Fixtures>({
writeFiles: async ({}, use, testInfo) => {
await use(files => writeFiles(testInfo, files));