Skip to content

Commit d07e17c

Browse files
committed
Fix remaining Windows CI test failures
- Skip Unix shell tests (/bin/sh) on Windows - Fix Windows file URL regex to accept backslashes or forward slashes - Fix case-insensitive path comparison on Windows in relative() function - Add promise catch handlers to prevent unhandled rejections in agent tests
1 parent ad42208 commit d07e17c

File tree

4 files changed

+50
-17
lines changed

4 files changed

+50
-17
lines changed

src/path.ts

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -983,17 +983,30 @@ function relative(from: string, to: string): string {
983983
let i = 0
984984

985985
for (; i < length; i += 1) {
986-
const fromCode = actualFrom.charCodeAt(fromStart + i)
987-
const toCode = actualTo.charCodeAt(toStart + i)
986+
let fromCode = actualFrom.charCodeAt(fromStart + i)
987+
let toCode = actualTo.charCodeAt(toStart + i)
988988

989989
// Paths diverge at this character.
990+
// On Windows, perform case-insensitive comparison.
991+
if (WIN32) {
992+
// Normalize to lowercase for case-insensitive comparison.
993+
// Convert A-Z (65-90) to a-z (97-122).
994+
if (fromCode >= CHAR_UPPERCASE_A && fromCode <= CHAR_UPPERCASE_Z) {
995+
fromCode += 32
996+
}
997+
if (toCode >= CHAR_UPPERCASE_A && toCode <= CHAR_UPPERCASE_Z) {
998+
toCode += 32
999+
}
1000+
}
1001+
9901002
if (fromCode !== toCode) {
9911003
break
9921004
}
9931005

9941006
// Track directory separators (both forward and backslash for Windows compatibility).
9951007
// We need this to ensure we only split at directory boundaries.
996-
if (isPathSeparator(fromCode)) {
1008+
// Use original fromCode from actualFrom (before case normalization).
1009+
if (isPathSeparator(actualFrom.charCodeAt(fromStart + i))) {
9971010
lastCommonSep = i
9981011
}
9991012
}

test/agent.test.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -474,6 +474,8 @@ describe('agent', () => {
474474
it('should have a function that returns a promise', () => {
475475
const result = execNpm(['--version'])
476476
expect(result).toBeInstanceOf(Promise)
477+
// Catch promise to prevent unhandled rejection on Windows.
478+
result.catch(() => {})
477479
})
478480

479481
it('should be a function', () => {
@@ -485,6 +487,8 @@ describe('agent', () => {
485487
it('should have a function that returns a promise', () => {
486488
const result = execPnpm(['--version'])
487489
expect(result).toBeInstanceOf(Promise)
490+
// Catch promise to prevent unhandled rejection on Windows.
491+
result.catch(() => {})
488492
})
489493

490494
it('should be a function', () => {
@@ -496,6 +500,8 @@ describe('agent', () => {
496500
it('should have a function that returns a promise', () => {
497501
const result = execYarn(['--version'])
498502
expect(result).toBeInstanceOf(Promise)
503+
// Catch promise to prevent unhandled rejection on Windows.
504+
result.catch(() => {})
499505
})
500506

501507
it('should be a function', () => {
@@ -507,6 +513,8 @@ describe('agent', () => {
507513
it('should have a function that returns a promise', () => {
508514
const result = execScript('test')
509515
expect(result).toBeInstanceOf(Promise)
516+
// Catch promise to prevent unhandled rejection on Windows.
517+
result.catch(() => {})
510518
})
511519

512520
it('should be a function', () => {
@@ -516,18 +524,24 @@ describe('agent', () => {
516524
it('should handle script name with array args', () => {
517525
const result = execScript('test', ['--coverage'])
518526
expect(result).toBeInstanceOf(Promise)
527+
// Catch promise to prevent unhandled rejection on Windows.
528+
result.catch(() => {})
519529
})
520530

521531
it('should handle script name with options object', () => {
522532
const result = execScript('test', { cwd: process.cwd() })
523533
expect(result).toBeInstanceOf(Promise)
534+
// Catch promise to prevent unhandled rejection on Windows.
535+
result.catch(() => {})
524536
})
525537

526538
it('should handle script name with args and options', () => {
527539
const result = execScript('test', ['--coverage'], {
528540
cwd: process.cwd(),
529541
})
530542
expect(result).toBeInstanceOf(Promise)
543+
// Catch promise to prevent unhandled rejection on Windows.
544+
result.catch(() => {})
531545
})
532546
})
533547
})

test/path.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -521,10 +521,10 @@ describe('path utilities', () => {
521521
it('should handle Windows file URLs', () => {
522522
if (process.platform === 'win32') {
523523
expect(pathLikeToString(new URL('file:///C:/Windows'))).toMatch(
524-
/^C:\//,
524+
/^C:[\\/]/,
525525
)
526526
expect(pathLikeToString(new URL('file:///D:/data/file.txt'))).toMatch(
527-
/^D:\//,
527+
/^D:[\\/]/,
528528
)
529529
}
530530
})

test/spawn.test.ts

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -279,12 +279,15 @@ describe('spawn', () => {
279279
expect(result.code).toBe(0)
280280
})
281281

282-
it('should handle shell as string path', async () => {
283-
const result = await spawn('echo', ['hello'], {
284-
shell: '/bin/sh',
285-
})
286-
expect(result.code).toBe(0)
287-
})
282+
it.skipIf(process.platform === 'win32')(
283+
'should handle shell as string path',
284+
async () => {
285+
const result = await spawn('echo', ['hello'], {
286+
shell: '/bin/sh',
287+
})
288+
expect(result.code).toBe(0)
289+
},
290+
)
288291

289292
it('should handle undefined args', async () => {
290293
const result = await spawn('pwd', undefined)
@@ -415,12 +418,15 @@ describe('spawn', () => {
415418
expect(result.status).toBe(0)
416419
})
417420

418-
it('should handle shell as string path', () => {
419-
const result = spawnSync('echo', ['hello'], {
420-
shell: '/bin/sh',
421-
})
422-
expect(result.status).toBe(0)
423-
})
421+
it.skipIf(process.platform === 'win32')(
422+
'should handle shell as string path',
423+
() => {
424+
const result = spawnSync('echo', ['hello'], {
425+
shell: '/bin/sh',
426+
})
427+
expect(result.status).toBe(0)
428+
},
429+
)
424430

425431
it('should handle undefined args', () => {
426432
const result = spawnSync('pwd', undefined)

0 commit comments

Comments
 (0)