From 5792ed89fba54713c65d85272c77463f7b31673b Mon Sep 17 00:00:00 2001 From: Evan You Date: Wed, 13 Jun 2018 14:22:35 -0400 Subject: [PATCH] test: fix tests --- .../__tests__/transpileDependencies.spec.js | 31 ++++++++----------- .../cli-service/__tests__/multiPage.spec.js | 2 +- packages/@vue/cli-service/lib/options.js | 2 +- 3 files changed, 15 insertions(+), 20 deletions(-) diff --git a/packages/@vue/cli-plugin-babel/__tests__/transpileDependencies.spec.js b/packages/@vue/cli-plugin-babel/__tests__/transpileDependencies.spec.js index 9340da3873..0edccfe948 100644 --- a/packages/@vue/cli-plugin-babel/__tests__/transpileDependencies.spec.js +++ b/packages/@vue/cli-plugin-babel/__tests__/transpileDependencies.spec.js @@ -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) @@ -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', @@ -40,14 +48,8 @@ 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 () => { @@ -55,13 +57,6 @@ test('dep from node_modules should been transpiled', async () => { '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__"') }) diff --git a/packages/@vue/cli-service/__tests__/multiPage.spec.js b/packages/@vue/cli-service/__tests__/multiPage.spec.js index 4e48770d81..ac6172c642 100644 --- a/packages/@vue/cli-service/__tests__/multiPage.spec.js +++ b/packages/@vue/cli-service/__tests__/multiPage.spec.js @@ -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 })) } } diff --git a/packages/@vue/cli-service/lib/options.js b/packages/@vue/cli-service/lib/options.js index 2aef44840e..08bfd4e242 100644 --- a/packages/@vue/cli-service/lib/options.js +++ b/packages/@vue/cli-service/lib/options.js @@ -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