forked from vitejs/vite
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbackend-integration.spec.ts
73 lines (64 loc) · 2.08 KB
/
backend-integration.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
import {
browserErrors,
browserLogs,
editFile,
getColor,
isBuild,
isServe,
page,
readManifest,
untilUpdated
} from '~utils'
const outerAssetMatch = isBuild
? /\/dev\/assets\/logo\.\w{8}\.png/
: /\/dev\/@fs\/.+?\/images\/logo\.png/
test('should have no 404s', () => {
browserLogs.forEach((msg) => {
expect(msg).not.toMatch('404')
})
})
describe('asset imports from js', () => {
test('file outside root', async () => {
expect(
await page.textContent('.asset-reference.outside-root .asset-url')
).toMatch(outerAssetMatch)
})
})
describe.runIf(isBuild)('build', () => {
test('manifest', async () => {
const manifest = readManifest('dev')
const htmlEntry = manifest['index.html']
const cssAssetEntry = manifest['global.css']
const imgAssetEntry = manifest['../images/logo.png']
expect(htmlEntry.css.length).toEqual(1)
expect(htmlEntry.assets.length).toEqual(1)
expect(cssAssetEntry?.file).not.toBeUndefined()
expect(imgAssetEntry?.file).not.toBeUndefined()
})
})
describe.runIf(isServe)('serve', () => {
test('No ReferenceError', async () => {
browserErrors.forEach((error) => {
expect(error.name).not.toBe('ReferenceError')
})
})
test('preserve the base in CSS HMR', async () => {
await untilUpdated(() => getColor('body'), 'black') // sanity check
editFile('frontend/entrypoints/global.css', (code) =>
code.replace('black', 'red')
)
await untilUpdated(() => getColor('body'), 'red') // successful HMR
// Verify that the base (/dev/) was added during the css-update
const link = await page.$('link[rel="stylesheet"]:last-of-type')
expect(await link.getAttribute('href')).toContain('/dev/global.css?t=')
})
test('CSS dependencies are tracked for HMR', async () => {
const el = await page.$('h1')
browserLogs.length = 0
editFile('frontend/entrypoints/main.ts', (code) =>
code.replace('text-black', 'text-[rgb(204,0,0)]')
)
await untilUpdated(() => getColor(el), 'rgb(204, 0, 0)')
expect(browserLogs).toContain('[vite] css hot updated: /global.css')
})
})