Skip to content

Commit cb058af

Browse files
committed
Fix Windows path separator issues in tests
1 parent e8f3451 commit cb058af

3 files changed

Lines changed: 18 additions & 15 deletions

File tree

test/registry/additional-coverage.test.mts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import path from 'node:path'
44

55
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
66

7+
import { normalizePath } from '../../registry/dist/lib/path.js'
78
import { trash } from '../../scripts/utils/fs.mjs'
89

910
// Helper predicate moved to outer scope.
@@ -88,12 +89,12 @@ describe('additional coverage tests', () => {
8889
// Create the directory
8990
require('node:fs').mkdirSync(dirPath)
9091
const unique2 = fsUtils.uniqueSync(dirPath)
91-
expect(unique2).toBe(path.join(tmpDir, 'mydir-1'))
92+
expect(unique2).toBe(normalizePath(path.join(tmpDir, 'mydir-1')))
9293

9394
// Create another file with same name to test multiple suffixes
9495
require('node:fs').mkdirSync(unique2)
9596
const unique3 = fsUtils.uniqueSync(dirPath)
96-
expect(unique3).toBe(path.join(tmpDir, 'mydir-2'))
97+
expect(unique3).toBe(normalizePath(path.join(tmpDir, 'mydir-2')))
9798
})
9899

99100
it('should handle safeReadFile with different encodings', async () => {

test/registry/fs-utilities.test.mts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import {
2525
writeJson,
2626
writeJsonSync,
2727
} from '../../registry/dist/lib/fs.js'
28+
import { normalizePath } from '../../registry/dist/lib/path.js'
2829
import { trash } from '../../scripts/utils/fs.mjs'
2930

3031
describe('fs utilities', () => {
@@ -46,7 +47,7 @@ describe('fs utilities', () => {
4647
fs.writeFileSync(path.join(tmpDir, 'target.txt'), 'content')
4748

4849
const result = await findUp('target.txt', { cwd: subDir })
49-
expect(result).toBe(path.join(tmpDir, 'target.txt'))
50+
expect(result).toBe(normalizePath(path.join(tmpDir, 'target.txt')))
5051
})
5152

5253
it('should find directory when onlyDirectories is true', async () => {
@@ -59,7 +60,7 @@ describe('fs utilities', () => {
5960
cwd: subDir,
6061
onlyDirectories: true,
6162
})
62-
expect(result).toBe(targetDir)
63+
expect(result).toBe(normalizePath(targetDir))
6364
})
6465

6566
it('should find multiple target names', async () => {
@@ -70,7 +71,7 @@ describe('fs utilities', () => {
7071
const result = await findUp(['package.json', 'config.json'], {
7172
cwd: subDir,
7273
})
73-
expect(result).toBe(path.join(tmpDir, 'config.json'))
74+
expect(result).toBe(normalizePath(path.join(tmpDir, 'config.json')))
7475
})
7576

7677
it('should return undefined when not found', async () => {
@@ -97,7 +98,7 @@ describe('fs utilities', () => {
9798
fs.writeFileSync(path.join(tmpDir, 'target.txt'), 'content')
9899

99100
const result = findUpSync('target.txt', { cwd: subDir })
100-
expect(result).toBe(path.join(tmpDir, 'target.txt'))
101+
expect(result).toBe(normalizePath(path.join(tmpDir, 'target.txt')))
101102
})
102103

103104
it('should stop at specified directory', () => {
@@ -108,7 +109,7 @@ describe('fs utilities', () => {
108109
fs.writeFileSync(path.join(stopDir, 'local.txt'), 'content')
109110

110111
const result = findUpSync('local.txt', { cwd: subDir, stopAt: stopDir })
111-
expect(result).toBe(path.join(stopDir, 'local.txt'))
112+
expect(result).toBe(normalizePath(path.join(stopDir, 'local.txt')))
112113
})
113114

114115
it('should return undefined when stopAt prevents finding', () => {
@@ -419,7 +420,7 @@ describe('fs utilities', () => {
419420
it('should return original path when file does not exist', () => {
420421
const filePath = path.join(tmpDir, 'unique.txt')
421422
const result = uniqueSync(filePath)
422-
expect(result).toBe(filePath)
423+
expect(result).toBe(normalizePath(filePath))
423424
})
424425

425426
it('should generate unique path when file exists', () => {

test/registry/fs.test.mts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import {
2727
writeJson,
2828
writeJsonSync,
2929
} from '../../registry/dist/lib/fs.js'
30+
import { normalizePath } from '../../registry/dist/lib/path.js'
3031
import { trash } from '../../scripts/utils/fs.mjs'
3132

3233
describe('fs module', () => {
@@ -393,22 +394,22 @@ describe('fs module', () => {
393394
const filePath = path.join(tmpDir, 'test.txt')
394395
fs.writeFileSync(filePath, 'content')
395396
const result = uniqueSync(filePath)
396-
expect(result).toBe(path.join(tmpDir, 'test-1.txt'))
397+
expect(result).toBe(normalizePath(path.join(tmpDir, 'test-1.txt')))
397398
})
398399

399400
it('should increment number for multiple conflicts', () => {
400401
const base = path.join(tmpDir, 'test.txt')
401402
fs.writeFileSync(base, 'content')
402403
fs.writeFileSync(path.join(tmpDir, 'test-1.txt'), 'content')
403404
const result = uniqueSync(base)
404-
expect(result).toBe(path.join(tmpDir, 'test-2.txt'))
405+
expect(result).toBe(normalizePath(path.join(tmpDir, 'test-2.txt')))
405406
})
406407

407408
it('should handle files with extensions', () => {
408409
const filePath = path.join(tmpDir, 'file.json')
409410
fs.writeFileSync(filePath, '{}')
410411
const result = uniqueSync(filePath)
411-
expect(result).toBe(path.join(tmpDir, 'file-1.json'))
412+
expect(result).toBe(normalizePath(path.join(tmpDir, 'file-1.json')))
412413
})
413414
})
414415

@@ -417,15 +418,15 @@ describe('fs module', () => {
417418
const searchFile = 'target.txt'
418419
fs.writeFileSync(path.join(tmpDir, searchFile), 'found')
419420
const result = findUpSync(searchFile, { cwd: tmpDir })
420-
expect(result).toBe(path.join(tmpDir, searchFile))
421+
expect(result).toBe(normalizePath(path.join(tmpDir, searchFile)))
421422
})
422423

423424
it('should find file in parent directories', () => {
424425
const subDir = path.join(tmpDir, 'sub', 'dir')
425426
fs.mkdirSync(subDir, { recursive: true })
426427
fs.writeFileSync(path.join(tmpDir, 'target.txt'), 'found')
427428
const result = findUpSync('target.txt', { cwd: subDir })
428-
expect(result).toBe(path.join(tmpDir, 'target.txt'))
429+
expect(result).toBe(normalizePath(path.join(tmpDir, 'target.txt')))
429430
})
430431

431432
it('should return undefined if not found', () => {
@@ -450,15 +451,15 @@ describe('fs module', () => {
450451
const searchFile = 'target.txt'
451452
fs.writeFileSync(path.join(tmpDir, searchFile), 'found')
452453
const result = await findUp(searchFile, { cwd: tmpDir })
453-
expect(result).toBe(path.join(tmpDir, searchFile))
454+
expect(result).toBe(normalizePath(path.join(tmpDir, searchFile)))
454455
})
455456

456457
it('should find file in parent directories', async () => {
457458
const subDir = path.join(tmpDir, 'sub', 'dir')
458459
fs.mkdirSync(subDir, { recursive: true })
459460
fs.writeFileSync(path.join(tmpDir, 'target.txt'), 'found')
460461
const result = await findUp('target.txt', { cwd: subDir })
461-
expect(result).toBe(path.join(tmpDir, 'target.txt'))
462+
expect(result).toBe(normalizePath(path.join(tmpDir, 'target.txt')))
462463
})
463464

464465
it('should return undefined if not found', async () => {

0 commit comments

Comments
 (0)