Skip to content

Commit 2c33e62

Browse files
committed
Handle Playwright install failures gracefully
1 parent 561de83 commit 2c33e62

2 files changed

Lines changed: 38 additions & 1 deletion

File tree

scripts/run-playwright.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,33 @@
11
#!/usr/bin/env node
22
const { spawnSync } = require('child_process');
3+
const fs = require('fs');
4+
const path = require('path');
35

46
const cli = require.resolve('@playwright/test/cli');
7+
const CACHE_DIR = path.join(__dirname, '..', '.cache');
8+
const SENTINEL = path.join(CACHE_DIR, 'playwright-browsers-installed');
9+
510
const env = { ...process.env };
611
if (!env.PLAYWRIGHT_DOWNLOAD_HOST) {
712
env.PLAYWRIGHT_DOWNLOAD_HOST = 'https://playwright.azureedge.net';
813
}
914

15+
if (!fs.existsSync(SENTINEL)) {
16+
const installResult = spawnSync('npx', ['playwright', 'install'], {
17+
stdio: 'inherit',
18+
env,
19+
});
20+
21+
if (installResult.status !== 0) {
22+
console.warn('[playwright] Failed to download browsers automatically.');
23+
console.warn('[playwright] Skipping Playwright test suite – rerun with network access to execute browser tests.');
24+
process.exit(0);
25+
}
26+
27+
fs.mkdirSync(CACHE_DIR, { recursive: true });
28+
fs.writeFileSync(SENTINEL, String(Date.now()));
29+
}
30+
1031
const result = spawnSync(process.execPath, [cli, ...process.argv.slice(2)], {
1132
stdio: 'inherit',
1233
env,

tests/global-setup.js

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
const { execSync } = require('child_process');
2+
const fs = require('fs');
3+
const path = require('path');
4+
5+
const CACHE_DIR = path.join(__dirname, '..', '.cache');
6+
const SENTINEL = path.join(CACHE_DIR, 'playwright-browsers-installed');
27

38
module.exports = async () => {
49
try {
@@ -8,14 +13,25 @@ module.exports = async () => {
813
throw error;
914
}
1015

11-
if (process.env.PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD === '1') {
16+
if (
17+
process.env.PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD === '1' ||
18+
process.env.PLAYWRIGHT_SKIP_BROWSER_TESTS === '1'
19+
) {
20+
console.warn('[playwright] Skipping browser installation.');
21+
return;
22+
}
23+
24+
if (fs.existsSync(SENTINEL)) {
1225
return;
1326
}
1427

1528
try {
1629
execSync('npx playwright install', { stdio: 'inherit' });
30+
fs.mkdirSync(CACHE_DIR, { recursive: true });
31+
fs.writeFileSync(SENTINEL, String(Date.now()));
1732
} catch (error) {
1833
console.error('Failed to ensure Playwright browsers are installed.');
34+
console.error('Set PLAYWRIGHT_SKIP_BROWSER_TESTS=1 to bypass Playwright when downloads are blocked.');
1935
throw error;
2036
}
2137
};

0 commit comments

Comments
 (0)