mirror of
https://github.com/microsoft/playwright.git
synced 2025-06-26 21:40:17 +00:00
fix(screenshot): account for screenshot === undefined
(#19627)
This commit is contained in:
parent
7508c574e1
commit
d12bc0be9a
@ -20,7 +20,7 @@ import type { APIRequestContext, BrowserContext, BrowserContextOptions, LaunchOp
|
|||||||
import * as playwrightLibrary from 'playwright-core';
|
import * as playwrightLibrary from 'playwright-core';
|
||||||
import { createGuid, debugMode } from 'playwright-core/lib/utils';
|
import { createGuid, debugMode } from 'playwright-core/lib/utils';
|
||||||
import { removeFolders } from 'playwright-core/lib/utils/fileUtils';
|
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 { store as _baseStore } from './store';
|
||||||
import type { TestInfoImpl } from './testInfo';
|
import type { TestInfoImpl } from './testInfo';
|
||||||
import { rootTestType, _setProjectSetup } from './testType';
|
import { rootTestType, _setProjectSetup } from './testType';
|
||||||
@ -246,8 +246,8 @@ const playwrightFixtures: Fixtures<TestFixtures, WorkerFixtures> = ({
|
|||||||
if (debugMode())
|
if (debugMode())
|
||||||
testInfo.setTimeout(0);
|
testInfo.setTimeout(0);
|
||||||
|
|
||||||
const screenshotOptions = typeof screenshot !== 'string' ? { fullPage: screenshot.fullPage, omitBackground: screenshot.omitBackground } : undefined;
|
const screenshotMode = normalizeScreenshotMode(screenshot);
|
||||||
const screenshotMode = typeof screenshot === 'string' ? screenshot : screenshot.mode;
|
const screenshotOptions = typeof screenshot === 'string' ? undefined : screenshot;
|
||||||
const traceMode = normalizeTraceMode(trace);
|
const traceMode = normalizeTraceMode(trace);
|
||||||
const defaultTraceOptions = { screenshots: true, snapshots: true, sources: true };
|
const defaultTraceOptions = { screenshots: true, snapshots: true, sources: true };
|
||||||
const traceOptions = typeof trace === 'string' ? defaultTraceOptions : { ...defaultTraceOptions, ...trace, mode: undefined };
|
const traceOptions = typeof trace === 'string' ? defaultTraceOptions : { ...defaultTraceOptions, ...trace, mode: undefined };
|
||||||
@ -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);
|
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');
|
const kTracingStarted = Symbol('kTracingStarted');
|
||||||
|
|
||||||
export const test = _baseTest.extend<TestFixtures, WorkerFixtures>(playwrightFixtures);
|
export const test = _baseTest.extend<TestFixtures, WorkerFixtures>(playwrightFixtures);
|
||||||
|
@ -600,3 +600,86 @@ test('should pass fixture defaults to tests', async ({ runInlineTest }) => {
|
|||||||
expect(result.exitCode).toBe(0);
|
expect(result.exitCode).toBe(0);
|
||||||
expect(result.passed).toBe(1);
|
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);
|
||||||
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user