Skip to content

Commit 74b082e

Browse files
committed
handle step timeout
# Conflicts: # packages/tools/src/snap-test.ts
1 parent 8facf1b commit 74b082e

File tree

2 files changed

+25
-18
lines changed

2 files changed

+25
-18
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,16 +173,16 @@ jobs:
173173
run: pnpx playwright install chromium
174174

175175
- name: Run CLI E2E tests
176+
if: ${{ matrix.os != 'windows-latest' }}
176177
run: |
177178
RUST_BACKTRACE=1 pnpm test
178179
git diff --exit-code
179-
if: ${{ matrix.os != 'windows-latest' }}
180180
181181
- name: Run CLI E2E tests
182+
if: ${{ matrix.os == 'windows-latest' }}
182183
run: |
183184
RUST_BACKTRACE=1 pnpm -r snap-test
184185
git diff --exit-code
185-
if: ${{ matrix.os != 'windows-latest' }}
186186
187187
install-e2e-test:
188188
name: vite install E2E test

packages/tools/src/snap-test.ts

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { cpus, tmpdir } from 'node:os';
88
import path from 'node:path';
99
import { debuglog, parseArgs } from 'node:util';
1010

11+
import { setTimeout } from 'node:timers/promises';
1112
import { isPassThroughEnv, replaceUnstableOutput } from './utils';
1213

1314
const debug = debuglog('vite-plus/snap-test');
@@ -159,34 +160,40 @@ async function runTestCase(name: string, tempTmpDir: string, casesDir: string) {
159160
const outputStreamPath = path.join(caseTmpDir, 'output.log');
160161
const outputStream = await open(outputStreamPath, 'w');
161162

162-
const exitCode = await execute(stripComments(command), [], {
163-
env,
164-
cwd,
165-
stdin: null,
166-
// Declared to be `Writable` but `FileHandle` works too.
167-
// @ts-expect-error
168-
stderr: outputStream,
169-
// @ts-expect-error
170-
stdout: outputStream,
171-
glob: {
172-
// Disable glob expansion. Pass args like '--filter=*' as-is.
173-
isGlobPattern: () => false,
174-
match: async () => [],
175-
},
176-
});
163+
const exitCode = await Promise.race([
164+
execute(stripComments(command), [], {
165+
env,
166+
cwd,
167+
stdin: null,
168+
// Declared to be `Writable` but `FileHandle` works too.
169+
// @ts-expect-error
170+
stderr: outputStream,
171+
// @ts-expect-error
172+
stdout: outputStream,
173+
glob: {
174+
// Disable glob expansion. Pass args like '--filter=*' as-is.
175+
isGlobPattern: () => false,
176+
match: async () => [],
177+
},
178+
}),
179+
setTimeout(30 * 1000),
180+
]);
177181

178182
await outputStream.close();
179183

180184
const output = readFileSync(outputStreamPath, 'utf-8');
181185

182186
let commandLine = `> ${command}`;
183187
if (exitCode !== 0) {
184-
commandLine = `[${exitCode}]` + commandLine;
188+
commandLine = (exitCode === undefined ? '[timeout]' : `[${exitCode}]`) + commandLine;
185189
}
186190
newSnap.push(commandLine);
187191
if (output.length > 0) {
188192
newSnap.push(replaceUnstableOutput(output, caseTmpDir));
189193
}
194+
if (exitCode === undefined) {
195+
break; // Stop executing further commands on timeout
196+
}
190197
}
191198
const newSnapContent = newSnap.join('\n');
192199

0 commit comments

Comments
 (0)