fix(test): use typed spawn options for Windows batch regression
Release Tag / validate-version (push) Canceled after 0s
Release Tag / trigger-release (push) Canceled after 0s

This commit is contained in:
手瓜一十雪 committed 2026-10-06 18:08:08 +08:00
1 parent 0d6ce7f509
commit 463d3ea5b1
1 file changed
+9 -16
+9 -16
View File
@@ -1,6 +1,6 @@
import { afterEach, describe, expect, test } from 'vitest'; import { afterEach, describe, expect, test } from 'vitest';
import { copyFileSync, mkdtempSync, mkdirSync, rmSync, writeFileSync } from 'node:fs'; import { copyFileSync, mkdtempSync, mkdirSync, rmSync, writeFileSync } from 'node:fs';
import { execFileSync } from 'node:child_process'; import { execFileSync, spawnSync } from 'node:child_process';
import { tmpdir } from 'node:os'; import { tmpdir } from 'node:os';
import path from 'node:path'; import path from 'node:path';
import { fileURLToPath } from 'node:url'; import { fileURLToPath } from 'node:url';
@@ -77,20 +77,13 @@ describe('loader paths', () => {
copyFileSync(process.execPath, path.join(installDir, 'node.exe')); copyFileSync(process.execPath, path.join(installDir, 'node.exe'));
copyFileSync(path.join(packageRoot, 'napcat-develop/napcat.bat'), path.join(installDir, 'napcat.bat')); copyFileSync(path.join(packageRoot, 'napcat-develop/napcat.bat'), path.join(installDir, 'napcat.bat'));
writeFileSync(path.join(installDir, 'index.js'), 'console.log(JSON.stringify({ cwd: process.cwd(), args: process.argv.slice(2) })); process.exitCode = 7;'); writeFileSync(path.join(installDir, 'index.js'), 'console.log(JSON.stringify({ cwd: process.cwd(), args: process.argv.slice(2) })); process.exitCode = 7;');
let exitStatus: number | null = null; const result = spawnSync('cmd.exe', ['/d', '/s', '/c', `""${path.join(installDir, 'napcat.bat')}" -q 123456"`], {
let output = ''; cwd: fixtureRoot,
try { encoding: 'utf8',
output = execFileSync('cmd.exe', ['/d', '/s', '/c', `""${path.join(installDir, 'napcat.bat')}" -q 123456"`], { windowsVerbatimArguments: true,
cwd: fixtureRoot, });
encoding: 'utf8', expect(result.error).toBeUndefined();
windowsVerbatimArguments: true, expect(result.status).toBe(7);
}); expect(JSON.parse(result.stdout)).toEqual({ cwd: installDir, args: ['-q', '123456'] });
} catch (error) {
const result = error as { status: number; stdout: string };
exitStatus = result.status;
output = result.stdout;
}
expect(exitStatus).toBe(7);
expect(JSON.parse(output)).toEqual({ cwd: installDir, args: ['-q', '123456'] });
}); });
}); });