-
-
Notifications
You must be signed in to change notification settings - Fork 6.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
62 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
jest.setTimeout(30000) | ||
|
||
const path = require('path') | ||
const portfinder = require('portfinder') | ||
const { createServer } = require('http-server') | ||
const { defaults } = require('@vue/cli/lib/options') | ||
const create = require('@vue/cli-test-utils/createTestProject') | ||
const launchPuppeteer = require('@vue/cli-test-utils/launchPuppeteer') | ||
|
||
let server, browser, page | ||
test('build with DLL', async () => { | ||
const project = await create('e2e-build-dll', Object.assign({}, defaults, { | ||
router: true, | ||
vuex: true | ||
})) | ||
|
||
// enable DLL | ||
await project.write('vue.config.js', 'module.exports = { dll: true }') | ||
|
||
const { stdout } = await project.run('vue-cli-service build') | ||
expect(stdout).toMatch('Build complete.') | ||
|
||
expect(project.has('dist/index.html')).toBe(true) | ||
expect(project.has('dist/favicon.ico')).toBe(true) | ||
expect(project.has('dist/js')).toBe(true) | ||
expect(project.has('dist/css')).toBe(true) | ||
|
||
const index = await project.read('dist/index.html') | ||
// should preload app.js & vendor.js | ||
expect(index).toMatch(/<link rel=preload [^>]+app[^>]+\.js>/) | ||
expect(index).toMatch(/<link rel=preload [^>]+vendor[^>]+\.js>/) | ||
|
||
const vendorFile = index.match(/<link rel=preload [^>]+(vendor[^>]+\.js)>/)[1] | ||
const vendor = await project.read(`dist/js/${vendorFile}`) | ||
expect(vendor).toMatch(`router-link`) | ||
expect(vendor).toMatch(`vuex`) | ||
|
||
const port = await portfinder.getPortPromise() | ||
server = createServer({ root: path.join(project.dir, 'dist') }) | ||
|
||
await new Promise((resolve, reject) => { | ||
server.listen(port, err => { | ||
if (err) return reject(err) | ||
resolve() | ||
}) | ||
}) | ||
|
||
const launched = await launchPuppeteer(`http://localhost:${port}/`) | ||
browser = launched.browser | ||
page = launched.page | ||
|
||
const h1Text = await page.evaluate(() => { | ||
return document.querySelector('h1').textContent | ||
}) | ||
|
||
expect(h1Text).toMatch('Welcome to Your Vue.js App') | ||
}) | ||
|
||
afterAll(async () => { | ||
await browser.close() | ||
server.close() | ||
}) |