fix(tests): 修两处跨平台测试缺陷(ci-windows 红)

两处都只在 Windows 上暴露,本机 macOS 全绿所以合入时没看出来:

① tests/fs-create-file.spec.ts:对 readdir 结果做**未排序**的 toEqual,而目录项顺序由文件系统决定
   (Windows 与 ext4/APFS 不同)→ 改为比较排序后的名字集合。

② tests/open-external.spec.ts:reveal 失败用例用字面量 '/a/b.txt' 做夹具,但被测代码用**宿主**路径
   模块规范化路径并推导父目录——'/a/b.txt' 在 win32 上不是绝对路径(会按当前盘符解析),于是
   期望的 args ['/a'] 与实到的父目录不一致 → 夹具与期望值都改为由宿主 path 模块推导
   (resolve('/', 'a', 'b.txt') / dirname(file)),两个平台跑同一份语义断言。

判别依据:本机 macOS 上两条 spec 47 例全绿;真 Windows 由 ci-windows lane 复验(`pnpm test:windows`)。
This commit is contained in:
Menghuan1918 committed 2026-10-05 23:36:02 +08:00
1 parent 58d7f7128a
commit c02a7917fa
2 files changed
+10 -6

No files matched your search

+3 -1
View File
@@ -91,7 +91,9 @@ describe('createWorkspaceFile', () => {
for (const name of ['console.txt', 'conx', 'COM10', 'LPT', 'null.md', 'auxiliary']) {
await expect(createWorkspaceFile({ cwd: root, path: root, name })).resolves.toEqual({ path: join(root, name) })
}
expect(await readdir(root)).toEqual(['COM10', 'LPT', 'auxiliary', 'console.txt', 'conx', 'null.md'])
// `readdir` order is filesystem-defined (Windows returns a different order than
// ext4/APFS), so compare the sorted name set instead of the raw listing.
expect((await readdir(root)).sort()).toEqual(['COM10', 'LPT', 'auxiliary', 'console.txt', 'conx', 'null.md'])
})
it('refuses an existing destination with the same conflict code as rename and mkdir', async () => {
+7 -5
View File
@@ -4,6 +4,7 @@
* OS handlers are not launched in unit tests.
*/
import { EventEmitter } from 'node:events'
import { dirname, resolve } from 'node:path'
import { describe, expect, it, vi } from 'vitest'
import {
launchExternal,
@@ -284,10 +285,11 @@ describe('launchExternal Windows branch order and failure reporting', () => {
it('reports a reveal failure with the same shape (one branch, `path` subject)', async () => {
const fake = recordingSpawn()
// Path absoluteness is checked with the HOST path module, so this case uses
// the linux branch (an absolute POSIX path) to pin the aggregated message
// of the reveal half.
const pending = launchExternal('reveal', '/a/b.txt', {
// The path is normalized and its parent derived with the HOST path module,
// so the fixture must be host-absolute too — a literal `/a/b.txt` is not an
// absolute path on Windows (win32 resolves it against the current drive).
const file = resolve('/', 'a', 'b.txt')
const pending = launchExternal('reveal', file, {
platform: 'linux',
wsl: false,
spawn: fake.spawn,
@@ -296,7 +298,7 @@ describe('launchExternal Windows branch order and failure reporting', () => {
const error = await pending.then(() => null, (reason: unknown) => reason)
expect(fake.calls.map(call => ({ command: call.command, args: call.args }))).toEqual([
{ command: 'xdg-open', args: ['/a'] },
{ command: 'xdg-open', args: [dirname(file)] },
])
expect((error as SidebarError).message).toBe(
'failed to launch external opener for the path: "xdg-open" (spawn xdg-open ENOENT)',