Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.
TypeScript automationchromechromiume2e-testingelectronend-to-end-testingfirefoxjavascriptplaywrighttesttest-automationtestingtesting-toolswebwebkit
fix: do not create empty directories for successful snapshot tests (#24127)
Andrey Lushnikov94d6b1210b8c
diff --git a/packages/playwright-test/src/matchers/toMatchSnapshot.ts b/packages/playwright-test/src/matchers/toMatchSnapshot.tsindex 87ad7d3e93..6c25e04c8e 100644--- a/packages/playwright-test/src/matchers/toMatchSnapshot.ts+++ b/packages/playwright-test/src/matchers/toMatchSnapshot.ts@@ -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');diff --git a/packages/playwright-test/src/worker/testInfo.ts b/packages/playwright-test/src/worker/testInfo.tsindex c4b04bd5b9..0d497fe294 100644--- a/packages/playwright-test/src/worker/testInfo.ts+++ b/packages/playwright-test/src/worker/testInfo.ts@@ -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)diff --git a/tests/playwright-test/to-have-screenshot.spec.ts b/tests/playwright-test/to-have-screenshot.spec.tsindex cdd48b84ad..a0c05f5a9a 100644--- a/tests/playwright-test/to-have-screenshot.spec.ts+++ b/tests/playwright-test/to-have-screenshot.spec.ts@@ -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);});