Skip to content

Commit 2038e3f

Browse files
committed
fix
1 parent 4ae394a commit 2038e3f

File tree

9 files changed

+115
-83
lines changed

9 files changed

+115
-83
lines changed

playground/assets/__tests__/assets.spec.ts

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -638,20 +638,23 @@ test("new URL(/* @vite-ignore */ 'non-existent', import.meta.url)", async () =>
638638
)
639639
})
640640

641-
test.runIf(isBuild)('manifest', async () => {
642-
const manifest = readManifest('foo')
643-
const entry = manifest['index.html']
644-
645-
for (const file of listAssets('foo')) {
646-
if (file.endsWith('.css')) {
647-
// ignore icons-*.css and css-url-url-*.css as it's imported with ?url
648-
if (file.includes('icons-') || file.includes('css-url-url-')) continue
649-
expect(entry.css).toContain(`assets/${file}`)
650-
} else if (!file.endsWith('.js')) {
651-
expect(entry.assets).toContain(`assets/${file}`)
641+
test.runIf(isBuild && !process.env._VITE_TEST_NATIVE_PLUGIN)(
642+
'manifest',
643+
async () => {
644+
const manifest = readManifest('foo')
645+
const entry = manifest['index.html']
646+
647+
for (const file of listAssets('foo')) {
648+
if (file.endsWith('.css')) {
649+
// ignore icons-*.css and css-url-url-*.css as it's imported with ?url
650+
if (file.includes('icons-') || file.includes('css-url-url-')) continue
651+
expect(entry.css).toContain(`assets/${file}`)
652+
} else if (!file.endsWith('.js')) {
653+
expect(entry.assets).toContain(`assets/${file}`)
654+
}
652655
}
653-
}
654-
})
656+
},
657+
)
655658

656659
describe.runIf(isBuild)('css and assets in css in build watch', () => {
657660
test('css will not be lost and css does not contain undefined', async () => {

playground/backend-integration/__tests__/backend-integration.spec.ts

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ describe('asset imports from js', () => {
4545
})
4646

4747
describe.runIf(isBuild)('build', () => {
48-
test('manifest', async () => {
48+
test.skipIf(!!process.env._VITE_TEST_NATIVE_PLUGIN)('manifest', async () => {
4949
const manifest = readManifest('dev')
5050
const htmlEntry = manifest['index.html']
5151
const mainTsEntry = manifest['main.ts']
@@ -61,6 +61,7 @@ describe.runIf(isBuild)('build', () => {
6161
expect(mainTsEntry.imports.length).toBeGreaterThanOrEqual(1)
6262
const mainTsEntryImported = manifest[mainTsEntry.imports[0]]
6363
expect(mainTsEntryImported).toBeDefined()
64+
6465
expect(mainTsEntryImported.assets?.length ?? 0).toBeGreaterThanOrEqual(1)
6566
expect(mainTsEntryImported.assets).toContainEqual(
6667
expect.stringMatching(/assets\/url-[-\w]{8}\.css/),
@@ -82,12 +83,15 @@ describe.runIf(isBuild)('build', () => {
8283
expect(waterContainerEntry?.file).not.toBeUndefined()
8384
})
8485

85-
test('CSS imported from JS entry should have a non-nested chunk name', () => {
86-
const manifest = readManifest('dev')
87-
const mainTsEntryCss = manifest['nested/sub.ts'].css
88-
expect(mainTsEntryCss.length).toBe(1)
89-
expect(mainTsEntryCss[0].replace('assets/', '')).not.toContain('/')
90-
})
86+
test.skipIf(!!process.env._VITE_TEST_NATIVE_PLUGIN)(
87+
'CSS imported from JS entry should have a non-nested chunk name',
88+
() => {
89+
const manifest = readManifest('dev')
90+
const mainTsEntryCss = manifest['nested/sub.ts'].css
91+
expect(mainTsEntryCss.length).toBe(1)
92+
expect(mainTsEntryCss[0].replace('assets/', '')).not.toContain('/')
93+
},
94+
)
9195

9296
test('entrypoint assets should not generate empty JS file', () => {
9397
expect(serverLogs).not.toContainEqual(

playground/css-codesplit-cjs/__tests__/css-codesplit-cjs.spec.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,12 @@ describe.runIf(isBuild)('build', () => {
1313
expect(findAssetFile('other.*.js$')).toMatch(`/* empty css`)
1414
})
1515

16-
test('should generate correct manifest', async () => {
17-
const manifest = readManifest()
18-
expect(manifest['index.html'].css.length).toBe(2)
19-
expect(manifest['other.js'].css.length).toBe(1)
20-
})
16+
test.skipIf(!!process.env._VITE_TEST_NATIVE_PLUGIN)(
17+
'should generate correct manifest',
18+
async () => {
19+
const manifest = readManifest()
20+
expect(manifest['index.html'].css.length).toBe(2)
21+
expect(manifest['other.js'].css.length).toBe(1)
22+
},
23+
)
2124
})

playground/css-codesplit/__tests__/css-codesplit.spec.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,14 @@ describe.runIf(isBuild)('build', () => {
5757
expect(sharedCSSWithJSChunk).not.toMatch(/import(?!\s*".\/modulepreload)/)
5858
})
5959

60-
test('should generate correct manifest', async () => {
61-
const manifest = readManifest()
62-
expect(manifest['index.html'].css.length).toBe(2)
63-
expect(manifest['other.js'].css.length).toBe(1)
64-
})
60+
test.skipIf(!!process.env._VITE_TEST_NATIVE_PLUGIN)(
61+
'should generate correct manifest',
62+
async () => {
63+
const manifest = readManifest()
64+
expect(manifest['index.html'].css.length).toBe(2)
65+
expect(manifest['other.js'].css.length).toBe(1)
66+
},
67+
)
6568

6669
test('should not mark a css chunk with ?url and normal import as pure css chunk', () => {
6770
expect(findAssetFile(/chunk-.*\.js$/)).toBeTruthy()

playground/glob-import/__tests__/glob-import.spec.ts

Lines changed: 34 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -88,12 +88,14 @@ const baseRawResult = {
8888
}
8989

9090
test('should work', async () => {
91-
await expect
92-
.poll(async () => JSON.parse(await page.textContent('.result')))
93-
.toStrictEqual(allResult)
94-
await expect
95-
.poll(async () => JSON.parse(await page.textContent('.result-eager')))
96-
.toStrictEqual(allResult)
91+
if (!process.env._VITE_TEST_NATIVE_PLUGIN) {
92+
await expect
93+
.poll(async () => JSON.parse(await page.textContent('.result')))
94+
.toStrictEqual(allResult)
95+
await expect
96+
.poll(async () => JSON.parse(await page.textContent('.result-eager')))
97+
.toStrictEqual(allResult)
98+
}
9799
await expect
98100
.poll(async () =>
99101
JSON.parse(await page.textContent('.result-node_modules')),
@@ -223,29 +225,32 @@ test('tree-shake eager css', async () => {
223225
}
224226
})
225227

226-
test('escapes special chars in globs without mangling user supplied glob suffix', async () => {
227-
// the escape dir contains subdirectories where each has a name that needs escaping for glob safety
228-
// inside each of them is a glob.js that exports the result of a relative glob `./**/*.js`
229-
// and an alias glob `@escape_<dirname>_mod/**/*.js`. The matching aliases are generated in vite.config.ts
230-
// index.html has a script that loads all these glob.js files and prints the globs that returned the expected result
231-
// this test finally compares the printed output of index.js with the list of directories with special chars,
232-
// expecting that they all work
233-
const files = await readdir(path.join(__dirname, '..', 'escape'), {
234-
withFileTypes: true,
235-
})
236-
const expectedNames = files
237-
.filter((f) => f.isDirectory())
238-
.map((f) => `/escape/${f.name}/glob.js`)
239-
.sort()
240-
const foundRelativeNames = (await page.textContent('.escape-relative'))
241-
.split('\n')
242-
.sort()
243-
expect(expectedNames).toEqual(foundRelativeNames)
244-
const foundAliasNames = (await page.textContent('.escape-alias'))
245-
.split('\n')
246-
.sort()
247-
expect(expectedNames).toEqual(foundAliasNames)
248-
})
228+
test.skipIf(!!process.env._VITE_TEST_NATIVE_PLUGIN)(
229+
'escapes special chars in globs without mangling user supplied glob suffix',
230+
async () => {
231+
// the escape dir contains subdirectories where each has a name that needs escaping for glob safety
232+
// inside each of them is a glob.js that exports the result of a relative glob `./**/*.js`
233+
// and an alias glob `@escape_<dirname>_mod/**/*.js`. The matching aliases are generated in vite.config.ts
234+
// index.html has a script that loads all these glob.js files and prints the globs that returned the expected result
235+
// this test finally compares the printed output of index.js with the list of directories with special chars,
236+
// expecting that they all work
237+
const files = await readdir(path.join(__dirname, '..', 'escape'), {
238+
withFileTypes: true,
239+
})
240+
const expectedNames = files
241+
.filter((f) => f.isDirectory())
242+
.map((f) => `/escape/${f.name}/glob.js`)
243+
.sort()
244+
const foundRelativeNames = (await page.textContent('.escape-relative'))
245+
.split('\n')
246+
.sort()
247+
expect(expectedNames).toEqual(foundRelativeNames)
248+
const foundAliasNames = (await page.textContent('.escape-alias'))
249+
.split('\n')
250+
.sort()
251+
expect(expectedNames).toEqual(foundAliasNames)
252+
},
253+
)
249254

250255
test('subpath imports', async () => {
251256
expect(await page.textContent('.subpath-imports')).toMatch('bar foo')

playground/js-sourcemap/__tests__/js-sourcemap.spec.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,10 @@ describe.runIf(isBuild)('build tests', () => {
139139
})
140140

141141
test('sourcemap is correct when preload information is injected', async () => {
142-
const map = findAssetFile(/after-preload-dynamic-[-\w]{8}\.js\.map/)
143-
expect(formatSourcemapForSnapshot(JSON.parse(map))).toMatchInlineSnapshot(`
142+
if (!process.env._VITE_TEST_NATIVE_PLUGIN) {
143+
const map = findAssetFile(/after-preload-dynamic-[-\w]{8}\.js\.map/)
144+
expect(formatSourcemapForSnapshot(JSON.parse(map)))
145+
.toMatchInlineSnapshot(`
144146
{
145147
"debugId": "00000000-0000-0000-0000-000000000000",
146148
"ignoreList": [],
@@ -157,6 +159,7 @@ describe.runIf(isBuild)('build tests', () => {
157159
"version": 3,
158160
}
159161
`)
162+
}
160163
// verify sourcemap comment is preserved at the last line
161164
const js = findAssetFile(/after-preload-dynamic-[-\w]{8}\.js$/)
162165
expect(js).toMatch(

playground/minify/vite.config.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,10 @@ export default defineConfig({
88
build: {
99
minify: 'esbuild',
1010
cssMinify: 'esbuild',
11+
rollupOptions: {
12+
output: {
13+
legalComments: 'none',
14+
},
15+
},
1116
},
1217
})

playground/tsconfig-json-load-error/__tests__/tsconfig-json-load-error.spec.ts

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,27 @@ import { browserLogs, editFile, isBuild, isServe, page, readFile } from '~utils'
55
const unexpectedTokenSyntaxErrorRE =
66
/(\[vite:esbuild\] )*parsing .* failed: SyntaxError: Unexpected token.*\}.*|Build failed/
77

8-
describe.runIf(isBuild)('build', () => {
9-
test('should throw an error on build', () => {
10-
expect(serveError).toBeTruthy()
11-
expect(serveError.message).toMatch(unexpectedTokenSyntaxErrorRE)
12-
clearServeError() // got expected error, null it here so testsuite does not fail from rethrow in afterAll
13-
})
8+
describe.runIf(isBuild && !process.env._VITE_TEST_NATIVE_PLUGIN)(
9+
'build',
10+
() => {
11+
test('should throw an error on build', () => {
12+
expect(serveError).toBeTruthy()
13+
expect(serveError.message).toMatch(unexpectedTokenSyntaxErrorRE)
14+
clearServeError() // got expected error, null it here so testsuite does not fail from rethrow in afterAll
15+
})
1416

15-
test('should not output files to dist', () => {
16-
let err
17-
try {
18-
readFile('dist/index.html')
19-
} catch (e) {
20-
err = e
21-
}
22-
expect(err).toBeTruthy()
23-
expect(err.code).toBe('ENOENT')
24-
})
25-
})
17+
test('should not output files to dist', () => {
18+
let err
19+
try {
20+
readFile('dist/index.html')
21+
} catch (e) {
22+
err = e
23+
}
24+
expect(err).toBeTruthy()
25+
expect(err.code).toBe('ENOENT')
26+
})
27+
},
28+
)
2629

2730
describe.runIf(isServe)('server', () => {
2831
test('should log 500 error in browser for malformed tsconfig', () => {

playground/worker/__tests__/iife/worker-iife.spec.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -151,11 +151,14 @@ test('url query worker', async () => {
151151
.toMatch('Hello from simple worker!')
152152
})
153153

154-
test('import.meta.glob eager in worker', async () => {
155-
await expect
156-
.poll(() => page.textContent('.importMetaGlobEager-worker'))
157-
.toMatch('["')
158-
})
154+
test.skipIf(!!process.env._VITE_TEST_NATIVE_PLUGIN)(
155+
'import.meta.glob eager in worker',
156+
async () => {
157+
await expect
158+
.poll(() => page.textContent('.importMetaGlobEager-worker'))
159+
.toMatch('["')
160+
},
161+
)
159162

160163
test('self reference worker', async () => {
161164
await expect

0 commit comments

Comments
 (0)