Skip to content

Commit d5a754e

Browse files
committed
fix(test): cross-platform entry path and bare remote default branch
- CLI 路径用 fileURLToPath 转换,修复 Windows 下 new URL().pathname 产生 C:\D:\... 的模块解析失败 - addOrigin 的 bare 仓库显式 -b main:CI 干净环境 init.defaultBranch 未设为 main 时,clone 分支漂移导致 sync 测试 push 报 src refspec main does not match any(原插件仓库套件同款隐性 bug, 由 CI 首次暴露)
1 parent 5616baa commit d5a754e

1 file changed

Lines changed: 4 additions & 3 deletions

File tree

‎test/cli.test.mjs‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@ import { execFileSync, spawn, spawnSync } from 'node:child_process'
33
import { existsSync, mkdtempSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs'
44
import { tmpdir } from 'node:os'
55
import { join } from 'node:path'
6+
import { fileURLToPath } from 'node:url'
67
import test from 'node:test'
78

8-
const CLI = new URL('../cli.mjs', import.meta.url)
9+
const CLI = fileURLToPath(new URL('../cli.mjs', import.meta.url))
910

1011
function run(args, cwd = process.cwd(), env = {}) {
11-
return spawnSync(process.execPath, [CLI.pathname, ...args], {
12+
return spawnSync(process.execPath, [CLI, ...args], {
1213
cwd,
1314
encoding: 'utf8',
1415
env: { ...process.env, ...env },
@@ -60,7 +61,7 @@ server.listen(0, '127.0.0.1', () => writeFileSync(process.env.PORT_FILE, String(
6061

6162
function addOrigin(root) {
6263
const remote = mkdtempSync(join(tmpdir(), 'shadow-remote-'))
63-
execFileSync('git', ['init', '--bare'], { cwd: remote })
64+
execFileSync('git', ['init', '--bare', '-b', 'main'], { cwd: remote })
6465
execFileSync('git', ['remote', 'add', 'origin', remote], { cwd: root })
6566
execFileSync('git', ['push', '-u', 'origin', 'main'], { cwd: root })
6667
return remote

0 commit comments

Comments
 (0)