Skip to content

Commit d45e248

Browse files
committedJan 7, 2020
feat: allow testing src code directly
1 parent e7b8d50 commit d45e248

File tree

5 files changed

+26
-8
lines changed

5 files changed

+26
-8
lines changed
 

‎package.json

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
"test:compat": "scripts/test-compat.sh",
2323
"test:unit": "npm run build:test && npm run test:unit:only",
2424
"test:unit:only": "mocha-webpack --webpack-config test/setup/webpack.test.config.js test/specs --recursive --require test/setup/mocha.setup.js",
25+
"test:unit:only:dev": "cross-env TARGET=dev yarn run test:unit:only",
2526
"test:unit:debug": "npm run build:test && node --inspect-brk node_modules/.bin/mocha-webpack --webpack-config test/setup/webpack.test.config.js test/specs --recursive --require test/setup/mocha.setup.js",
2627
"test:unit:karma": "npm run build:test && npm run test:unit:karma:only",
2728
"test:unit:karma:only": "cross-env TARGET=browser karma start test/setup/karma.conf.js --single-run",
+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
import testUtils from '@vue/test-utils'
1+
import * as testUtils from '@vue/test-utils'
22

33
export default testUtils.config

‎packages/server-test-utils/src/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import renderToString from './renderToString'
22
import render from './render'
33
import config from './config'
44

5-
export default {
5+
export {
66
renderToString,
77
config,
88
render

‎packages/test-utils/src/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ function shallow(component, options) {
1616
return shallowMount(component, options)
1717
}
1818

19-
export default {
19+
export {
2020
createLocalVue,
2121
createWrapper,
2222
config,

‎test/setup/webpack.test.config.js

+22-5
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,36 @@ const rules = [].concat(
1515
{
1616
test: /\.js$/,
1717
loader: 'babel-loader',
18-
exclude: /node_modules\/(?!(shared|create-instance)\/).*/
18+
exclude: /node_modules/
1919
}
2020
)
21-
21+
const externals = nodeExternals({
22+
// we need to whitelist both `create-instance` and files in `shared` package. Otherwise Webpack wont bundle them in the test dev env
23+
whitelist: ['create-instance', /^shared\/.*/]
24+
})
25+
// define the default aliases
26+
let aliasedFiles = {
27+
'~vue/server-test-utils': `@vue/server-test-utils`,
28+
'~vue/test-utils': `@vue/test-utils`
29+
}
30+
if (process.env.TARGET === 'dev') {
31+
// if we are in dev test mode, we want to alias all files to the src file, not dist
32+
aliasedFiles = {
33+
// we need both as some places import the old alias with ~, others directly test utils package.
34+
'@vue/server-test-utils': `@vue/server-test-utils/src/index.js`,
35+
'@vue/test-utils': `@vue/test-utils/src/index.js`,
36+
'~vue/server-test-utils': `@vue/server-test-utils/src/index.js`,
37+
'~vue/test-utils': `@vue/test-utils/src/index.js`
38+
}
39+
}
2240
module.exports = {
2341
module: {
2442
rules
2543
},
26-
externals: !browser ? [nodeExternals()] : undefined,
44+
externals: !browser ? [externals] : undefined,
2745
resolve: {
2846
alias: {
29-
'~vue/server-test-utils': `${projectRoot}/packages/server-test-utils/dist/vue-server-test-utils.js`,
30-
'~vue/test-utils': `${projectRoot}/packages/test-utils/dist/vue-test-utils.js`,
47+
...aliasedFiles,
3148
'~resources': `${projectRoot}/test/resources`
3249
}
3350
},

0 commit comments

Comments
 (0)
Please sign in to comment.