Skip to content

Commit c833bed

Browse files
committed
test: test build with DLL
1 parent 8dff383 commit c833bed

File tree

1 file changed

+62
-0
lines changed

1 file changed

+62
-0
lines changed
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
jest.setTimeout(30000)
2+
3+
const path = require('path')
4+
const portfinder = require('portfinder')
5+
const { createServer } = require('http-server')
6+
const { defaults } = require('@vue/cli/lib/options')
7+
const create = require('@vue/cli-test-utils/createTestProject')
8+
const launchPuppeteer = require('@vue/cli-test-utils/launchPuppeteer')
9+
10+
let server, browser, page
11+
test('build with DLL', async () => {
12+
const project = await create('e2e-build-dll', Object.assign({}, defaults, {
13+
router: true,
14+
vuex: true
15+
}))
16+
17+
// enable DLL
18+
await project.write('vue.config.js', 'module.exports = { dll: true }')
19+
20+
const { stdout } = await project.run('vue-cli-service build')
21+
expect(stdout).toMatch('Build complete.')
22+
23+
expect(project.has('dist/index.html')).toBe(true)
24+
expect(project.has('dist/favicon.ico')).toBe(true)
25+
expect(project.has('dist/js')).toBe(true)
26+
expect(project.has('dist/css')).toBe(true)
27+
28+
const index = await project.read('dist/index.html')
29+
// should preload app.js & vendor.js
30+
expect(index).toMatch(/<link rel=preload [^>]+app[^>]+\.js>/)
31+
expect(index).toMatch(/<link rel=preload [^>]+vendor[^>]+\.js>/)
32+
33+
const vendorFile = index.match(/<link rel=preload [^>]+(vendor[^>]+\.js)>/)[1]
34+
const vendor = await project.read(`dist/js/${vendorFile}`)
35+
expect(vendor).toMatch(`router-link`)
36+
expect(vendor).toMatch(`vuex`)
37+
38+
const port = await portfinder.getPortPromise()
39+
server = createServer({ root: path.join(project.dir, 'dist') })
40+
41+
await new Promise((resolve, reject) => {
42+
server.listen(port, err => {
43+
if (err) return reject(err)
44+
resolve()
45+
})
46+
})
47+
48+
const launched = await launchPuppeteer(`http://localhost:${port}/`)
49+
browser = launched.browser
50+
page = launched.page
51+
52+
const h1Text = await page.evaluate(() => {
53+
return document.querySelector('h1').textContent
54+
})
55+
56+
expect(h1Text).toMatch('Welcome to Your Vue.js App')
57+
})
58+
59+
afterAll(async () => {
60+
await browser.close()
61+
server.close()
62+
})

0 commit comments

Comments
 (0)