Skip to content

Commit 5d6ac96

Browse files
authored
cherry-pick(#34442): fix(test runner): respect updateSourceMethod from the config (#34445)
1 parent 97b76b4 commit 5d6ac96

File tree

2 files changed

+43
-2
lines changed

2 files changed

+43
-2
lines changed

packages/playwright/src/program.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ async function mergeReports(reportDir: string | undefined, opts: { [key: string]
282282
function overridesFromOptions(options: { [key: string]: any }): ConfigCLIOverrides {
283283
const shardPair = options.shard ? options.shard.split('/').map((t: string) => parseInt(t, 10)) : undefined;
284284

285-
let updateSnapshots: 'all' | 'changed' | 'missing' | 'none';
285+
let updateSnapshots: 'all' | 'changed' | 'missing' | 'none' | undefined;
286286
if (['all', 'changed', 'missing', 'none'].includes(options.updateSnapshots))
287287
updateSnapshots = options.updateSnapshots;
288288
else
@@ -303,7 +303,7 @@ function overridesFromOptions(options: { [key: string]: any }): ConfigCLIOverrid
303303
tsconfig: options.tsconfig ? path.resolve(process.cwd(), options.tsconfig) : undefined,
304304
ignoreSnapshots: options.ignoreSnapshots ? !!options.ignoreSnapshots : undefined,
305305
updateSnapshots,
306-
updateSourceMethod: options.updateSourceMethod || 'patch',
306+
updateSourceMethod: options.updateSourceMethod,
307307
workers: options.workers,
308308
};
309309

tests/playwright-test/update-aria-snapshot.spec.ts

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -661,4 +661,45 @@ test.describe('update-source-method', () => {
661661
a.spec.ts
662662
`);
663663
});
664+
665+
test('should overwrite source when specified in the config', async ({ runInlineTest }, testInfo) => {
666+
const result = await runInlineTest({
667+
'.git/marker': '',
668+
'playwright.config.ts': `
669+
export default { updateSourceMethod: 'overwrite' };
670+
`,
671+
'a.spec.ts': `
672+
import { test, expect } from '@playwright/test';
673+
test('test', async ({ page }) => {
674+
await page.setContent(\`<h1>hello</h1>\`);
675+
await expect(page.locator('body')).toMatchAriaSnapshot(\`
676+
- heading "world"
677+
\`);
678+
});
679+
`
680+
}, { 'update-snapshots': 'all' });
681+
682+
expect(result.exitCode).toBe(0);
683+
const patchPath = testInfo.outputPath('test-results/rebaselines.patch');
684+
expect(fs.existsSync(patchPath)).toBeFalsy();
685+
686+
const data = fs.readFileSync(testInfo.outputPath('a.spec.ts'), 'utf-8');
687+
expect(data).toBe(`
688+
import { test, expect } from '@playwright/test';
689+
test('test', async ({ page }) => {
690+
await page.setContent(\`<h1>hello</h1>\`);
691+
await expect(page.locator('body')).toMatchAriaSnapshot(\`
692+
- heading "hello" [level=1]
693+
\`);
694+
});
695+
`);
696+
697+
expect(stripAnsi(result.output).replace(/\\/g, '/')).toContain(`New baselines created for:
698+
699+
a.spec.ts
700+
`);
701+
702+
const result2 = await runInlineTest({});
703+
expect(result2.exitCode).toBe(0);
704+
});
664705
});

0 commit comments

Comments
 (0)