From c154e69dc8381a799f660271105efb0ed9a91591 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=83=B3=E6=83=B3?= <2998495730@qq.com> Date: Tue, 25 Aug 2026 22:23:28 +0800 Subject: [PATCH] Fix issue:validate tests on Windows --- tests/commands/issue/validate.test.ts | 41 +++++++++++++++++++-------- 1 file changed, 29 insertions(+), 12 deletions(-) diff --git a/tests/commands/issue/validate.test.ts b/tests/commands/issue/validate.test.ts index fca2145e95..ba2eefe6ce 100644 --- a/tests/commands/issue/validate.test.ts +++ b/tests/commands/issue/validate.test.ts @@ -1,10 +1,14 @@ import issues from '../../__data__/input/issues' import { pathToFileURL } from 'node:url' -import { execSync } from 'child_process' +import { execFileSync } from 'child_process' import * as fs from 'fs-extra' -const ENV_VAR = - 'cross-env DATA_DIR=tests/__data__/input/data STREAMS_DIR=tests/__data__/output/streams LOGS_DIR=tests/__data__/output/logs' +const ENV = { + ...process.env, + DATA_DIR: 'tests/__data__/input/data', + STREAMS_DIR: 'tests/__data__/output/streams', + LOGS_DIR: 'tests/__data__/output/logs' +} beforeEach(() => { fs.emptyDirSync('tests/__data__/output') @@ -14,11 +18,10 @@ beforeEach(() => { describe('issue:validate', () => { it('can handle streams:add request', () => { const body = issues.find(issue => issue.number === 14179)?.body - const cmd = `${ENV_VAR} npm run issue:validate --- --body="${body}" --labels="approved,streams:add"` try { - const stdout = execSync(cmd, { encoding: 'utf8' }) - if (process.env.DEBUG === 'true') console.log(cmd, stdout) + const stdout = runIssueValidate(body, 'approved,streams:add') + if (process.env.DEBUG === 'true') console.log(stdout) throw new Error('Failed') } catch { expect(content('tests/__data__/output/logs/errors.txt')).toBe( @@ -29,11 +32,10 @@ describe('issue:validate', () => { it('can handle streams:remove request', () => { const body = issues.find(issue => issue.number === 14150)?.body - const cmd = `${ENV_VAR} npm run issue:validate --- --body="${body}" --labels="approved,streams:remove"` try { - const stdout = execSync(cmd, { encoding: 'utf8' }) - if (process.env.DEBUG === 'true') console.log(cmd, stdout) + const stdout = runIssueValidate(body, 'approved,streams:remove') + if (process.env.DEBUG === 'true') console.log(stdout) throw new Error('Failed') } catch { expect(content('tests/__data__/output/logs/errors.txt')).toBe( @@ -44,11 +46,10 @@ describe('issue:validate', () => { it('can handle streams:edit request', () => { const body = issues.find(issue => issue.number === 39097)?.body - const cmd = `${ENV_VAR} npm run issue:validate --- --body="${body}" --labels="approved,streams:edit"` try { - const stdout = execSync(cmd, { encoding: 'utf8' }) - if (process.env.DEBUG === 'true') console.log(cmd, stdout) + const stdout = runIssueValidate(body, 'approved,streams:edit') + if (process.env.DEBUG === 'true') console.log(stdout) throw new Error('Failed') } catch { expect(content('tests/__data__/output/logs/errors.txt')).toBe( @@ -58,6 +59,22 @@ describe('issue:validate', () => { }) }) +function runIssueValidate(body: string | undefined, labels: string) { + return execFileSync( + process.execPath, + [ + '--import', + 'tsx', + 'scripts/commands/issue/validate.ts', + '--body', + `${body}`, + '--labels', + labels + ], + { encoding: 'utf8', env: ENV } + ) +} + function content(filepath: string) { return fs.readFileSync(pathToFileURL(filepath), { encoding: 'utf8' }) }