dx: use per-branch folder for e2e snapshots
Massimo Melina committed
Feb 21, 2026 at 17:09 UTC
bfd59fb77bf4cdcf28ee9fd7f1f1116682969366
2 files changed
+20
-1
.gitignore
+1
-1
@@ -14,4 +14,4 @@ tests/config.yaml.bak
14
/playwright-report/
15
/blob-report/
16
/playwright/.cache/
17
-e2e/frontend.spec.ts-snapshots
\ No newline at end of file
17
+e2e/frontend.spec.ts-snapshots*
\ No newline at end of file
playwright.config.ts
+19
@@ -1,4 +1,7 @@
1
import { defineConfig, devices } from '@playwright/test';
2
+import { execSync } from 'node:child_process';
3
+
4
+const snapshotBranch = getSnapshotBranch()
5
6
/**
7
* Read environment variables from file.
@@ -13,6 +16,7 @@ import { defineConfig, devices } from '@playwright/test';
16
*/
17
export default defineConfig({
18
testDir: './e2e',
19
+ snapshotPathTemplate: `{testDir}/{testFilePath}-snapshots-${snapshotBranch}/{arg}-{projectName}-{platform}{ext}`,
20
timeout: 30_000,
21
fullyParallel: true, // Run tests in files in parallel
22
forbidOnly: !!process.env.CI, // Fail the build on CI if you accidentally left test.only in the source code.
@@ -103,3 +107,18 @@ export default defineConfig({
107
reuseExistingServer: !process.env.CI,
108
}]
109
});
110
+
111
+function getSnapshotBranch() {
112
+ // CI often runs in detached HEAD, so allow callers to force the logical branch name.
113
+ const branchName = process.env.PLAYWRIGHT_SNAPSHOT_BRANCH || getGitBranchName() || 'detached-head'
114
+ return branchName.replace(/[^a-zA-Z0-9._-]/g, '_')
115
+}
116
+
117
+function getGitBranchName() {
118
+ try {
119
+ return execSync('git branch --show-current', { encoding: 'utf8' }).trim()
120
+ }
121
+ catch {
122
+ return ''
123
+ }
124
+}