Skip to content

Commit b08fa2a

Browse files
committed
fix: normalize paths in additional windows compat tests
1 parent 3d49e4f commit b08fa2a

3 files changed

Lines changed: 62 additions & 37 deletions

File tree

tests/compat/custom-ignore.test.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*/
77

88
import { describe, it, expect, beforeAll, afterAll } from 'vitest'
9-
import { basename } from 'path'
9+
import { basename, isAbsolute } from 'path'
1010
import { glob as globOriginal, globSync as globSyncOriginal, type IgnoreLike } from 'glob'
1111
import { glob, globSync, IgnorePattern, Path } from '../../js/index.js'
1212
import { createTestFixture, cleanupFixture, FixtureConfig } from '../harness.js'
@@ -344,11 +344,11 @@ describe('custom ignore objects', () => {
344344

345345
const results = globSync('*', { cwd: fixture, ignore, absolute: true })
346346

347-
// Should not include 'a' file
348-
expect(results.some(r => r.endsWith('/a'))).toBe(false)
347+
// Should not include 'a' file (check with both forward and back slashes for cross-platform)
348+
expect(results.some(r => r.endsWith('/a') || r.endsWith('\\a'))).toBe(false)
349349

350-
// Paths should be absolute
351-
expect(results.every(r => r.startsWith('/'))).toBe(true)
350+
// Paths should be absolute (use Node's isAbsolute for cross-platform check)
351+
expect(results.every(r => isAbsolute(r))).toBe(true)
352352
})
353353

354354
it('should work with mark option', () => {

tests/compat/dot-relative.test.ts

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@ import { sep } from 'path'
99
import { glob as globOriginal, globSync as globSyncOriginal, Glob as GlobOriginal } from 'glob'
1010
import { createTestFixture, cleanupFixture, loadGloblin, DEFAULT_FIXTURE } from '../harness.js'
1111

12+
// Helper to check if path starts with ./ or .\ (cross-platform dotRelative prefix)
13+
const startsWithDotSlash = (path: string): boolean =>
14+
path.startsWith('./') || path.startsWith('.\\')
15+
// Normalize path to use forward slashes
16+
const normalize = (path: string): string => path.replace(/\\/g, '/')
17+
1218
describe('dot-relative - prepend ./ to relative paths', () => {
1319
let fixturePath: string
1420
let globlin: Awaited<ReturnType<typeof loadGloblin>>
@@ -66,7 +72,7 @@ describe('dot-relative - prepend ./ to relative paths', () => {
6672

6773
expect(results.length).toBeGreaterThan(0)
6874
for (const m of results) {
69-
expect(m.startsWith('./')).toBe(true)
75+
expect(startsWithDotSlash(m)).toBe(true)
7076
}
7177
})
7278

@@ -79,7 +85,7 @@ describe('dot-relative - prepend ./ to relative paths', () => {
7985

8086
expect(results.length).toBeGreaterThan(0)
8187
for (const m of results) {
82-
expect(m.startsWith('./')).toBe(true)
88+
expect(startsWithDotSlash(m)).toBe(true)
8389
}
8490
})
8591

@@ -92,7 +98,7 @@ describe('dot-relative - prepend ./ to relative paths', () => {
9298

9399
expect(results.length).toBeGreaterThan(0)
94100
for (const m of results) {
95-
expect(m.startsWith('./')).toBe(false)
101+
expect(startsWithDotSlash(m)).toBe(false)
96102
}
97103
})
98104

@@ -105,7 +111,7 @@ describe('dot-relative - prepend ./ to relative paths', () => {
105111

106112
expect(results.length).toBeGreaterThan(0)
107113
for (const m of results) {
108-
expect(m.startsWith('./')).toBe(false)
114+
expect(startsWithDotSlash(m)).toBe(false)
109115
}
110116
})
111117
})
@@ -145,7 +151,7 @@ describe('dot-relative - prepend ./ to relative paths', () => {
145151
}
146152
const results = await globlin.glob('a/b/c/d', { cwd: fixturePath, dotRelative: true })
147153
expect(results.length).toBe(1)
148-
expect(results[0]).toBe('./a/b/c/d')
154+
expect(normalize(results[0])).toBe('./a/b/c/d')
149155
})
150156

151157
it('works with ** pattern', async () => {
@@ -155,7 +161,7 @@ describe('dot-relative - prepend ./ to relative paths', () => {
155161
}
156162
const results = await globlin.glob('**/*.txt', { cwd: fixturePath, dotRelative: true })
157163
for (const m of results) {
158-
expect(m.startsWith('./')).toBe(true)
164+
expect(startsWithDotSlash(m)).toBe(true)
159165
}
160166
})
161167

@@ -172,7 +178,7 @@ describe('dot-relative - prepend ./ to relative paths', () => {
172178
})
173179
for (const m of results) {
174180
// Absolute paths should not start with ./
175-
expect(m.startsWith('./')).toBe(false)
181+
expect(startsWithDotSlash(m)).toBe(false)
176182
}
177183
})
178184
})

tests/compat/dot.test.ts

Lines changed: 44 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ import { createTestFixture, cleanupFixture, loadGloblin, type GloblinModule } fr
99
let fixtureDir: string
1010
let globlin: GloblinModule
1111

12+
// Normalize paths for cross-platform comparison (replace backslashes with forward slashes)
13+
const normalize = (paths: string[]): string[] => paths.map(p => p.replace(/\\/g, '/'))
14+
const normalizeStr = (path: string): string => path.replace(/\\/g, '/')
15+
1216
// Fixture with dotfiles
1317
const DOT_FILE_FIXTURE = {
1418
files: [
@@ -75,13 +79,17 @@ describe('Dot file handling', () => {
7579
const globResults = await glob('nested/**/*', { cwd: fixtureDir })
7680
const globlinResults = await globlin.glob('nested/**/*', { cwd: fixtureDir })
7781

82+
// Normalize paths for cross-platform comparison
83+
const normalizedGlob = normalize(globResults)
84+
const normalizedGloblin = normalize(globlinResults)
85+
7886
// Should include visible files
79-
expect(globResults).toContain('nested/visible')
80-
expect(globResults).toContain('nested/visible/file.txt')
87+
expect(normalizedGlob).toContain('nested/visible')
88+
expect(normalizedGlob).toContain('nested/visible/file.txt')
8189

8290
// Globlin should match
83-
expect(globlinResults).toContain('nested/visible')
84-
expect(globlinResults).toContain('nested/visible/file.txt')
91+
expect(normalizedGloblin).toContain('nested/visible')
92+
expect(normalizedGloblin).toContain('nested/visible/file.txt')
8593
})
8694
})
8795

@@ -104,29 +112,37 @@ describe('Dot file handling', () => {
104112
const globResults = await glob('**/*', { cwd: fixtureDir, dot: true })
105113
const globlinResults = await globlin.glob('**/*', { cwd: fixtureDir, dot: true })
106114

107-
// Should include dotfiles
108-
expect(globResults).toContain('.hidden')
109-
expect(globResults).toContain('.git/config')
110-
expect(globResults).toContain('src/.env')
111-
expect(globResults).toContain('nested/.config')
115+
// Normalize paths for cross-platform comparison
116+
const normalizedGlob = normalize(globResults)
117+
const normalizedGloblin = normalize(globlinResults)
112118

113-
expect(globlinResults).toContain('.hidden')
114-
expect(globlinResults).toContain('.git/config')
115-
expect(globlinResults).toContain('src/.env')
116-
expect(globlinResults).toContain('nested/.config')
119+
// Should include dotfiles
120+
expect(normalizedGlob).toContain('.hidden')
121+
expect(normalizedGlob).toContain('.git/config')
122+
expect(normalizedGlob).toContain('src/.env')
123+
expect(normalizedGlob).toContain('nested/.config')
124+
125+
expect(normalizedGloblin).toContain('.hidden')
126+
expect(normalizedGloblin).toContain('.git/config')
127+
expect(normalizedGloblin).toContain('src/.env')
128+
expect(normalizedGloblin).toContain('nested/.config')
117129
})
118130

119131
it('should include files inside dotdirs with **/*', async () => {
120132
const globResults = await glob('**/*', { cwd: fixtureDir, dot: true })
121133
const globlinResults = await globlin.glob('**/*', { cwd: fixtureDir, dot: true })
122134

123-
expect(globResults).toContain('.git/config')
124-
expect(globResults).toContain('.git/HEAD')
125-
expect(globResults).toContain('nested/.config/settings.json')
135+
// Normalize paths for cross-platform comparison
136+
const normalizedGlob = normalize(globResults)
137+
const normalizedGloblin = normalize(globlinResults)
138+
139+
expect(normalizedGlob).toContain('.git/config')
140+
expect(normalizedGlob).toContain('.git/HEAD')
141+
expect(normalizedGlob).toContain('nested/.config/settings.json')
126142

127-
expect(globlinResults).toContain('.git/config')
128-
expect(globlinResults).toContain('.git/HEAD')
129-
expect(globlinResults).toContain('nested/.config/settings.json')
143+
expect(normalizedGloblin).toContain('.git/config')
144+
expect(normalizedGloblin).toContain('.git/HEAD')
145+
expect(normalizedGloblin).toContain('nested/.config/settings.json')
130146
})
131147
})
132148

@@ -143,24 +159,27 @@ describe('Dot file handling', () => {
143159
const globResults = await glob('.git/*', { cwd: fixtureDir })
144160
const globlinResults = await globlin.glob('.git/*', { cwd: fixtureDir })
145161

146-
expect(globResults.sort()).toEqual(['.git/HEAD', '.git/config'].sort())
147-
expect(globlinResults.sort()).toEqual(['.git/HEAD', '.git/config'].sort())
162+
// Normalize paths for cross-platform comparison
163+
expect(normalize(globResults).sort()).toEqual(['.git/HEAD', '.git/config'].sort())
164+
expect(normalize(globlinResults).sort()).toEqual(['.git/HEAD', '.git/config'].sort())
148165
})
149166

150167
it('should match **/.env without dot option', async () => {
151168
const globResults = await glob('**/.env', { cwd: fixtureDir })
152169
const globlinResults = await globlin.glob('**/.env', { cwd: fixtureDir })
153170

154-
expect(globResults).toContain('src/.env')
155-
expect(globlinResults).toContain('src/.env')
171+
// Normalize paths for cross-platform comparison
172+
expect(normalize(globResults)).toContain('src/.env')
173+
expect(normalize(globlinResults)).toContain('src/.env')
156174
})
157175

158176
it('should match nested dotdir pattern without dot option', async () => {
159177
const globResults = await glob('nested/.config/*', { cwd: fixtureDir })
160178
const globlinResults = await globlin.glob('nested/.config/*', { cwd: fixtureDir })
161179

162-
expect(globResults).toContain('nested/.config/settings.json')
163-
expect(globlinResults).toContain('nested/.config/settings.json')
180+
// Normalize paths for cross-platform comparison
181+
expect(normalize(globResults)).toContain('nested/.config/settings.json')
182+
expect(normalize(globlinResults)).toContain('nested/.config/settings.json')
164183
})
165184
})
166185

0 commit comments

Comments
 (0)