Skip to content

Commit 7899a38

Browse files
piotrskiclaude
andcommitted
fix(e2e): resolve vite binary from node_modules instead of npx
npx may not find vite in CI. Resolve the binary directly from the example app's or monorepo root's node_modules/.bin instead. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent f442450 commit 7899a38

1 file changed

Lines changed: 24 additions & 4 deletions

File tree

packages/e2e-tests/src/vite-server.ts

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,21 @@ const VITE_APP_DIR = path.resolve(
66
'../../../examples/vite-app',
77
);
88

9+
/**
10+
* Resolve the vite binary from the example app's node_modules.
11+
* Falls back to the monorepo root's node_modules.
12+
*/
13+
function getViteBin(): string {
14+
const localBin = path.join(VITE_APP_DIR, 'node_modules', '.bin', 'vite');
15+
const rootBin = path.resolve(VITE_APP_DIR, '../../node_modules/.bin/vite');
16+
try {
17+
require('fs').accessSync(localBin);
18+
return localBin;
19+
} catch {
20+
return rootBin;
21+
}
22+
}
23+
924
/**
1025
* Start a Vite dev server for the example app with a custom devtools port.
1126
* Uses AGENT_DEVTOOLS_PORT env var read by the example app's vite config.
@@ -14,25 +29,30 @@ export async function startViteServer(
1429
vitePort: number,
1530
daemonPort: number,
1631
): Promise<ChildProcess> {
32+
const viteBin = getViteBin();
1733
const viteProcess = spawn(
18-
'npx',
19-
['vite', '--port', String(vitePort), '--strictPort'],
34+
viteBin,
35+
['--port', String(vitePort), '--strictPort'],
2036
{
2137
cwd: VITE_APP_DIR,
2238
env: { ...process.env, AGENT_DEVTOOLS_PORT: String(daemonPort) },
2339
stdio: 'pipe',
2440
},
2541
);
2642

27-
// Capture stderr for debugging if Vite fails
43+
// Capture output for debugging if Vite fails
44+
let stdoutOutput = '';
2845
let stderrOutput = '';
46+
viteProcess.stdout?.on('data', (chunk: Buffer) => {
47+
stdoutOutput += chunk.toString();
48+
});
2949
viteProcess.stderr?.on('data', (chunk: Buffer) => {
3050
stderrOutput += chunk.toString();
3151
});
3252

3353
await new Promise<void>((resolve, reject) => {
3454
const timeout = setTimeout(() => {
35-
reject(new Error(`Vite failed to start within 30s. stderr:\n${stderrOutput}`));
55+
reject(new Error(`Vite failed to start within 30s. stdout:\n${stdoutOutput}\nstderr:\n${stderrOutput}`));
3656
}, 30_000);
3757

3858
const onOutput = (chunk: Buffer) => {

0 commit comments

Comments
 (0)