/
utils.spec.ts
58 lines (52 loc) · 1.45 KB
/
utils.spec.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import { describe, expect, it } from 'vitest'
import { normalizeAliases, filename, resolveAlias } from '../src/utils'
describe('alias', () => {
const _aliases = {
'@foo/bar': '@foo/bar/dist/index.mjs',
'@foo/bar/utils': '@foo/bar/dist/utils.mjs',
'@': '/root',
bingpot: '@/bingpot/index.ts',
test: '@bingpot/index.ts'
}
const aliases = normalizeAliases(_aliases)
it('normalizeAliases', () => {
expect(aliases).toMatchInlineSnapshot(`
{
"@": "/root",
"@foo/bar": "@foo/bar/dist/index.mjs",
"@foo/bar/utils": "@foo/bar/dist/utils.mjs",
"bingpot": "/root/bingpot/index.ts",
"test": "@bingpot/index.ts",
}
`)
})
describe('resolveAlias', () => {
for (const [from, to] of Object.entries(aliases)) {
it(from, () => {
expect(resolveAlias(from, aliases)).toBe(to)
})
}
it('unchanged', () => {
expect(resolveAlias('foo/bar.js', aliases)).toBe('foo/bar.js')
expect(resolveAlias('./bar.js', aliases)).toBe('./bar.js')
})
})
})
describe('filename', () => {
const files = {
// POSIX
'test.html': 'test',
'/temp/myfile.html': 'myfile',
'./myfile.html': 'myfile',
// Windows
'C:\\temp\\': undefined,
'C:\\temp\\myfile.html': 'myfile',
'\\temp\\myfile.html': 'myfile',
'.\\myfile.html': 'myfile'
}
for (const file in files) {
it(file, () => {
expect(filename(file)).toEqual(files[file])
})
}
})