Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: do not create empty directories for successful snapshot tests #24127

Merged
merged 1 commit into from
Jul 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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