mirror of
https://github.com/HeyPuter/puter.git
synced 2026-10-03 18:38:32 +00:00
* fix(tools): spawn npm.cmd through a shell on Windows * fix(tools): join the npm command line on Windows to avoid DEP0190 Passing args alongside shell: true warns on Node 24. Test the spawn tuple as data and run a real npm spawn instead of mocking child_process. --------- Co-authored-by: Daniel Salazar <daniel.salazar@puter.com>
35 lines
1.1 KiB
JavaScript
35 lines
1.1 KiB
JavaScript
import { describe, expect, it } from 'vitest';
|
|
import { npmSpawnArgs, spawnNpm } from './npmSpawn.mjs';
|
|
|
|
describe('npmSpawnArgs', () => {
|
|
it('runs npm.cmd through a shell on Windows, with no separate args', () => {
|
|
expect(
|
|
npmSpawnArgs(['run', 'build:ts'], { cwd: '.' }, 'win32'),
|
|
).toEqual(['npm.cmd run build:ts', [], { cwd: '.', shell: true }]);
|
|
});
|
|
|
|
it('spawns npm directly without a shell elsewhere', () => {
|
|
for (const platform of ['linux', 'darwin']) {
|
|
expect(npmSpawnArgs(['ci'], { cwd: '.' }, platform)).toEqual([
|
|
'npm',
|
|
['ci'],
|
|
{ cwd: '.' },
|
|
]);
|
|
}
|
|
});
|
|
});
|
|
|
|
describe('spawnNpm', () => {
|
|
it('runs npm on the current platform', async () => {
|
|
const child = spawnNpm(['--version']);
|
|
let out = '';
|
|
child.stdout.on('data', (d) => (out += d));
|
|
const code = await new Promise((resolve, reject) => {
|
|
child.on('error', reject);
|
|
child.on('close', resolve);
|
|
});
|
|
expect(code).toBe(0);
|
|
expect(out.trim()).toMatch(/^\d+\.\d+\.\d+/);
|
|
}, 20_000);
|
|
});
|