Skip to content

Commit b7dcc2b

Browse files
committed
cherry-pick(#24127): fix: do not create empty directories for successful snapshot tests
Fixes microsoft/playwright#15600
1 parent 52f594e commit b7dcc2b

File tree

3 files changed

+8
-2
lines changed

3 files changed

+8
-2
lines changed

packages/playwright-test/src/matchers/toMatchSnapshot.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,8 @@ class SnapshotHelper<T extends ImageComparatorOptions> {
124124
const inputPathSegments = Array.isArray(name) ? name : [addSuffixToFilePath(name, '', undefined, true)];
125125
const outputPathSegments = Array.isArray(name) ? name : [addSuffixToFilePath(name, actualModifier, undefined, true)];
126126
this.snapshotPath = snapshotPathResolver(...inputPathSegments);
127-
const inputFile = testInfo.outputPath(...inputPathSegments);
128-
const outputFile = testInfo.outputPath(...outputPathSegments);
127+
const inputFile = testInfo._getOutputPath(...inputPathSegments);
128+
const outputFile = testInfo._getOutputPath(...outputPathSegments);
129129
this.expectedPath = addSuffixToFilePath(inputFile, '-expected');
130130
this.previousPath = addSuffixToFilePath(outputFile, '-previous');
131131
this.actualPath = addSuffixToFilePath(outputFile, '-actual');

packages/playwright-test/src/worker/testInfo.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,12 @@ export class TestInfoImpl implements TestInfo {
382382
}
383383

384384
outputPath(...pathSegments: string[]){
385+
const outputPath = this._getOutputPath(...pathSegments);
385386
fs.mkdirSync(this.outputDir, { recursive: true });
387+
return outputPath;
388+
}
389+
390+
_getOutputPath(...pathSegments: string[]){
386391
const joinedPath = path.join(...pathSegments);
387392
const outputPath = getContainedPath(this.outputDir, joinedPath);
388393
if (outputPath)

tests/playwright-test/to-have-screenshot.spec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,7 @@ test('should support clip option for page', async ({ runInlineTest }, testInfo)
283283
});
284284
`
285285
});
286+
expect(fs.existsSync(testInfo.outputPath('test-results', 'a-is-a-test'))).toBe(false);
286287
expect(result.exitCode).toBe(0);
287288
});
288289

0 commit comments

Comments
 (0)