Files
VoiceStudio/scripts/electron-smoke-test.mjs
Palash Debnath bc6d564cfc fix(dev): spawn the real Bun so npm-installed Bun works on Windows (#4603)
* fix(dev): spawn the real Bun so npm-installed Bun works on Windows

bunCommand() prefers the running Bun, then npm_execpath, then the executable behind a Windows npm shim on PATH. A missing Bun gives an install hint from every script that spawns it, and a test guards against bare bun/bunx spawns. Builds on the report and first fix in #4525.

* Add changelog fragment for the Bun spawn fix
2026-12-02 20:25:13 +00:00

38 lines
1.2 KiB
JavaScript

#!/usr/bin/env node
import { spawnSync } from 'node:child_process';
import process from 'node:process';
import { bunCommand, explainBunError } from '../electron/scripts/bun-command.mjs';
function run(command, args) {
console.log(`\n> ${command} ${args.join(' ')}`);
const result = spawnSync(command, args, {
cwd: process.cwd(),
env: process.env,
stdio: 'inherit',
});
if (result.error) throw explainBunError(result.error);
if (result.status !== 0) process.exit(result.status ?? 1);
}
const args = process.argv.slice(2);
if (!args.includes('--skip-build')) {
run(bunCommand(), ['run', '--cwd', 'electron', 'dist:dir']);
}
const testArgs = args.filter((arg) => arg !== '--skip-build');
const smoke = ['electron/tests/packaged-smoke.mjs', ...(testArgs.length ? testArgs : ['--setup'])];
const headlessLinux =
process.platform === 'linux' && !process.env.DISPLAY && !process.env.WAYLAND_DISPLAY;
if (headlessLinux) {
const probe = spawnSync('xvfb-run', ['--help'], { stdio: 'ignore' });
if (probe.error) {
console.error('A display is required. Install xvfb or run this command from a desktop session.');
process.exit(1);
}
run('xvfb-run', ['-a', 'node', ...smoke]);
} else {
run('node', smoke);
}