/
utils.test.ts
40 lines (34 loc) · 1.42 KB
/
utils.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
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')
})
})