Skip to content

Commit

Permalink
cherry-pick(#24127): fix: do not create empty directories for success…
Browse files Browse the repository at this point in the history
…ful snapshot tests

Fixes #15600
  • Loading branch information
aslushnikov committed Jul 10, 2023
1 parent 52f594e commit b7dcc2b
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
4 changes: 2 additions & 2 deletions packages/playwright-test/src/matchers/toMatchSnapshot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,8 @@ class SnapshotHelper<T extends ImageComparatorOptions> {
const inputPathSegments = Array.isArray(name) ? name : [addSuffixToFilePath(name, '', undefined, true)];
const outputPathSegments = Array.isArray(name) ? name : [addSuffixToFilePath(name, actualModifier, undefined, true)];
this.snapshotPath = snapshotPathResolver(...inputPathSegments);
const inputFile = testInfo.outputPath(...inputPathSegments);
const outputFile = testInfo.outputPath(...outputPathSegments);
const inputFile = testInfo._getOutputPath(...inputPathSegments);
const outputFile = testInfo._getOutputPath(...outputPathSegments);
this.expectedPath = addSuffixToFilePath(inputFile, '-expected');
this.previousPath = addSuffixToFilePath(outputFile, '-previous');
this.actualPath = addSuffixToFilePath(outputFile, '-actual');
Expand Down
5 changes: 5 additions & 0 deletions packages/playwright-test/src/worker/testInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,12 @@ export class TestInfoImpl implements TestInfo {
}

outputPath(...pathSegments: string[]){
const outputPath = this._getOutputPath(...pathSegments);
fs.mkdirSync(this.outputDir, { recursive: true });
return outputPath;
}

_getOutputPath(...pathSegments: string[]){
const joinedPath = path.join(...pathSegments);
const outputPath = getContainedPath(this.outputDir, joinedPath);
if (outputPath)
Expand Down
1 change: 1 addition & 0 deletions tests/playwright-test/to-have-screenshot.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,7 @@ test('should support clip option for page', async ({ runInlineTest }, testInfo)
});
`
});
expect(fs.existsSync(testInfo.outputPath('test-results', 'a-is-a-test'))).toBe(false);
expect(result.exitCode).toBe(0);
});

Expand Down

0 comments on commit b7dcc2b

Please sign in to comment.