Skip to content

Commit 7aef4aa

Browse files
committed
ci: retry flaky tests on Windows Node.js 24
Assisted-by: openai:gpt-5.5 Signed-off-by: Kamat, Trivikram <16024985+trivikr@users.noreply.github.com>
1 parent df5ded9 commit 7aef4aa

3 files changed

Lines changed: 57 additions & 2 deletions

File tree

scripts/platform-shell.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,13 @@ const { writeFileSync } = require('node:fs')
55
const { resolve } = require('node:path')
66

77
if (platform() === 'win32') {
8+
const shouldRetryTests = process.env.GITHUB_ACTIONS === 'true' && process.versions.node.split('.')[0] === '24'
9+
const scriptShell = shouldRetryTests
10+
? resolve(__dirname, 'retry-test-shell.cmd')
11+
: 'C:\\windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe'
12+
813
writeFileSync(
9-
resolve(__dirname, '.npmrc'),
10-
'script-shell = "C:\\windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe"\n'
14+
resolve(__dirname, shouldRetryTests ? '..' : '.', '.npmrc'),
15+
`script-shell = ${scriptShell}\n`
1116
)
1217
}

scripts/retry-test-shell.cmd

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
@echo off
2+
powershell.exe -NoLogo -NoProfile -ExecutionPolicy Bypass -File "%~dp0retry-test-shell.ps1" %*

scripts/retry-test-shell.ps1

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
$testScripts = @(
2+
'test:cache',
3+
'test:cache-interceptor',
4+
'test:cache-tests',
5+
'test:cookies',
6+
'test:eventsource',
7+
'test:fetch',
8+
'test:infra',
9+
'test:interceptors',
10+
'test:jest',
11+
'test:node-fetch',
12+
'test:node-test',
13+
'test:subresource-integrity',
14+
'test:unit',
15+
'test:websocket',
16+
'test:wpt'
17+
)
18+
19+
$commandIndex = -1
20+
for ($i = 0; $i -lt $args.Length; $i++) {
21+
if ($args[$i] -ieq '/c' -or $args[$i] -ieq '-c') {
22+
$commandIndex = $i
23+
break
24+
}
25+
}
26+
27+
if ($args.Length -eq 0 -or $commandIndex -eq $args.Length - 1) {
28+
exit 1
29+
}
30+
31+
if ($commandIndex -eq -1) {
32+
$command = $args -join ' '
33+
} else {
34+
$command = $args[($commandIndex + 1)..($args.Length - 1)] -join ' '
35+
}
36+
$shouldRetry = $testScripts -contains $env:npm_lifecycle_event
37+
38+
cmd.exe /d /s /c $command
39+
$exitCode = $LASTEXITCODE
40+
41+
if ($exitCode -eq 0 -or -not $shouldRetry) {
42+
exit $exitCode
43+
}
44+
45+
Write-Host "Command failed with exit code $exitCode. Retrying once on Windows with Node.js 24."
46+
47+
cmd.exe /d /s /c $command
48+
exit $LASTEXITCODE

0 commit comments

Comments
 (0)