Skip to content

Commit

Permalink
cherry-pick(#19627): fix(screenshot): account for `screenshot === und…
Browse files Browse the repository at this point in the history
…efined` (#19631)
  • Loading branch information
dgozman authored Dec 21, 2022
1 parent db88d4b commit f2916d4
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 3 deletions.
12 changes: 9 additions & 3 deletions packages/playwright-test/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import type { APIRequestContext, BrowserContext, BrowserContextOptions, LaunchOp
import * as playwrightLibrary from 'playwright-core';
import { createGuid, debugMode } from 'playwright-core/lib/utils';
import { removeFolders } from 'playwright-core/lib/utils/fileUtils';
import type { Fixtures, PlaywrightTestArgs, PlaywrightTestOptions, PlaywrightWorkerArgs, PlaywrightWorkerOptions, TestInfo, TestType, TraceMode, VideoMode } from '../types/test';
import type { Fixtures, PlaywrightTestArgs, PlaywrightTestOptions, PlaywrightWorkerArgs, PlaywrightWorkerOptions, ScreenshotMode, TestInfo, TestType, TraceMode, VideoMode } from '../types/test';
import { store as _baseStore } from './store';
import type { TestInfoImpl } from './testInfo';
import { rootTestType, _setProjectSetup } from './testType';
Expand Down Expand Up @@ -246,8 +246,8 @@ const playwrightFixtures: Fixtures<TestFixtures, WorkerFixtures> = ({
if (debugMode())
testInfo.setTimeout(0);

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

function normalizeScreenshotMode(screenshot: PlaywrightWorkerOptions['screenshot'] | undefined): ScreenshotMode {
if (!screenshot)
return 'off';
return typeof screenshot === 'string' ? screenshot : screenshot.mode;
}

const kTracingStarted = Symbol('kTracingStarted');

export const test = _baseTest.extend<TestFixtures, WorkerFixtures>(playwrightFixtures);
Expand Down
83 changes: 83 additions & 0 deletions tests/playwright-test/playwright.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -600,3 +600,86 @@ test('should pass fixture defaults to tests', async ({ runInlineTest }) => {
expect(result.exitCode).toBe(0);
expect(result.passed).toBe(1);
});

test('should not throw with many fixtures set to undefined', async ({ runInlineTest }, testInfo) => {
const result = await runInlineTest({
'playwright.config.ts': `
module.exports = { use: {
headless: undefined,
channel: undefined,
launchOptions: undefined,
connectOptions: undefined,
screenshot: undefined,
video: undefined,
trace: undefined,
acceptDownloads: undefined,
bypassCSP: undefined,
colorScheme: undefined,
deviceScaleFactor: undefined,
extraHTTPHeaders: undefined,
geolocation: undefined,
hasTouch: undefined,
httpCredentials: undefined,
ignoreHTTPSErrors: undefined,
isMobile: undefined,
javaScriptEnabled: undefined,
locale: undefined,
offline: undefined,
permissions: undefined,
proxy: undefined,
storageState: undefined,
timezoneId: undefined,
userAgent: undefined,
viewport: undefined,
actionTimeout: undefined,
testIdAttribute: undefined,
navigationTimeout: undefined,
baseURL: undefined,
serviceWorkers: undefined,
contextOptions: undefined,
} };
`,
'a.spec.ts': `
const { test } = pwt;
test.use({
headless: undefined,
channel: undefined,
launchOptions: undefined,
connectOptions: undefined,
screenshot: undefined,
video: undefined,
trace: undefined,
acceptDownloads: undefined,
bypassCSP: undefined,
colorScheme: undefined,
deviceScaleFactor: undefined,
extraHTTPHeaders: undefined,
geolocation: undefined,
hasTouch: undefined,
httpCredentials: undefined,
ignoreHTTPSErrors: undefined,
isMobile: undefined,
javaScriptEnabled: undefined,
locale: undefined,
offline: undefined,
permissions: undefined,
proxy: undefined,
storageState: undefined,
timezoneId: undefined,
userAgent: undefined,
viewport: undefined,
actionTimeout: undefined,
testIdAttribute: undefined,
navigationTimeout: undefined,
baseURL: undefined,
serviceWorkers: undefined,
contextOptions: undefined,
});
test('passes', async ({ page }) => {
});
`,
}, { workers: 1 });

expect(result.exitCode).toBe(0);
expect(result.passed).toBe(1);
});

0 comments on commit f2916d4

Please sign in to comment.