Skip to content

Commit 9417622

Browse files
fix: ensure playwright single instance for vue2-in-vue3
1 parent 62d9dcc commit 9417622

File tree

3 files changed

+50
-3
lines changed

3 files changed

+50
-3
lines changed

vue2-in-vue3/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
"build": "pnpm --filter vue2-in-vue3_vue* build",
99
"serve": "pnpm --filter vue2-in-vue3_vue* --parallel serve",
1010
"clean": "pnpm --filter vue2-in-vue3_vue* --parallel clean",
11-
"test:e2e": "pnpm exec playwright test",
12-
"test:e2e:ui": "pnpm exec playwright test --ui",
13-
"e2e:ci": "pnpm exec playwright test --reporter=line"
11+
"test:e2e": "node scripts/run-playwright.cjs test",
12+
"test:e2e:ui": "node scripts/run-playwright.cjs test --ui",
13+
"e2e:ci": "node scripts/run-playwright.cjs test --reporter=line"
1414
},
1515
"devDependencies": {
1616
"@playwright/test": "^1.54.2",
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
const path = require('node:path');
2+
const { createRequire } = require('node:module');
3+
4+
const requireFromHere = createRequire(__filename);
5+
const repoRoot = path.resolve(__dirname, '..', '..');
6+
7+
function aliasModule(request) {
8+
let localPath;
9+
try {
10+
localPath = requireFromHere.resolve(request);
11+
} catch {
12+
return;
13+
}
14+
15+
// Ensure the module is loaded so the cache entry exists.
16+
requireFromHere(request);
17+
18+
try {
19+
const rootPath = requireFromHere.resolve(request, { paths: [repoRoot] });
20+
if (rootPath !== localPath && require.cache[localPath]) {
21+
require.cache[rootPath] = require.cache[localPath];
22+
}
23+
} catch {
24+
// The root dependency might not exist when running this example in
25+
// isolation. That's fine; in that case nothing extra is needed.
26+
}
27+
}
28+
29+
aliasModule('@playwright/test');
30+
aliasModule('playwright');
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/usr/bin/env node
2+
const { spawn } = require('node:child_process');
3+
const path = require('node:path');
4+
5+
const cli = require.resolve('@playwright/test/cli');
6+
const aliasHook = path.resolve(__dirname, 'register-playwright-alias.cjs');
7+
const args = process.argv.slice(2);
8+
9+
const child = spawn(process.execPath, ['--require', aliasHook, cli, ...args], {
10+
stdio: 'inherit',
11+
});
12+
13+
child.on('exit', code => {
14+
if (code !== null) {
15+
process.exit(code);
16+
}
17+
});

0 commit comments

Comments
 (0)