diff --git a/packages/playwright/src/program.ts b/packages/playwright/src/program.ts index ea0a48fe6a..93969662bb 100644 --- a/packages/playwright/src/program.ts +++ b/packages/playwright/src/program.ts @@ -282,7 +282,7 @@ async function mergeReports(reportDir: string | undefined, opts: { [key: string] function overridesFromOptions(options: { [key: string]: any }): ConfigCLIOverrides { const shardPair = options.shard ? options.shard.split('/').map((t: string) => parseInt(t, 10)) : undefined; - let updateSnapshots: 'all' | 'changed' | 'missing' | 'none'; + let updateSnapshots: 'all' | 'changed' | 'missing' | 'none' | undefined; if (['all', 'changed', 'missing', 'none'].includes(options.updateSnapshots)) updateSnapshots = options.updateSnapshots; else @@ -303,7 +303,7 @@ function overridesFromOptions(options: { [key: string]: any }): ConfigCLIOverrid tsconfig: options.tsconfig ? path.resolve(process.cwd(), options.tsconfig) : undefined, ignoreSnapshots: options.ignoreSnapshots ? !!options.ignoreSnapshots : undefined, updateSnapshots, - updateSourceMethod: options.updateSourceMethod || 'patch', + updateSourceMethod: options.updateSourceMethod, workers: options.workers, }; diff --git a/tests/playwright-test/update-aria-snapshot.spec.ts b/tests/playwright-test/update-aria-snapshot.spec.ts index 0052d3d3d9..fce8e48551 100644 --- a/tests/playwright-test/update-aria-snapshot.spec.ts +++ b/tests/playwright-test/update-aria-snapshot.spec.ts @@ -661,4 +661,45 @@ test.describe('update-source-method', () => { a.spec.ts `); }); + + test('should overwrite source when specified in the config', async ({ runInlineTest }, testInfo) => { + const result = await runInlineTest({ + '.git/marker': '', + 'playwright.config.ts': ` + export default { updateSourceMethod: 'overwrite' }; + `, + 'a.spec.ts': ` + import { test, expect } from '@playwright/test'; + test('test', async ({ page }) => { + await page.setContent(\`

hello

\`); + await expect(page.locator('body')).toMatchAriaSnapshot(\` + - heading "world" + \`); + }); + ` + }, { 'update-snapshots': 'all' }); + + expect(result.exitCode).toBe(0); + const patchPath = testInfo.outputPath('test-results/rebaselines.patch'); + expect(fs.existsSync(patchPath)).toBeFalsy(); + + const data = fs.readFileSync(testInfo.outputPath('a.spec.ts'), 'utf-8'); + expect(data).toBe(` + import { test, expect } from '@playwright/test'; + test('test', async ({ page }) => { + await page.setContent(\`

hello

\`); + await expect(page.locator('body')).toMatchAriaSnapshot(\` + - heading "hello" [level=1] + \`); + }); + `); + + expect(stripAnsi(result.output).replace(/\\/g, '/')).toContain(`New baselines created for: + + a.spec.ts +`); + + const result2 = await runInlineTest({}); + expect(result2.exitCode).toBe(0); + }); });