Skip to content

Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.

fix(ui mode): allow --updateSnapshots (#31584)

Dmitry Gozman48db1b1663ed
diff --git a/packages/playwright-core/src/server/trace/viewer/traceViewer.ts b/packages/playwright-core/src/server/trace/viewer/traceViewer.ts
index 3c2872e6fa..d053a3e643 100644
--- a/packages/playwright-core/src/server/trace/viewer/traceViewer.ts
+++ b/packages/playwright-core/src/server/trace/viewer/traceViewer.ts
@@ -47,6 +47,7 @@ export type TraceViewerRedirectOptions = {
webApp?: string;
isServer?: boolean;
outputDir?: string;
+ updateSnapshots?: 'all' | 'none' | 'missing';
};
export type TraceViewerAppOptions = {
@@ -132,6 +133,8 @@ export async function installRootRedirect(server: HttpServer, traceUrls: string[
params.append('headed', '');
if (options.outputDir)
params.append('outputDir', options.outputDir);
+ if (options.updateSnapshots)
+ params.append('updateSnapshots', options.updateSnapshots);
for (const reporter of options.reporter || [])
params.append('reporter', reporter);
diff --git a/packages/playwright/src/isomorphic/testServerInterface.ts b/packages/playwright/src/isomorphic/testServerInterface.ts
index c63a9793d3..ac06f65c24 100644
--- a/packages/playwright/src/isomorphic/testServerInterface.ts
+++ b/packages/playwright/src/isomorphic/testServerInterface.ts
@@ -93,6 +93,7 @@ export interface TestServerInterface {
workers?: number | string;
timeout?: number,
outputDir?: string;
+ updateSnapshots?: 'all' | 'none' | 'missing';
reporters?: string[],
trace?: 'on' | 'off';
video?: 'on' | 'off';
diff --git a/packages/playwright/src/program.ts b/packages/playwright/src/program.ts
index f462b81d43..6e49a02b05 100644
--- a/packages/playwright/src/program.ts
+++ b/packages/playwright/src/program.ts
@@ -171,6 +171,7 @@ async function runTests(args: string[], opts: { [key: string]: any }) {
workers: cliOverrides.workers,
timeout: cliOverrides.timeout,
outputDir: cliOverrides.outputDir,
+ updateSnapshots: cliOverrides.updateSnapshots,
});
await stopProfiling('runner');
if (status === 'restarted')
diff --git a/packages/playwright/src/runner/testServer.ts b/packages/playwright/src/runner/testServer.ts
index e797ed9b08..c5133df3eb 100644
--- a/packages/playwright/src/runner/testServer.ts
+++ b/packages/playwright/src/runner/testServer.ts
@@ -314,6 +314,7 @@ class TestServerDispatcher implements TestServerInterface {
_optionConnectOptions: params.connectWsEndpoint ? { wsEndpoint: params.connectWsEndpoint } : undefined,
},
outputDir: params.outputDir,
+ updateSnapshots: params.updateSnapshots,
workers: params.workers,
};
if (params.trace === 'on')
diff --git a/packages/trace-viewer/src/ui/uiModeView.tsx b/packages/trace-viewer/src/ui/uiModeView.tsx
index 914280cb34..c626c862c9 100644
--- a/packages/trace-viewer/src/ui/uiModeView.tsx
+++ b/packages/trace-viewer/src/ui/uiModeView.tsx
@@ -61,8 +61,11 @@ const queryParams = {
timeout: searchParams.has('timeout') ? +searchParams.get('timeout')! : undefined,
headed: searchParams.has('headed'),
outputDir: searchParams.get('outputDir') || undefined,
+ updateSnapshots: (searchParams.get('updateSnapshots') as 'all' | 'none' | 'missing' | undefined) || undefined,
reporters: searchParams.has('reporter') ? searchParams.getAll('reporter') : undefined,
};
+if (queryParams.updateSnapshots && !['all', 'none', 'missing'].includes(queryParams.updateSnapshots))
+ queryParams.updateSnapshots = undefined;
const isMac = navigator.platform === 'MacIntel';
@@ -285,6 +288,7 @@ export const UIModeView: React.FC<{}> = ({
timeout: queryParams.timeout,
headed: queryParams.headed,
outputDir: queryParams.outputDir,
+ updateSnapshots: queryParams.updateSnapshots,
reporters: queryParams.reporters,
trace: 'on',
});