-
-
Notifications
You must be signed in to change notification settings - Fork 5.8k
/
assets.spec.ts
99 lines (82 loc) · 2.6 KB
/
assets.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
import fs from 'fs'
import path from 'path'
import {
findAssetFile,
getBg,
getColor,
isBuild,
testDir
} from '../../testUtils'
const assetMatch = isBuild
? /\/foo\/assets\/asset\.\w{8}\.png/
: '/nested/asset.png'
const iconMatch = isBuild ? `/foo/icon.png` : `icon.png`
test('should have no 404s', () => {
browserLogs.forEach((msg) => {
expect(msg).not.toMatch('404')
})
})
describe('raw references from /public', () => {
test('load raw js from /public', async () => {
expect(await page.textContent('.raw-js')).toMatch('[success]')
})
test('load raw css from /public', async () => {
expect(await getColor('.raw-css')).toBe('red')
})
})
describe('asset imports from js', () => {
test('relative', async () => {
expect(await page.textContent('.asset-import-relative')).toMatch(assetMatch)
})
test('absolute', async () => {
expect(await page.textContent('.asset-import-absolute')).toMatch(assetMatch)
})
test('from /public', async () => {
expect(await page.textContent('.public-import')).toMatch(iconMatch)
})
})
describe('css url() references', () => {
test('fonts', async () => {
expect(
await page.evaluate(() => {
return (document as any).fonts.check('700 32px Inter')
})
).toBe(true)
})
test('relative', async () => {
expect(await getBg('.css-url-relative')).toMatch(assetMatch)
})
test('absolute', async () => {
expect(await getBg('.css-url-absolute')).toMatch(assetMatch)
})
test('from /public', async () => {
expect(await getBg('.css-url-public')).toMatch(iconMatch)
})
test('base64 inline', async () => {
const match = isBuild ? `data:image/png;base64` : `/icon.png`
expect(await getBg('.css-url-base64-inline')).toMatch(match)
expect(await getBg('.css-url-quotes-base64-inline')).toMatch(match)
})
if (isBuild) {
test('preserve postfix query/hash', () => {
expect(findAssetFile(/\.css$/, 'foo')).toMatch(`woff2?#iefix`)
})
}
})
describe('svg fragments', () => {
// 404 is checked already, so here we just ensure the urls end with #fragment
test('img url', async () => {
const img = await page.$('.svg-frag-img')
expect(await img.getAttribute('src')).toMatch(/svg#icon-clock-view$/)
})
test('via css url()', async () => {
const bg = await page.evaluate(() => {
return getComputedStyle(document.querySelector('.icon')).backgroundImage
})
expect(bg).toMatch(/svg#icon-clock-view"\)$/)
})
test('from js import', async () => {
const img = await page.$('.svg-frag-import')
expect(await img.getAttribute('src')).toMatch(/svg#icon-heart-view$/)
})
})