forked from vitejs/vite
-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
resolve.spec.ts
136 lines (106 loc) · 4.16 KB
/
resolve.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
import { expect, test } from 'vitest'
import { isBuild, isWindows, page } from '~utils'
test('bom import', async () => {
expect(await page.textContent('.utf8-bom')).toMatch('[success]')
})
test('deep import', async () => {
expect(await page.textContent('.deep-import')).toMatch('[2,4]')
})
test('entry with exports field', async () => {
expect(await page.textContent('.exports-entry')).toMatch('[success]')
})
test('deep import with exports field', async () => {
expect(await page.textContent('.exports-deep')).toMatch('[success]')
})
test('deep import with query with exports field', async () => {
// since it is imported with `?url` it should return a url
expect(await page.textContent('.exports-deep-query')).toMatch(
isBuild ? /base64/ : '/exports-path/deep.json'
)
})
test('deep import with exports field + exposed dir', async () => {
expect(await page.textContent('.exports-deep-exposed-dir')).toMatch(
'[success]'
)
})
test('deep import with exports field + mapped dir', async () => {
expect(await page.textContent('.exports-deep-mapped-dir')).toMatch(
'[success]'
)
})
test('Respect exports field env key priority', async () => {
expect(await page.textContent('.exports-env')).toMatch('[success]')
})
test('Respect production/development conditionals', async () => {
expect(await page.textContent('.exports-env')).toMatch(
isBuild ? `browser.prod.mjs` : `browser.mjs`
)
})
test('implicit dir/index.js', async () => {
expect(await page.textContent('.index')).toMatch('[success]')
})
test('implicit dir/index.js vs explicit file', async () => {
expect(await page.textContent('.dir-vs-file')).toMatch('[success]')
})
test('exact extension vs. duplicated (.js.js)', async () => {
expect(await page.textContent('.exact-extension')).toMatch('[success]')
})
test('dont add extension to directory name (./dir-with-ext.js/index.js)', async () => {
expect(await page.textContent('.dir-with-ext')).toMatch('[success]')
})
test('do not resolve to the `module` field if the importer is a `require` call', async () => {
expect(await page.textContent('.require-pkg-with-module-field')).toMatch(
'[success]'
)
})
test('a ts module can import another ts module using its corresponding js file name', async () => {
expect(await page.textContent('.ts-extension')).toMatch('[success]')
})
test('filename with dot', async () => {
expect(await page.textContent('.dot')).toMatch('[success]')
})
test.runIf(isWindows)('drive-relative path', async () => {
expect(await page.textContent('.drive-relative')).toMatch('[success]')
})
test('absolute path', async () => {
expect(await page.textContent('.absolute')).toMatch('[success]')
})
test('browser field', async () => {
expect(await page.textContent('.browser')).toMatch('[success]')
})
// TODO: skip because #9459 is reverted
test.skip('Resolve browser field even if module field exists', async () => {
expect(await page.textContent('.browser-module1')).toMatch('[success]')
})
test('Resolve module field if browser field is likely UMD or CJS', async () => {
expect(await page.textContent('.browser-module2')).toMatch('[success]')
})
test('css entry', async () => {
expect(await page.textContent('.css')).toMatch('[success]')
})
test('monorepo linked dep', async () => {
expect(await page.textContent('.monorepo')).toMatch('[success]')
})
test('plugin resolved virtual file', async () => {
expect(await page.textContent('.virtual')).toMatch('[success]')
})
test('plugin resolved custom virtual file', async () => {
expect(await page.textContent('.custom-virtual')).toMatch('[success]')
})
test('resolve inline package', async () => {
expect(await page.textContent('.inline-pkg')).toMatch('[success]')
})
test('resolve.extensions', async () => {
expect(await page.textContent('.custom-ext')).toMatch('[success]')
})
test('resolve.mainFields', async () => {
expect(await page.textContent('.custom-main-fields')).toMatch('[success]')
})
test('resolve.conditions', async () => {
expect(await page.textContent('.custom-condition')).toMatch('[success]')
})
test('resolve package that contains # in path', async () => {
expect(await page.textContent('.path-contains-sharp-symbol')).toMatch(
'[success]'
)
})