From 755cf60496fa90e236f0b516550a6c195d45a406 Mon Sep 17 00:00:00 2001 From: Andrey Lushnikov Date: Sun, 8 Aug 2021 02:52:11 +0300 Subject: [PATCH] feat(test): write missing snapshots to `test-results` (#7879) By default, CI's are set up to upload `//test-results` folder to artifacts storage. Storing missing snapshots in the `//test-results` folder too will simplify collecting new baselines from the CI. --- src/test/matchers/golden.ts | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/test/matchers/golden.ts b/src/test/matchers/golden.ts index 33739d8531..83e1274a18 100644 --- a/src/test/matchers/golden.ts +++ b/src/test/matchers/golden.ts @@ -90,6 +90,10 @@ export function compare( options?: { threshold?: number } ): { pass: boolean; message?: string; expectedPath?: string, actualPath?: string, diffPath?: string, mimeType?: string } { const snapshotFile = snapshotPath(name); + const outputFile = outputPath(name); + const expectedPath = addSuffix(outputFile, '-expected'); + const actualPath = addSuffix(outputFile, '-actual'); + const diffPath = addSuffix(outputFile, '-diff'); if (!fs.existsSync(snapshotFile)) { const isWriteMissingMode = updateSnapshots === 'all' || updateSnapshots === 'missing'; @@ -101,6 +105,7 @@ export function compare( if (isWriteMissingMode) { fs.mkdirSync(path.dirname(snapshotFile), { recursive: true }); fs.writeFileSync(snapshotFile, actual); + fs.writeFileSync(actualPath, actual); } const message = `${commonMissingSnapshotMessage}${isWriteMissingMode ? ', writing actual.' : '.'}`; if (updateSnapshots === 'all') { @@ -154,10 +159,6 @@ export function compare( }; } - const outputFile = outputPath(name); - const expectedPath = addSuffix(outputFile, '-expected'); - const actualPath = addSuffix(outputFile, '-actual'); - const diffPath = addSuffix(outputFile, '-diff'); fs.writeFileSync(expectedPath, expected); fs.writeFileSync(actualPath, actual); if (result.diff)