Skip to content

Commit

Permalink
test: test build with DLL
Browse files Browse the repository at this point in the history
  • Loading branch information
yyx990803 committed Jan 25, 2018
1 parent 8dff383 commit c833bed
Showing 1 changed file with 62 additions and 0 deletions.
62 changes: 62 additions & 0 deletions packages/@vue/cli-service/__tests__/buildDLL.spec.js
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()
})

0 comments on commit c833bed

Please sign in to comment.