Skip to content

Commit f2916d4

Browse files
authored
cherry-pick(#19627): fix(screenshot): account for screenshot === undefined (#19631)
1 parent db88d4b commit f2916d4

File tree

2 files changed

+92
-3
lines changed

2 files changed

+92
-3
lines changed

packages/playwright-test/src/index.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import type { APIRequestContext, BrowserContext, BrowserContextOptions, LaunchOp
2020
import * as playwrightLibrary from 'playwright-core';
2121
import { createGuid, debugMode } from 'playwright-core/lib/utils';
2222
import { removeFolders } from 'playwright-core/lib/utils/fileUtils';
23-
import type { Fixtures, PlaywrightTestArgs, PlaywrightTestOptions, PlaywrightWorkerArgs, PlaywrightWorkerOptions, TestInfo, TestType, TraceMode, VideoMode } from '../types/test';
23+
import type { Fixtures, PlaywrightTestArgs, PlaywrightTestOptions, PlaywrightWorkerArgs, PlaywrightWorkerOptions, ScreenshotMode, TestInfo, TestType, TraceMode, VideoMode } from '../types/test';
2424
import { store as _baseStore } from './store';
2525
import type { TestInfoImpl } from './testInfo';
2626
import { rootTestType, _setProjectSetup } from './testType';
@@ -246,8 +246,8 @@ const playwrightFixtures: Fixtures<TestFixtures, WorkerFixtures> = ({
246246
if (debugMode())
247247
testInfo.setTimeout(0);
248248

249-
const screenshotOptions = typeof screenshot !== 'string' ? { fullPage: screenshot.fullPage, omitBackground: screenshot.omitBackground } : undefined;
250-
const screenshotMode = typeof screenshot === 'string' ? screenshot : screenshot.mode;
249+
const screenshotMode = normalizeScreenshotMode(screenshot);
250+
const screenshotOptions = typeof screenshot === 'string' ? undefined : screenshot;
251251
const traceMode = normalizeTraceMode(trace);
252252
const defaultTraceOptions = { screenshots: true, snapshots: true, sources: true };
253253
const traceOptions = typeof trace === 'string' ? defaultTraceOptions : { ...defaultTraceOptions, ...trace, mode: undefined };
@@ -620,6 +620,12 @@ export function shouldCaptureTrace(traceMode: TraceMode, testInfo: TestInfo) {
620620
return traceMode === 'on' || traceMode === 'retain-on-failure' || (traceMode === 'on-first-retry' && testInfo.retry === 1);
621621
}
622622

623+
function normalizeScreenshotMode(screenshot: PlaywrightWorkerOptions['screenshot'] | undefined): ScreenshotMode {
624+
if (!screenshot)
625+
return 'off';
626+
return typeof screenshot === 'string' ? screenshot : screenshot.mode;
627+
}
628+
623629
const kTracingStarted = Symbol('kTracingStarted');
624630

625631
export const test = _baseTest.extend<TestFixtures, WorkerFixtures>(playwrightFixtures);

tests/playwright-test/playwright.spec.ts

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -600,3 +600,86 @@ test('should pass fixture defaults to tests', async ({ runInlineTest }) => {
600600
expect(result.exitCode).toBe(0);
601601
expect(result.passed).toBe(1);
602602
});
603+
604+
test('should not throw with many fixtures set to undefined', async ({ runInlineTest }, testInfo) => {
605+
const result = await runInlineTest({
606+
'playwright.config.ts': `
607+
module.exports = { use: {
608+
headless: undefined,
609+
channel: undefined,
610+
launchOptions: undefined,
611+
connectOptions: undefined,
612+
screenshot: undefined,
613+
video: undefined,
614+
trace: undefined,
615+
acceptDownloads: undefined,
616+
bypassCSP: undefined,
617+
colorScheme: undefined,
618+
deviceScaleFactor: undefined,
619+
extraHTTPHeaders: undefined,
620+
geolocation: undefined,
621+
hasTouch: undefined,
622+
httpCredentials: undefined,
623+
ignoreHTTPSErrors: undefined,
624+
isMobile: undefined,
625+
javaScriptEnabled: undefined,
626+
locale: undefined,
627+
offline: undefined,
628+
permissions: undefined,
629+
proxy: undefined,
630+
storageState: undefined,
631+
timezoneId: undefined,
632+
userAgent: undefined,
633+
viewport: undefined,
634+
actionTimeout: undefined,
635+
testIdAttribute: undefined,
636+
navigationTimeout: undefined,
637+
baseURL: undefined,
638+
serviceWorkers: undefined,
639+
contextOptions: undefined,
640+
} };
641+
`,
642+
'a.spec.ts': `
643+
const { test } = pwt;
644+
test.use({
645+
headless: undefined,
646+
channel: undefined,
647+
launchOptions: undefined,
648+
connectOptions: undefined,
649+
screenshot: undefined,
650+
video: undefined,
651+
trace: undefined,
652+
acceptDownloads: undefined,
653+
bypassCSP: undefined,
654+
colorScheme: undefined,
655+
deviceScaleFactor: undefined,
656+
extraHTTPHeaders: undefined,
657+
geolocation: undefined,
658+
hasTouch: undefined,
659+
httpCredentials: undefined,
660+
ignoreHTTPSErrors: undefined,
661+
isMobile: undefined,
662+
javaScriptEnabled: undefined,
663+
locale: undefined,
664+
offline: undefined,
665+
permissions: undefined,
666+
proxy: undefined,
667+
storageState: undefined,
668+
timezoneId: undefined,
669+
userAgent: undefined,
670+
viewport: undefined,
671+
actionTimeout: undefined,
672+
testIdAttribute: undefined,
673+
navigationTimeout: undefined,
674+
baseURL: undefined,
675+
serviceWorkers: undefined,
676+
contextOptions: undefined,
677+
});
678+
test('passes', async ({ page }) => {
679+
});
680+
`,
681+
}, { workers: 1 });
682+
683+
expect(result.exitCode).toBe(0);
684+
expect(result.passed).toBe(1);
685+
});

0 commit comments

Comments
 (0)