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

Fixes https://github.com/microsoft/playwright/issues/15600
This commit is contained in:
Andrey Lushnikov 2023-07-10 09:45:24 -07:00 committed by GitHub
parent 19474bef78
commit 94d6b1210b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 8 additions and 2 deletions

View File

@ -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');

View File

@ -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)

View File

@ -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);
});