Skip to content

Commit

Permalink
test: fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
yyx990803 committed Jun 13, 2018
1 parent 00d37d8 commit 5792ed8
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 20 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
jest.setTimeout(30000)

const fs = require('fs-extra')
const path = require('path')
const { defaultPreset } = require('@vue/cli/lib/options')
const create = require('@vue/cli-test-utils/createTestProject')

let project

async function readVendorFile () {
const files = await fs.readdir(path.join(project.dir, 'dist/js'))
const filename = files.find(f => /chunk-vendors\.[^.]+\.js$/.test(f))
return project.read(`dist/js/${filename}`)
}

beforeAll(async () => {
project = await create('babel-transpile-deps', defaultPreset)

Expand All @@ -31,7 +39,7 @@ beforeAll(async () => {

let $mainjs = await project.read('src/main.js')

$mainjs = `import test from 'external-dep'\n${$mainjs}\nconsole.log(test())`
$mainjs = `import test from 'external-dep'\n${$mainjs}\ntest()`

await project.write(
'src/main.js',
Expand All @@ -40,28 +48,15 @@ beforeAll(async () => {
})

test('dep from node_modules should not been transpiled', async () => {
const { stdout } = await project.run('vue-cli-service build')

let $vendorjs = stdout.match(/(js\/chunk-vendors\.[^.]+\.js)/)[1]

$vendorjs = `dist/${$vendorjs}`
$vendorjs = await project.read($vendorjs)

expect($vendorjs).toMatch('() => "__TEST__"')
await project.run('vue-cli-service build')
expect(await readVendorFile()).toMatch('() => "__TEST__"')
})

test('dep from node_modules should been transpiled', async () => {
await project.write(
'vue.config.js',
`module.exports = { transpileDependencies: ['external-dep'] }`
)

const { stdout } = await project.run('vue-cli-service build')

let $vendorjs = stdout.match(/(js\/chunk-vendors\.[^.]+\.js)/)[1]

$vendorjs = `dist/${$vendorjs}`
$vendorjs = await project.read($vendorjs)

expect($vendorjs).toMatch('return "__TEST__"')
await project.run('vue-cli-service build')
expect(await readVendorFile()).toMatch('return "__TEST__"')
})
2 changes: 1 addition & 1 deletion packages/@vue/cli-service/__tests__/multiPage.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ async function makeProjectMultiPage (project) {
chainWebpack: config => {
const splitOptions = config.optimization.get('splitChunks')
config.optimization.splitChunks(Object.assign({}, splitOptions, {
minSize: 10000
minSize: 100
}))
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/@vue/cli-service/lib/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ exports.defaults = () => ({
transpileDependencies: [/* string or regex */],

// sourceMap for production build?
productionSourceMap: true,
productionSourceMap: !process.env.VUE_CLI_TEST,

// use thread-loader for babel & TS in production build
// enabled by default if the machine has more than 1 cores
Expand Down

0 comments on commit 5792ed8

Please sign in to comment.