Skip to content

Commit

Permalink
feat: allow testing src code directly
Browse files Browse the repository at this point in the history
  • Loading branch information
dobromir-hristov committed Jan 7, 2020
1 parent e7b8d50 commit d45e248
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 8 deletions.
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -22,6 +22,7 @@
"test:compat": "scripts/test-compat.sh",
"test:unit": "npm run build:test && npm run test:unit:only",
"test:unit:only": "mocha-webpack --webpack-config test/setup/webpack.test.config.js test/specs --recursive --require test/setup/mocha.setup.js",
"test:unit:only:dev": "cross-env TARGET=dev yarn run test:unit:only",
"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",
"test:unit:karma": "npm run build:test && npm run test:unit:karma:only",
"test:unit:karma:only": "cross-env TARGET=browser karma start test/setup/karma.conf.js --single-run",
Expand Down
2 changes: 1 addition & 1 deletion packages/server-test-utils/src/config.js
@@ -1,3 +1,3 @@
import testUtils from '@vue/test-utils'
import * as testUtils from '@vue/test-utils'

export default testUtils.config
2 changes: 1 addition & 1 deletion packages/server-test-utils/src/index.js
Expand Up @@ -2,7 +2,7 @@ import renderToString from './renderToString'
import render from './render'
import config from './config'

export default {
export {
renderToString,
config,
render
Expand Down
2 changes: 1 addition & 1 deletion packages/test-utils/src/index.js
Expand Up @@ -16,7 +16,7 @@ function shallow(component, options) {
return shallowMount(component, options)
}

export default {
export {
createLocalVue,
createWrapper,
config,
Expand Down
27 changes: 22 additions & 5 deletions test/setup/webpack.test.config.js
Expand Up @@ -15,19 +15,36 @@ const rules = [].concat(
{
test: /\.js$/,
loader: 'babel-loader',
exclude: /node_modules\/(?!(shared|create-instance)\/).*/
exclude: /node_modules/
}
)

const externals = nodeExternals({
// we need to whitelist both `create-instance` and files in `shared` package. Otherwise Webpack wont bundle them in the test dev env
whitelist: ['create-instance', /^shared\/.*/]
})
// define the default aliases
let aliasedFiles = {
'~vue/server-test-utils': `@vue/server-test-utils`,
'~vue/test-utils': `@vue/test-utils`
}
if (process.env.TARGET === 'dev') {
// if we are in dev test mode, we want to alias all files to the src file, not dist
aliasedFiles = {
// we need both as some places import the old alias with ~, others directly test utils package.
'@vue/server-test-utils': `@vue/server-test-utils/src/index.js`,
'@vue/test-utils': `@vue/test-utils/src/index.js`,
'~vue/server-test-utils': `@vue/server-test-utils/src/index.js`,
'~vue/test-utils': `@vue/test-utils/src/index.js`
}
}
module.exports = {
module: {
rules
},
externals: !browser ? [nodeExternals()] : undefined,
externals: !browser ? [externals] : undefined,
resolve: {
alias: {
'~vue/server-test-utils': `${projectRoot}/packages/server-test-utils/dist/vue-server-test-utils.js`,
'~vue/test-utils': `${projectRoot}/packages/test-utils/dist/vue-test-utils.js`,
...aliasedFiles,
'~resources': `${projectRoot}/test/resources`
}
},
Expand Down

0 comments on commit d45e248

Please sign in to comment.