Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: respect folders with dot at the start, when mocking (#2244)
- Loading branch information
1 parent
55fa650
commit 7f55c54
Showing
3 changed files
with
48 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { describe, expect, test } from 'vitest' | ||
import { pathFromRoot } from 'vite-node/utils' | ||
|
||
describe('vite-node utils', () => { | ||
test('usual path from root returns correct path', () => { | ||
const root = '/Users/name/project' | ||
const filename = '/Users/name/project/test.ts' | ||
expect(pathFromRoot(root, filename)).toBe('/test.ts') | ||
}) | ||
|
||
test('correct path when file and directory share a name', () => { | ||
const root = '/Users/name/project/test' | ||
const filename = '/Users/name/project/test/test/test.ts' | ||
expect(pathFromRoot(root, filename)).toBe('/test/test.ts') | ||
}) | ||
|
||
test('correct path for node builtins', () => { | ||
const root = '/Users/name/project' | ||
const filename = 'fs' | ||
expect(pathFromRoot(root, filename)).toBe('fs') | ||
}) | ||
|
||
test('correct path when relative path has back symbols', () => { | ||
const root = '/Users/name/project' | ||
const filename = '/Users/name/project/../test/test.ts' | ||
expect(pathFromRoot(root, filename)).toBe('/test/test.ts') | ||
}) | ||
|
||
test('correct path when name has a dot at the start', () => { | ||
const root = '/Users/name/project' | ||
const filename = '/Users/name/project/.test.ts' | ||
expect(pathFromRoot(root, filename)).toBe('/.test.ts') | ||
}) | ||
|
||
test('correct path when subfolder has a dot at the start', () => { | ||
const root = '/Users/name/project' | ||
const filename = '/Users/name/project/../.test/test.ts' | ||
expect(pathFromRoot(root, filename)).toBe('/.test/test.ts') | ||
}) | ||
}) |