fix(test-runner): fix browser initialization in test modifiers (#11984)
Fixes #11985
This commit is contained in:
parent
ae7c52154f
commit
6904b3294e
|
|
@ -88,7 +88,7 @@ export const test = _baseTest.extend<TestFixtures, WorkerFixtures>({
|
||||||
await removeFolders([dir]);
|
await removeFolders([dir]);
|
||||||
}, { scope: 'worker' }],
|
}, { scope: 'worker' }],
|
||||||
|
|
||||||
_browserOptions: [async ({ headless, channel, launchOptions }, use) => {
|
_browserOptions: [async ({ playwright, headless, channel, launchOptions }, use) => {
|
||||||
const options: LaunchOptions = {
|
const options: LaunchOptions = {
|
||||||
handleSIGINT: false,
|
handleSIGINT: false,
|
||||||
timeout: 0,
|
timeout: 0,
|
||||||
|
|
@ -98,8 +98,13 @@ export const test = _baseTest.extend<TestFixtures, WorkerFixtures>({
|
||||||
options.headless = headless;
|
options.headless = headless;
|
||||||
if (channel !== undefined)
|
if (channel !== undefined)
|
||||||
options.channel = channel;
|
options.channel = channel;
|
||||||
|
|
||||||
|
for (const browserType of [playwright.chromium, playwright.firefox, playwright.webkit])
|
||||||
|
(browserType as any)._defaultLaunchOptions = options;
|
||||||
await use(options);
|
await use(options);
|
||||||
}, { scope: 'worker' }],
|
for (const browserType of [playwright.chromium, playwright.firefox, playwright.webkit])
|
||||||
|
(browserType as any)._defaultLaunchOptions = undefined;
|
||||||
|
}, { scope: 'worker', auto: true }],
|
||||||
|
|
||||||
browser: [async ({ playwright, browserName, connectOptions }, use) => {
|
browser: [async ({ playwright, browserName, connectOptions }, use) => {
|
||||||
if (!['chromium', 'firefox', 'webkit'].includes(browserName))
|
if (!['chromium', 'firefox', 'webkit'].includes(browserName))
|
||||||
|
|
@ -323,7 +328,6 @@ export const test = _baseTest.extend<TestFixtures, WorkerFixtures>({
|
||||||
(browserType as any)._onDidCreateContext = onDidCreateBrowserContext;
|
(browserType as any)._onDidCreateContext = onDidCreateBrowserContext;
|
||||||
(browserType as any)._onWillCloseContext = onWillCloseContext;
|
(browserType as any)._onWillCloseContext = onWillCloseContext;
|
||||||
(browserType as any)._defaultContextOptions = _combinedContextOptions;
|
(browserType as any)._defaultContextOptions = _combinedContextOptions;
|
||||||
(browserType as any)._defaultLaunchOptions = _browserOptions;
|
|
||||||
const existingContexts = Array.from((browserType as any)._contexts) as BrowserContext[];
|
const existingContexts = Array.from((browserType as any)._contexts) as BrowserContext[];
|
||||||
await Promise.all(existingContexts.map(onDidCreateBrowserContext));
|
await Promise.all(existingContexts.map(onDidCreateBrowserContext));
|
||||||
}
|
}
|
||||||
|
|
@ -365,7 +369,6 @@ export const test = _baseTest.extend<TestFixtures, WorkerFixtures>({
|
||||||
(browserType as any)._onDidCreateContext = undefined;
|
(browserType as any)._onDidCreateContext = undefined;
|
||||||
(browserType as any)._onWillCloseContext = undefined;
|
(browserType as any)._onWillCloseContext = undefined;
|
||||||
(browserType as any)._defaultContextOptions = undefined;
|
(browserType as any)._defaultContextOptions = undefined;
|
||||||
(browserType as any)._defaultLaunchOptions = undefined;
|
|
||||||
}
|
}
|
||||||
leftoverContexts.forEach(context => (context as any)._instrumentation.removeAllListeners());
|
leftoverContexts.forEach(context => (context as any)._instrumentation.removeAllListeners());
|
||||||
for (const context of (playwright.request as any)._contexts)
|
for (const context of (playwright.request as any)._contexts)
|
||||||
|
|
|
||||||
|
|
@ -257,6 +257,26 @@ test('should respect headless in launchPersistent', async ({ runInlineTest }) =>
|
||||||
expect(result.passed).toBe(1);
|
expect(result.passed).toBe(1);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('should respect headless in modifiers that run before tests', async ({ runInlineTest }) => {
|
||||||
|
const result = await runInlineTest({
|
||||||
|
'playwright.config.ts': `
|
||||||
|
module.exports = { use: { headless: false } };
|
||||||
|
`,
|
||||||
|
'a.test.ts': `
|
||||||
|
const { test } = pwt;
|
||||||
|
|
||||||
|
test.skip(({ browser }) => false);
|
||||||
|
|
||||||
|
test('should work', async ({ page }) => {
|
||||||
|
expect(await page.evaluate(() => navigator.userAgent)).not.toContain('Headless');
|
||||||
|
});
|
||||||
|
`,
|
||||||
|
}, { workers: 1 });
|
||||||
|
|
||||||
|
expect(result.exitCode).toBe(0);
|
||||||
|
expect(result.passed).toBe(1);
|
||||||
|
});
|
||||||
|
|
||||||
test('should call logger from launchOptions config', async ({ runInlineTest }, testInfo) => {
|
test('should call logger from launchOptions config', async ({ runInlineTest }, testInfo) => {
|
||||||
const result = await runInlineTest({
|
const result = await runInlineTest({
|
||||||
'a.test.ts': `
|
'a.test.ts': `
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue