Skip to content

Commit 1016c85

Browse files
committed
test: fix multiPage test case
1 parent d8eaae0 commit 1016c85

File tree

1 file changed

+35
-31
lines changed

1 file changed

+35
-31
lines changed

packages/@vue/cli-service/__tests__/multiPage.spec.js

Lines changed: 35 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -81,59 +81,59 @@ test('build w/ multi page', async () => {
8181

8282
const assertSharedAssets = file => {
8383
// should split and preload vendor chunk
84-
expect(file).toMatch(/<link [^>]+js\/chunk-vendors[^>]+\.js rel=preload>/)
84+
expect(file).toMatch(/<link [^>]*js\/chunk-vendors[^>]*\.js rel=preload>/)
8585
// should split and preload common js and css
86-
expect(file).toMatch(/<link [^>]+js\/chunk-common[^>]+\.js rel=preload>/)
87-
expect(file).toMatch(/<link [^>]+chunk-common[^>]+\.css rel=preload>/)
86+
expect(file).toMatch(/<link [^>]*js\/chunk-common[^>]*\.js rel=preload>/)
87+
expect(file).toMatch(/<link [^>]*chunk-common[^>]*\.css rel=preload>/)
8888
// should load common css
8989
expect(file).toMatch(/<link href=\/css\/chunk-common\.\w+\.css rel=stylesheet>/)
9090
// should load common js
91-
expect(file).toMatch(/<script [^>]+src=\/js\/chunk-vendors\.\w+\.js>/)
92-
expect(file).toMatch(/<script [^>]+src=\/js\/chunk-common\.\w+\.js>/)
91+
expect(file).toMatch(/<script [^>]*src=\/js\/chunk-vendors\.\w+\.js>/)
92+
expect(file).toMatch(/<script [^>]*src=\/js\/chunk-common\.\w+\.js>/)
9393
}
9494

9595
const index = await project.read('dist/index.html')
9696
assertSharedAssets(index)
9797
// should preload correct page file
98-
expect(index).toMatch(/<link [^>]+js\/index[^>]+\.js rel=preload>/)
99-
expect(index).not.toMatch(/<link [^>]+js\/foo[^>]+\.js rel=preload>/)
100-
expect(index).not.toMatch(/<link [^>]+js\/bar[^>]+\.js rel=preload>/)
98+
expect(index).toMatch(/<link [^>]*js\/index[^>]*\.js rel=preload>/)
99+
expect(index).not.toMatch(/<link [^>]*js\/foo[^>]*\.js rel=preload>/)
100+
expect(index).not.toMatch(/<link [^>]*js\/bar[^>]*\.js rel=preload>/)
101101
// should prefetch async chunk js and css
102-
expect(index).toMatch(/<link [^>]+css\/0\.\w+\.css rel=prefetch>/)
103-
expect(index).toMatch(/<link [^>]+js\/0\.\w+\.js rel=prefetch>/)
102+
expect(index).toMatch(/<link [^>]*css\/0\.\w+\.css rel=prefetch>/)
103+
expect(index).toMatch(/<link [^>]*js\/0\.\w+\.js rel=prefetch>/)
104104
// should load correct page js
105-
expect(index).toMatch(/<script [^>]+src=\/js\/index\.\w+\.js>/)
106-
expect(index).not.toMatch(/<script [^>]+src=\/js\/foo\.\w+\.js>/)
107-
expect(index).not.toMatch(/<script [^>]+src=\/js\/bar\.\w+\.js>/)
105+
expect(index).toMatch(/<script [^>]*src=\/js\/index\.\w+\.js>/)
106+
expect(index).not.toMatch(/<script [^>]*src=\/js\/foo\.\w+\.js>/)
107+
expect(index).not.toMatch(/<script [^>]*src=\/js\/bar\.\w+\.js>/)
108108

109109
const foo = await project.read('dist/foo.html')
110110
assertSharedAssets(foo)
111111
// should preload correct page file
112-
expect(foo).not.toMatch(/<link [^>]+js\/index[^>]+\.js rel=preload>/)
113-
expect(foo).toMatch(/<link [^>]+js\/foo[^>]+\.js rel=preload>/)
114-
expect(foo).not.toMatch(/<link [^>]+js\/bar[^>]+\.js rel=preload>/)
112+
expect(foo).not.toMatch(/<link [^>]*js\/index[^>]*\.js rel=preload>/)
113+
expect(foo).toMatch(/<link [^>]*js\/foo[^>]*\.js rel=preload>/)
114+
expect(foo).not.toMatch(/<link [^>]*js\/bar[^>]*\.js rel=preload>/)
115115
// should not prefetch async chunk js and css because it's not used by
116116
// this entry
117-
expect(foo).not.toMatch(/<link [^>]+css\/0\.\w+\.css rel=prefetch>/)
118-
expect(foo).not.toMatch(/<link [^>]+js\/0\.\w+\.js rel=prefetch>/)
117+
expect(foo).not.toMatch(/<link [^>]*css\/0\.\w+\.css rel=prefetch>/)
118+
expect(foo).not.toMatch(/<link [^>]*js\/0\.\w+\.js rel=prefetch>/)
119119
// should load correct page js
120-
expect(foo).not.toMatch(/<script [^>]+src=\/js\/index\.\w+\.js>/)
121-
expect(foo).toMatch(/<script [^>]+src=\/js\/foo\.\w+\.js>/)
122-
expect(foo).not.toMatch(/<script [^>]+src=\/js\/bar\.\w+\.js>/)
120+
expect(foo).not.toMatch(/<script [^>]*src=\/js\/index\.\w+\.js>/)
121+
expect(foo).toMatch(/<script [^>]*src=\/js\/foo\.\w+\.js>/)
122+
expect(foo).not.toMatch(/<script [^>]*src=\/js\/bar\.\w+\.js>/)
123123

124124
const bar = await project.read('dist/bar.html')
125125
assertSharedAssets(bar)
126126
// should preload correct page file
127-
expect(bar).not.toMatch(/<link [^>]+js\/index[^>]+\.js rel=preload>/)
128-
expect(bar).not.toMatch(/<link [^>]+js\/foo[^>]+\.js rel=preload>/)
129-
expect(bar).toMatch(/<link [^>]+js\/bar[^>]+\.js rel=preload>/)
127+
expect(bar).not.toMatch(/<link [^>]*js\/index[^>]*\.js rel=preload>/)
128+
expect(bar).not.toMatch(/<link [^>]*js\/foo[^>]*\.js rel=preload>/)
129+
expect(bar).toMatch(/<link [^>]*js\/bar[^>]*\.js rel=preload>/)
130130
// should prefetch async chunk js and css
131-
expect(bar).toMatch(/<link [^>]+css\/0\.\w+\.css rel=prefetch>/)
132-
expect(bar).toMatch(/<link [^>]+js\/0\.\w+\.js rel=prefetch>/)
131+
expect(bar).toMatch(/<link [^>]*css\/0\.\w+\.css rel=prefetch>/)
132+
expect(bar).toMatch(/<link [^>]*js\/0\.\w+\.js rel=prefetch>/)
133133
// should load correct page js
134-
expect(bar).not.toMatch(/<script [^>]+src=\/js\/index\.\w+\.js>/)
135-
expect(bar).not.toMatch(/<script [^>]+src=\/js\/foo\.\w+\.js>/)
136-
expect(bar).toMatch(/<script [^>]+src=\/js\/bar\.\w+\.js>/)
134+
expect(bar).not.toMatch(/<script [^>]*src=\/js\/index\.\w+\.js>/)
135+
expect(bar).not.toMatch(/<script [^>]*src=\/js\/foo\.\w+\.js>/)
136+
expect(bar).toMatch(/<script [^>]*src=\/js\/bar\.\w+\.js>/)
137137

138138
// assert pages work
139139
const port = await portfinder.getPortPromise()
@@ -165,6 +165,10 @@ test('build w/ multi page', async () => {
165165
})
166166

167167
afterAll(async () => {
168-
await browser.close()
169-
server.close()
168+
if (browser) {
169+
await browser.close()
170+
}
171+
if (server) {
172+
server.close()
173+
}
170174
})

0 commit comments

Comments
 (0)