From 463d3ea5b143d43dbab2c743c2e850fd17b4ecc3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=89=8B=E7=93=9C=E4=B8=80=E5=8D=81=E9=9B=AA?= Date: Tue, 6 Oct 2026 18:08:08 +0800 Subject: [PATCH] fix(test): use typed spawn options for Windows batch regression --- packages/napcat-test/loaderPaths.test.ts | 25 +++++++++--------------- 1 file changed, 9 insertions(+), 16 deletions(-) diff --git a/packages/napcat-test/loaderPaths.test.ts b/packages/napcat-test/loaderPaths.test.ts index 051fdbbd..ec188de5 100644 --- a/packages/napcat-test/loaderPaths.test.ts +++ b/packages/napcat-test/loaderPaths.test.ts @@ -1,6 +1,6 @@ import { afterEach, describe, expect, test } from 'vitest'; 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 path from 'node:path'; import { fileURLToPath } from 'node:url'; @@ -77,20 +77,13 @@ describe('loader paths', () => { copyFileSync(process.execPath, path.join(installDir, 'node.exe')); 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;'); - let exitStatus: number | null = null; - let output = ''; - try { - output = execFileSync('cmd.exe', ['/d', '/s', '/c', `""${path.join(installDir, 'napcat.bat')}" -q 123456"`], { - cwd: fixtureRoot, - encoding: 'utf8', - windowsVerbatimArguments: true, - }); - } 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'] }); + const result = spawnSync('cmd.exe', ['/d', '/s', '/c', `""${path.join(installDir, 'napcat.bat')}" -q 123456"`], { + cwd: fixtureRoot, + encoding: 'utf8', + windowsVerbatimArguments: true, + }); + expect(result.error).toBeUndefined(); + expect(result.status).toBe(7); + expect(JSON.parse(result.stdout)).toEqual({ cwd: installDir, args: ['-q', '123456'] }); }); });