Skip to content

Commit 5d892bb

Browse files
authored
Merge pull request #1396 from vuejs/feat/allow-testing-src-directly
Allow testing src directly
2 parents cff91c9 + 13e04b8 commit 5d892bb

40 files changed

+568
-481
lines changed

Diff for: .github/CONTRIBUTING.md

+3
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@ $ yarn test:unit
5959

6060
# run the full test suite, include linting / type checking
6161
$ yarn test
62+
63+
# run tests against src files only. Allows inline debugging.
64+
$ yarn test:unit:only:dev
6265
```
6366

6467
There are some other scripts available in the `scripts` section of the `package.json` file.

Diff for: package.json

+9-7
Original file line numberDiff line numberDiff line change
@@ -15,24 +15,26 @@
1515
"flow": "flow check",
1616
"lint": "eslint --ext js,vue . --ignore-path .gitignore",
1717
"lint:docs": "eslint --ext js,vue,md docs --ignore-path .gitignore",
18-
"lint:fix": "npm run lint -- --fix",
18+
"lint:fix": "yarn lint -- --fix",
1919
"format": "prettier --write \"**/*.{js,json,vue,md}\"",
2020
"format:check": "prettier --check \"**/*.{js,json,vue,md}\"",
21-
"release": "npm run build && npm run test:unit:only && lerna publish --conventional-commits -m \"chore(release): publish %s\" --cd-version prerelease",
22-
"test": "npm run format:check && npm run lint && npm run lint:docs && npm run flow && npm run test:types && npm run test:unit && npm run test:unit:karma && npm run test:unit:node",
21+
"release": "yarn build && yarn test:unit:only && lerna publish --conventional-commits -m \"chore(release): publish %s\" --cd-version prerelease",
22+
"test": "yarn format:check && yarn lint && yarn lint:docs && yarn flow && yarn test:types && yarn test:unit && yarn test:unit:karma && yarn test:unit:node",
2323
"test:compat": "scripts/test-compat.sh",
24-
"test:unit": "npm run build:test && npm run test:unit:only",
24+
"test:unit": "yarn build:test && yarn test:unit:only",
2525
"test:unit:only": "mocha-webpack --webpack-config test/setup/webpack.test.config.js test/specs --recursive --require test/setup/mocha.setup.js",
26-
"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",
27-
"test:unit:karma": "npm run build:test && npm run test:unit:karma:only",
26+
"test:unit:only:dev": "cross-env TARGET=dev yarn test:unit:only",
27+
"test:unit:debug": "yarn 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",
28+
"test:unit:karma": "yarn build:test && yarn test:unit:karma:only",
2829
"test:unit:karma:only": "cross-env TARGET=browser karma start test/setup/karma.conf.js --single-run",
29-
"test:unit:node": "npm run build:test && npm run test:unit:node:only",
30+
"test:unit:node": "yarn build:test && yarn test:unit:node:only",
3031
"test:unit:node:only": "cross-env TEST_ENV=node mocha-webpack --webpack-config test/setup/webpack.test.config.js test/specs/render.spec.js test/specs/renderToString.spec.js --require test/setup/mocha.setup.js",
3132
"test:types": "tsc -p packages/test-utils/types && tsc -p packages/server-test-utils/types"
3233
},
3334
"dependencies": {
3435
"babel-core": "^6.26.0",
3536
"babel-eslint": "^8.2.2",
37+
"babel-helper-vue-jsx-merge-props": "^2.0.3",
3638
"babel-loader": "^7.1.3",
3739
"babel-plugin-syntax-jsx": "^6.18.0",
3840
"babel-plugin-transform-decorators-legacy": "^1.3.4",

Diff for: packages/server-test-utils/src/config.js

+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

Diff for: packages/server-test-utils/src/index.js

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

5-
export default {
6-
renderToString,
7-
config,
8-
render
9-
}
5+
export { renderToString, config, render }

Diff for: 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,

Diff for: test/resources/utils.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
/* global describe */
22

33
import Vue from 'vue'
4-
import { shallowMount, mount } from '~vue/test-utils'
5-
import { renderToString } from '~vue/server-test-utils'
4+
import { shallowMount, mount } from '@vue/test-utils'
5+
import { renderToString } from '@vue/server-test-utils'
66

77
export const vueVersion = Number(
88
`${Vue.version.split('.')[0]}.${Vue.version.split('.')[1]}`

Diff for: test/setup/webpack.test.config.js

+21-5
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,35 @@ 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 won't bundle them in the test dev env
23+
whitelist: [
24+
'@vue/test-utils',
25+
'@vue/server-test-utils',
26+
'create-instance',
27+
/^shared\/.*/
28+
]
29+
})
30+
// define the default aliases
31+
let aliasedFiles = {}
32+
if (process.env.TARGET === 'dev') {
33+
// if we are in dev test mode, we want to alias all files to the src file, not dist
34+
aliasedFiles = {
35+
'@vue/server-test-utils': `@vue/server-test-utils/src/index.js`,
36+
'@vue/test-utils': `@vue/test-utils/src/index.js`
37+
}
38+
}
2239
module.exports = {
2340
module: {
2441
rules
2542
},
26-
externals: !browser ? [nodeExternals()] : undefined,
43+
externals: !browser ? [externals] : undefined,
2744
resolve: {
2845
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`,
46+
...aliasedFiles,
3147
'~resources': `${projectRoot}/test/resources`
3248
}
3349
},

Diff for: test/specs/components/RouterLink.spec.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { RouterLinkStub } from '~vue/test-utils'
1+
import { RouterLinkStub } from '@vue/test-utils'
22
import { describeWithShallowAndMount } from '~resources/utils'
33

44
describeWithShallowAndMount('RouterLinkStub', mountingMethod => {

Diff for: test/specs/config.spec.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { describeWithShallowAndMount } from '~resources/utils'
22
import ComponentWithProps from '~resources/components/component-with-props.vue'
3-
import { config, createLocalVue } from '~vue/test-utils'
3+
import { config, createLocalVue } from '@vue/test-utils'
44

55
describeWithShallowAndMount('config', mountingMethod => {
66
const sandbox = sinon.createSandbox()

Diff for: test/specs/create-local-vue.spec.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import Vue from 'vue'
22
import Vuex from 'vuex'
33
import VueRouter from 'vue-router'
4-
import { createLocalVue } from '~vue/test-utils'
4+
import { createLocalVue } from '@vue/test-utils'
55
import Component from '~resources/components/component.vue'
66
import ComponentWithVuex from '~resources/components/component-with-vuex.vue'
77
import ComponentWithRouter from '~resources/components/component-with-router.vue'

Diff for: test/specs/create-wrapper.spec.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import Vue from 'vue'
2-
import { createWrapper, Wrapper, WrapperArray } from '~vue/test-utils'
2+
import { createWrapper, Wrapper, WrapperArray } from '@vue/test-utils'
33
import Component from '~resources/components/component.vue'
44
import { describeRunIf } from 'conditional-specs'
55

Diff for: test/specs/external-libraries.spec.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { createLocalVue, mount } from '~vue/test-utils'
1+
import { createLocalVue, mount } from '@vue/test-utils'
22
import VeeValidate from 'vee-validate'
33
import { describeWithShallowAndMount } from '~resources/utils'
44

Diff for: test/specs/mount.spec.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import Vue from 'vue'
22
import { compileToFunctions } from 'vue-template-compiler'
3-
import { mount, createLocalVue } from '~vue/test-utils'
3+
import { mount, createLocalVue } from '@vue/test-utils'
44
import Component from '~resources/components/component.vue'
55
import ComponentWithProps from '~resources/components/component-with-props.vue'
66
import ComponentWithMixin from '~resources/components/component-with-mixin.vue'

Diff for: test/specs/mounting-options/localVue.spec.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import {
44
isRunningPhantomJS,
55
vueVersion
66
} from '~resources/utils'
7-
import { createLocalVue, shallowMount, mount } from '~vue/test-utils'
7+
import { createLocalVue, shallowMount, mount } from '@vue/test-utils'
88
import { itSkipIf, itRunIf, itDoNotRunIf } from 'conditional-specs'
99
import Vuex from 'vuex'
1010

Diff for: test/specs/mounting-options/methods.spec.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { config } from '~vue/test-utils'
1+
import { config } from '@vue/test-utils'
22
import { describeWithShallowAndMount } from '~resources/utils'
33

44
describeWithShallowAndMount('options.methods', mountingMethod => {

Diff for: test/specs/mounting-options/mocks.spec.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { createLocalVue, config } from '~vue/test-utils'
1+
import { createLocalVue, config } from '@vue/test-utils'
22
import Vue from 'vue'
33
import Component from '~resources/components/component.vue'
44
import ComponentWithVuex from '~resources/components/component-with-vuex.vue'

Diff for: test/specs/mounting-options/propsData.spec.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { shallowMount } from '~vue/test-utils'
1+
import { shallowMount } from '@vue/test-utils'
22
import ComponentWithProps from '~resources/components/component-with-props.vue'
33
import { describeRunIf } from 'conditional-specs'
44

Diff for: test/specs/mounting-options/provide.spec.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { config } from '~vue/test-utils'
2-
import { createLocalVue } from '~vue/test-utils'
1+
import { config } from '@vue/test-utils'
2+
import { createLocalVue } from '@vue/test-utils'
33
import ComponentWithInject from '~resources/components/component-with-inject.vue'
44
import CompositionComponentWithInject from '~resources/components/component-with-inject-composition.vue'
55
import { injectSupported } from '~resources/utils'

Diff for: test/specs/mounting-options/scopedSlots.spec.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { describeWithShallowAndMount, vueVersion } from '~resources/utils'
2-
import { createLocalVue } from '~vue/test-utils'
2+
import { createLocalVue } from '@vue/test-utils'
33
import ComponentWithScopedSlots from '~resources/components/component-with-scoped-slots.vue'
44
import { itDoNotRunIf } from 'conditional-specs'
55
import Vue from 'vue'

Diff for: test/specs/mounting-options/slots.spec.js

+9-12
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import ComponentAsAClass from '~resources/components/component-as-a-class.vue'
55
import ComponentWithParentName from '~resources/components/component-with-parent-name.vue'
66
import { describeWithShallowAndMount, vueVersion } from '~resources/utils'
77
import { itDoNotRunIf } from 'conditional-specs'
8-
import { mount, createLocalVue } from '~vue/test-utils'
8+
import { mount, createLocalVue } from '@vue/test-utils'
99

1010
describeWithShallowAndMount('options.slots', mountingMethod => {
1111
it('mounts component with default slot if passed component in slot object', () => {
@@ -138,10 +138,8 @@ describeWithShallowAndMount('options.slots', mountingMethod => {
138138
require.cache[
139139
require.resolve('vue-template-compiler')
140140
].exports.compileToFunctions = undefined
141-
delete require.cache[require.resolve('../../../packages/test-utils')]
142-
const mountingMethodFresh = require('../../../packages/test-utils')[
143-
mountingMethod.name
144-
]
141+
delete require.cache[require.resolve('@vue/test-utils')]
142+
const mountingMethodFresh = require('@vue/test-utils')[mountingMethod.name]
145143
const message =
146144
'[vue-test-utils]: vueTemplateCompiler is undefined, you must pass precompiled components if vue-template-compiler is undefined'
147145
const fn = () =>
@@ -391,13 +389,12 @@ describeWithShallowAndMount('options.slots', mountingMethod => {
391389
const compilerSave =
392390
require.cache[require.resolve('vue-template-compiler')].exports
393391
.compileToFunctions
394-
require.cache[require.resolve('vue-template-compiler')].exports = {
395-
compileToFunctions: undefined
396-
}
397-
delete require.cache[require.resolve('../../../packages/test-utils')]
398-
const mountingMethodFresh = require('../../../packages/test-utils')[
399-
mountingMethod.name
400-
]
392+
require.cache[
393+
require.resolve('vue-template-compiler')
394+
].exports.compileToFunctions = undefined
395+
396+
delete require.cache[require.resolve('@vue/test-utils')]
397+
const mountingMethodFresh = require('@vue/test-utils')[mountingMethod.name]
401398
const message =
402399
'[vue-test-utils]: vueTemplateCompiler is undefined, you must pass precompiled components if vue-template-compiler is undefined'
403400
const fn = () => {

Diff for: test/specs/mounting-options/stubs.spec.js

+5-7
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ import ComponentWithChild from '~resources/components/component-with-child.vue'
22
import ComponentWithNestedChildren from '~resources/components/component-with-nested-children.vue'
33
import Component from '~resources/components/component.vue'
44
import ComponentAsAClass from '~resources/components/component-as-a-class.vue'
5-
import { createLocalVue, config } from '~vue/test-utils'
6-
import { config as serverConfig } from '~vue/server-test-utils'
5+
import { createLocalVue, config } from '@vue/test-utils'
6+
import { config as serverConfig } from '@vue/server-test-utils'
77
import Vue from 'vue'
88
import { describeWithShallowAndMount, vueVersion } from '~resources/utils'
99
import { itDoNotRunIf, itSkipIf, itRunIf } from 'conditional-specs'
@@ -263,11 +263,9 @@ describeWithShallowAndMount('options.stub', mountingMethod => {
263263
require.cache[
264264
require.resolve('vue-template-compiler')
265265
].exports.compileToFunctions = undefined
266-
delete require.cache[require.resolve('../../../packages/test-utils')]
267-
delete require.cache[require.resolve('../../../packages/server-test-utils')]
268-
const mountingMethodFresh = require('../../../packages/test-utils')[
269-
mountingMethod.name
270-
]
266+
delete require.cache[require.resolve('@vue/test-utils')]
267+
delete require.cache[require.resolve('@vue/server-test-utils')]
268+
const mountingMethodFresh = require('@vue/test-utils')[mountingMethod.name]
271269
const message =
272270
'[vue-test-utils]: vueTemplateCompiler is undefined, you must pass precompiled components if vue-template-compiler is undefined'
273271
const fn = () =>

Diff for: test/specs/render.spec.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { render } from '~vue/server-test-utils'
1+
import { render } from '@vue/server-test-utils'
22
import Cheerio from 'cheerio'
33
import { describeDoNotRunIf } from 'conditional-specs'
44

Diff for: test/specs/renderToString.spec.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { renderToString } from '~vue/server-test-utils'
2-
import { createLocalVue } from '~vue/test-utils'
1+
import { renderToString } from '@vue/server-test-utils'
2+
import { createLocalVue } from '@vue/test-utils'
33
import ComponentWithChild from '~resources/components/component-with-child.vue'
44
import { describeDoNotRunIf } from 'conditional-specs'
55

Diff for: test/specs/shallow-mount.spec.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { compileToFunctions } from 'vue-template-compiler'
22
import Vue from 'vue'
3-
import { mount, shallowMount, createLocalVue } from '~vue/test-utils'
3+
import { mount, shallowMount, createLocalVue } from '@vue/test-utils'
44
import Component from '~resources/components/component.vue'
55
import ComponentWithChild from '~resources/components/component-with-child.vue'
66
import ComponentWithNestedChildren from '~resources/components/component-with-nested-children.vue'

Diff for: test/specs/wrapper-array.spec.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Wrapper, WrapperArray } from '~vue/test-utils'
1+
import { Wrapper, WrapperArray } from '@vue/test-utils'
22
import { describeWithShallowAndMount } from '~resources/utils'
33

44
describeWithShallowAndMount('WrapperArray', mountingMethod => {

Diff for: test/specs/wrapper-array/at.spec.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { describeWithShallowAndMount } from '~resources/utils'
2-
import '~vue/test-utils'
2+
import '@vue/test-utils'
33

44
describeWithShallowAndMount('at', mountingMethod => {
55
it('returns Wrapper at index', () => {

Diff for: test/specs/wrapper-array/attributes.spec.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { describeWithShallowAndMount } from '~resources/utils'
2-
import '~vue/test-utils'
2+
import '@vue/test-utils'
33

44
describeWithShallowAndMount('attributes', mountingMethod => {
55
it('throws error if wrapper array contains no items', () => {

Diff for: test/specs/wrapper-array/classes.spec.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { describeWithShallowAndMount } from '~resources/utils'
2-
import '~vue/test-utils'
2+
import '@vue/test-utils'
33

44
describeWithShallowAndMount('classes', mountingMethod => {
55
it('throws error if wrapper array contains no items', () => {

Diff for: test/specs/wrapper-array/contains.spec.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { describeWithShallowAndMount } from '~resources/utils'
2-
import '~vue/test-utils'
2+
import '@vue/test-utils'
33

44
describeWithShallowAndMount('contains', mountingMethod => {
55
it('returns true if every Wrapper contains element', () => {

Diff for: test/specs/wrapper-array/find.spec.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { describeWithShallowAndMount } from '~resources/utils'
2-
import '~vue/test-utils'
2+
import '@vue/test-utils'
33

44
describeWithShallowAndMount('find', mountingMethod => {
55
it('throws error if wrapper array contains no items', () => {

Diff for: test/specs/wrapper-array/findAll.spec.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { describeWithShallowAndMount } from '~resources/utils'
22
import { compileToFunctions } from 'vue-template-compiler'
3-
import '~vue/test-utils'
3+
import '@vue/test-utils'
44

55
describeWithShallowAndMount('findAll', mountingMethod => {
66
it('throws error if wrapper array contains no items', () => {

Diff for: test/specs/wrapper-array/html.spec.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { describeWithShallowAndMount } from '~resources/utils'
22
import { compileToFunctions } from 'vue-template-compiler'
3-
import '~vue/test-utils'
3+
import '@vue/test-utils'
44

55
describeWithShallowAndMount('html', mountingMethod => {
66
it('throws error if wrapper array contains no items', () => {

Diff for: test/specs/wrapper-array/isEmpty.spec.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { describeWithShallowAndMount } from '~resources/utils'
22
import { compileToFunctions } from 'vue-template-compiler'
3-
import '~vue/test-utils'
3+
import '@vue/test-utils'
44

55
describeWithShallowAndMount('isEmpty', mountingMethod => {
66
it('returns true if node is empty', () => {

Diff for: test/specs/wrapper-array/isVisible.spec.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { describeWithShallowAndMount } from '~resources/utils'
22
import { compileToFunctions } from 'vue-template-compiler'
3-
import '~vue/test-utils'
3+
import '@vue/test-utils'
44

55
describeWithShallowAndMount('isVisible', mountingMethod => {
66
it('returns true if node has no inline style', () => {

Diff for: test/specs/wrapper-array/name.spec.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { describeWithShallowAndMount } from '~resources/utils'
22
import { compileToFunctions } from 'vue-template-compiler'
3-
import '~vue/test-utils'
3+
import '@vue/test-utils'
44

55
describeWithShallowAndMount('name', mountingMethod => {
66
it('throws an error when called on a WrapperArray', () => {

Diff for: test/specs/wrapper-array/props.spec.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { describeWithShallowAndMount } from '~resources/utils'
22
import { compileToFunctions } from 'vue-template-compiler'
3-
import '~vue/test-utils'
3+
import '@vue/test-utils'
44

55
describeWithShallowAndMount('props', mountingMethod => {
66
it('throws error if wrapper array contains no items', () => {

Diff for: test/specs/wrapper-array/text.spec.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { describeWithShallowAndMount } from '~resources/utils'
22
import { compileToFunctions } from 'vue-template-compiler'
3-
import '~vue/test-utils'
3+
import '@vue/test-utils'
44

55
describeWithShallowAndMount('text', mountingMethod => {
66
it('throws error when called on a WrapperArray', () => {

Diff for: test/specs/wrapper/emitted.spec.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { createLocalVue, createWrapper } from '~vue/test-utils'
1+
import { createLocalVue, createWrapper } from '@vue/test-utils'
22
import { describeWithShallowAndMount, vueVersion } from '~resources/utils'
33
import { itDoNotRunIf } from 'conditional-specs'
44
import Vue from 'vue'

0 commit comments

Comments
 (0)