Skip to content

Commit 0eecb26

Browse files
committed
Fix find root
1 parent c60294b commit 0eecb26

File tree

1 file changed

+8
-23
lines changed

1 file changed

+8
-23
lines changed

packages/next-plugin/src/__tests__/find-root.test.ts

Lines changed: 8 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -81,38 +81,23 @@ describe('findRoot', () => {
8181
expect(result).toBe(expectedRoot)
8282
})
8383

84-
it('should handle Windows-style paths', () => {
85-
const mockDir = 'C:\\project\\src\\components'
86-
const expectedRoot = 'C:\\project'
84+
it('should handle paths', () => {
85+
const mockDir = join('a', 'b', 'c', 'd')
86+
const expectedRoot = join('a', 'b')
8787

8888
vi.mocked(existsSync)
89-
.mockReturnValueOnce(false) // C:\project\src\components\package.json
90-
.mockReturnValueOnce(false) // C:\project\src\package.json
91-
.mockReturnValueOnce(true) // C:\project\package.json
92-
.mockReturnValueOnce(false) // C:\package.json
93-
94-
const result = findRoot(mockDir)
95-
96-
expect(result).toBe(expectedRoot)
97-
})
98-
99-
it('should handle relative paths', () => {
100-
const mockDir = './src/components'
101-
const expectedRoot = '.'
102-
103-
vi.mocked(existsSync)
104-
.mockReturnValueOnce(false) // ./src/components/package.json
105-
.mockReturnValueOnce(false) // ./src/package.json
106-
.mockReturnValueOnce(true) // ./package.json
107-
.mockReturnValueOnce(false) // ../package.json
89+
.mockReturnValueOnce(false) // a/b/c/d/package.json
90+
.mockReturnValueOnce(false) // a/b/c/package.json
91+
.mockReturnValueOnce(true) // a/b/package.json
92+
.mockReturnValueOnce(false) // a/package.json
10893

10994
const result = findRoot(mockDir)
11095

11196
expect(result).toBe(expectedRoot)
11297
})
11398

11499
it('should stop at filesystem root', () => {
115-
const mockDir = '/some/path'
100+
const mockDir = join('a', 'b', 'c')
116101

117102
// Mock existsSync to return false for all calls, simulating no package.json found
118103
vi.mocked(existsSync).mockReturnValue(false)

0 commit comments

Comments
 (0)