@@ -12,7 +12,8 @@ const getConfig = (base: string): InlineConfig => ({
12
12
base,
13
13
root : rootDir ,
14
14
logLevel : 'silent' ,
15
- preview : { port : ports [ 'css/dynamic-import' ] }
15
+ preview : { port : ports [ 'css/dynamic-import' ] } ,
16
+ build : { assetsInlineLimit : 0 }
16
17
} )
17
18
18
19
async function withBuild ( base : string , fn : ( ) => Promise < void > ) {
@@ -42,14 +43,17 @@ async function withServe(base: string, fn: () => Promise<void>) {
42
43
}
43
44
}
44
45
45
- async function getChunks ( ) {
46
+ async function getLinks ( ) {
46
47
const links = await page . $$ ( 'link' )
47
- const hrefs = await Promise . all ( links . map ( ( l ) => l . evaluate ( ( el ) => el . href ) ) )
48
- return hrefs . map ( ( href ) => {
49
- // drop hash part from the file name
50
- const [ _ , name , ext ] = href . match ( / a s s e t s \/ ( [ a - z ] + ) \. .* ?\. ( .* ) $ / )
51
- return `${ name } .${ ext } `
52
- } )
48
+ return await Promise . all (
49
+ links . map ( ( handle ) => {
50
+ return handle . evaluate ( ( link ) => ( {
51
+ pathname : new URL ( link . href ) . pathname ,
52
+ rel : link . rel ,
53
+ as : link . as
54
+ } ) )
55
+ } )
56
+ )
53
57
}
54
58
55
59
baseOptions . forEach ( ( { base, label } ) => {
@@ -60,12 +64,37 @@ baseOptions.forEach(({ base, label }) => {
60
64
await page . waitForSelector ( '.loaded' , { state : 'attached' } )
61
65
62
66
expect ( await getColor ( '.css-dynamic-import' ) ) . toBe ( 'green' )
63
- expect ( await getChunks ( ) ) . toEqual ( [
64
- 'index.css' ,
65
- 'dynamic.js' ,
66
- 'dynamic.css' ,
67
- 'static.js' ,
68
- 'index.js'
67
+ expect ( await getLinks ( ) ) . toEqual ( [
68
+ {
69
+ pathname : expect . stringMatching ( / ^ \/ a s s e t s \/ i n d e x \. .+ \. c s s $ / ) ,
70
+ rel : 'stylesheet' ,
71
+ as : ''
72
+ } ,
73
+ {
74
+ pathname : expect . stringMatching ( / ^ \/ a s s e t s \/ d y n a m i c \. .+ \. c s s $ / ) ,
75
+ rel : 'preload' ,
76
+ as : 'style'
77
+ } ,
78
+ {
79
+ pathname : expect . stringMatching ( / ^ \/ a s s e t s \/ d y n a m i c \. .+ \. j s $ / ) ,
80
+ rel : 'modulepreload' ,
81
+ as : 'script'
82
+ } ,
83
+ {
84
+ pathname : expect . stringMatching ( / ^ \/ a s s e t s \/ d y n a m i c \. .+ \. c s s $ / ) ,
85
+ rel : 'stylesheet' ,
86
+ as : ''
87
+ } ,
88
+ {
89
+ pathname : expect . stringMatching ( / ^ \/ a s s e t s \/ s t a t i c \. .+ \. j s $ / ) ,
90
+ rel : 'modulepreload' ,
91
+ as : 'script'
92
+ } ,
93
+ {
94
+ pathname : expect . stringMatching ( / ^ \/ a s s e t s \/ i n d e x \. .+ \. j s $ / ) ,
95
+ rel : 'modulepreload' ,
96
+ as : 'script'
97
+ }
69
98
] )
70
99
} )
71
100
}
@@ -79,7 +108,13 @@ baseOptions.forEach(({ base, label }) => {
79
108
80
109
expect ( await getColor ( '.css-dynamic-import' ) ) . toBe ( 'green' )
81
110
// in serve there is no preloading
82
- expect ( await getChunks ( ) ) . toEqual ( [ ] )
111
+ expect ( await getLinks ( ) ) . toEqual ( [
112
+ {
113
+ pathname : '/dynamic.css' ,
114
+ rel : 'preload' ,
115
+ as : 'style'
116
+ }
117
+ ] )
83
118
} )
84
119
}
85
120
)
0 commit comments