Skip to content

Commit 92d935a

Browse files
Merge branch 'dev' into feat/allow-testing-src-directly
# Conflicts: # yarn.lock
2 parents f33308b + 9ac748b commit 92d935a

File tree

12 files changed

+282
-9
lines changed

12 files changed

+282
-9
lines changed

.github/COMMIT_CONVENTIONS.md

+91
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
## Git Commit Message Convention
2+
3+
> This is adapted from [Angular's commit convention](https://github.com/conventional-changelog/conventional-changelog/tree/master/packages/conventional-changelog-angular).
4+
5+
#### TL;DR:
6+
7+
Messages must be matched by the following regex:
8+
9+
```js
10+
;/^(revert: )?(feat|fix|polish|docs|style|refactor|perf|test|workflow|ci|chore|types)(\(.+\))?: .{1,50}/
11+
```
12+
13+
#### Examples
14+
15+
Appears under "Features" header, `Server Utils` subheader:
16+
17+
```
18+
feat(server-utils): add 'props' option
19+
```
20+
21+
Appears under "Bug Fixes" header, `Test Utils` subheader, with a link to issue #28:
22+
23+
```
24+
fix(test-utils): handle events on blur
25+
26+
close #28
27+
```
28+
29+
Appears under "Performance Improvements" header, and under "Breaking Changes" with the breaking change explanation:
30+
31+
```
32+
perf(test-utils): improve vdom diffing by removing 'foo' option
33+
34+
BREAKING CHANGE: The 'foo' option has been removed.
35+
```
36+
37+
The following commit and commit `667ecc1` do not appear in the changelog if they are under the same release. If not, the revert commit appears under the "Reverts" header.
38+
39+
```
40+
revert: feat(server-utils): add 'comments' option
41+
42+
This reverts commit 667ecc1654a317a13331b17617d973392f415f02.
43+
```
44+
45+
### Full Message Format
46+
47+
A commit message consists of a **header**, **body** and **footer**. The header has a **type**, **scope** and **subject**:
48+
49+
```
50+
<type>(<scope>): <subject>
51+
<BLANK LINE>
52+
<body>
53+
<BLANK LINE>
54+
<footer>
55+
```
56+
57+
The **header** is mandatory and the **scope** of the header is optional.
58+
59+
### Revert
60+
61+
If the commit reverts a previous commit, it should begin with `revert:`, followed by the header of the reverted commit. In the body, it should say: `This reverts commit <hash>.`, where the hash is the SHA of the commit being reverted.
62+
63+
### Type
64+
65+
If the prefix is `feat`, `fix` or `perf`, it will appear in the changelog. However, if there is any [BREAKING CHANGE](#footer), the commit will always appear in the changelog.
66+
67+
Other prefixes are up to your discretion. Suggested prefixes are `docs`, `chore`, `style`, `refactor`, and `test` for non-changelog related tasks.
68+
69+
### Scope
70+
71+
The scope could be anything specifying the place of the commit change. For example `core`, `compiler`, `ssr`, `v-model`, `transition` etc...
72+
73+
### Subject
74+
75+
The subject contains a succinct description of the change:
76+
77+
- use the imperative, present tense: "change" not "changed" nor "changes"
78+
- don't capitalize the first letter
79+
- no dot (.) at the end
80+
81+
### Body
82+
83+
Just as in the **subject**, use the imperative, present tense: "change" not "changed" nor "changes".
84+
The body should include the motivation for the change and contrast this with previous behavior.
85+
86+
### Footer
87+
88+
The footer should contain any information about **Breaking Changes** and is also the place to
89+
reference GitHub issues that this commit **Closes**.
90+
91+
**Breaking Changes** should start with the word `BREAKING CHANGE:` with a space or two newlines. The rest of the commit message is then used for this.

.github/CONTRIBUTING.md

+5
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ Hi! I’m really excited that you are interested in contributing to Vue Test Uti
55
- [Code of Conduct](https://github.com/vuejs/vue/blob/dev/.github/CODE_OF_CONDUCT.md)
66
- [Issue Reporting Guidelines](#issue-reporting-guidelines)
77
- [Pull Request Guidelines](#pull-request-guidelines)
8+
- [Committing Changes](#committing-changes)
89
- [Development Setup](#development-setup)
910
- [Project Structure](#project-structure)
1011

@@ -34,6 +35,10 @@ Hi! I’m really excited that you are interested in contributing to Vue Test Uti
3435
- Provide detailed description of the bug in the PR. Live demo preferred.
3536
- Add appropriate test coverage if applicable.
3637

38+
### Committing Changes
39+
40+
Commit messages should follow the [commit message convention](./COMMIT_CONVENTION.md) so that changelogs can be automatically generated. Commit messages will be automatically validated upon commit. If you are not familiar with the commit message convention, you can use `npm run commit` or `yarn commit` instead of `git commit`, which provides an interactive CLI for generating proper commit messages.
41+
3742
## Development Setup
3843

3944
You will need [Node.js](http://nodejs.org) **version 6+**

.nvmrc

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
v10

docs/guides/getting-started.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ cd vue-test-utils-getting-started
1010
npm install
1111
```
1212

13-
If you already have a project that was craeted with the [Vue CLI](https://cli.vuejs.org/) and want to add testing capabilities you may run:
13+
If you already have a project that was created with the [Vue CLI](https://cli.vuejs.org/) and want to add testing capabilities you may run:
1414

1515
```bash
1616
# unit testing

package.json

+32-5
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
"build": "lerna run build",
1010
"build:test": "lerna run build:test",
1111
"clean": "lerna clean --yes",
12+
"commit": "git-cz",
1213
"docs": "vuepress dev docs",
1314
"docs:build": "vuepress build docs",
1415
"flow": "flow check",
@@ -66,7 +67,6 @@
6667
"markdown-it-include": "^1.0.0",
6768
"mocha": "^5.2.0",
6869
"mocha-webpack": "^1.0.1",
69-
"prettier": "^1.16.0",
7070
"rollup": "1",
7171
"rollup-plugin-buble": "^0.19",
7272
"rollup-plugin-commonjs": "10",
@@ -78,19 +78,46 @@
7878
"sinon-chai": "^3.3.0",
7979
"typescript": "3",
8080
"vee-validate": "^2.1.3",
81-
"vue": "^2.5.22",
81+
"vue": "^2.6.11",
8282
"vue-class-component": "^6.1.2",
8383
"vue-loader": "^13.6.2",
8484
"vue-router": "^3.0.1",
85-
"vue-server-renderer": "^2.5.22",
86-
"vue-template-compiler": "^2.5.22",
85+
"vue-server-renderer": "^2.6.11",
86+
"vue-template-compiler": "^2.6.11",
8787
"vuepress": "^0.14.2",
8888
"vuepress-theme-vue": "^1.0.3",
8989
"vuex": "^3.0.1",
9090
"webpack": "^3.0.1",
9191
"webpack-node-externals": "^1.6.0"
9292
},
9393
"devDependencies": {
94-
"@vue/composition-api": "^0.3.2"
94+
"@commitlint/cli": "^8.2.0",
95+
"@commitlint/config-conventional": "^8.2.0",
96+
"@vue/composition-api": "^0.3.2",
97+
"commitizen": "^4.0.3",
98+
"cz-conventional-changelog": "^3.0.2",
99+
"husky": "^3.1.0",
100+
"lint-staged": "^9.5.0",
101+
"prettier": "^1.16.0"
102+
},
103+
"config": {
104+
"commitizen": {
105+
"path": "./node_modules/cz-conventional-changelog"
106+
}
107+
},
108+
"commitlint": {
109+
"extends": [
110+
"@commitlint/config-conventional"
111+
]
112+
},
113+
"husky": {
114+
"hooks": {
115+
"pre-commit": "lint-staged",
116+
"commit-msg": "commitlint -E HUSKY_GIT_PARAMS"
117+
}
118+
},
119+
"lint-staged": {
120+
"*.{js,json,vue,md}": ["prettier --write", "git add"],
121+
"*.{js,vue}": ["eslint --fix", "git add"]
95122
}
96123
}

packages/create-instance/create-component-stubs.js

+32-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
// @flow
22

33
import Vue from 'vue'
4-
import { throwError, camelize, capitalize, hyphenate } from '../shared/util'
4+
import {
5+
throwError,
6+
camelize,
7+
capitalize,
8+
hyphenate,
9+
keys
10+
} from '../shared/util'
511
import {
612
componentNeedsCompiling,
713
templateContainsComponent,
@@ -74,6 +80,25 @@ function resolveOptions(component, _Vue) {
7480
return options
7581
}
7682

83+
function getScopedSlotRenderFunctions(ctx: any): Array<string> {
84+
// In Vue 2.6+ a new v-slot syntax was introduced
85+
// scopedSlots are now saved in parent._vnode.data.scopedSlots
86+
// We filter out the _normalized and $stable key
87+
if (
88+
ctx &&
89+
ctx.$options &&
90+
ctx.$options.parent &&
91+
ctx.$options.parent._vnode &&
92+
ctx.$options.parent._vnode.data &&
93+
ctx.$options.parent._vnode.data.scopedSlots
94+
) {
95+
const slotKeys: Array<string> = ctx.$options.parent._vnode.data.scopedSlots
96+
return keys(slotKeys).filter(x => x !== '_normalized' && x !== '$stable')
97+
}
98+
99+
return []
100+
}
101+
77102
export function createStubFromComponent(
78103
originalComponent: Component,
79104
name: string,
@@ -109,7 +134,12 @@ export function createStubFromComponent(
109134
...this.$props
110135
}
111136
},
112-
context ? context.children : this.$options._renderChildren
137+
context
138+
? context.children
139+
: this.$options._renderChildren ||
140+
getScopedSlotRenderFunctions(this).map(x =>
141+
this.$options.parent._vnode.data.scopedSlots[x]()
142+
)
113143
)
114144
}
115145
}

packages/create-instance/create-instance.js

+14-1
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,21 @@ export default function createInstance(
7171
// used to identify extended component using constructor
7272
componentOptions.$_vueTestUtils_original = component
7373

74-
// make sure all extends are based on this instance
74+
// watchers provided in mounting options should override preexisting ones
75+
if (componentOptions.watch && instanceOptions.watch) {
76+
const componentWatchers = Object.keys(componentOptions.watch)
77+
const instanceWatchers = Object.keys(instanceOptions.watch)
78+
79+
for (let i = 0; i < instanceWatchers.length; i++) {
80+
const k = instanceWatchers[i]
81+
// override the componentOptions with the one provided in mounting options
82+
if (componentWatchers.includes(k)) {
83+
componentOptions.watch[k] = instanceOptions.watch[k]
84+
}
85+
}
86+
}
7587

88+
// make sure all extends are based on this instance
7689
const Constructor = _Vue.extend(componentOptions).extend(instanceOptions)
7790
componentOptions._Ctor = {}
7891
Constructor.options._base = _Vue

packages/shared/util.js

+4
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ function hasOwnProperty(obj, prop) {
3636
return Object.prototype.hasOwnProperty.call(obj, prop)
3737
}
3838

39+
export function keys<T: string>(obj: any): Array<T> {
40+
return Object.keys(obj)
41+
}
42+
3943
export function resolveComponent(id: string, components: Object) {
4044
if (typeof id !== 'string') {
4145
return
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<template>
2+
<ComponentWithVSlot>
3+
<template v-slot:newSyntax>
4+
<p class="new-example">new slot syntax</p>
5+
</template>
6+
</ComponentWithVSlot>
7+
</template>
8+
9+
<script>
10+
import ComponentWithVSlot from './component-with-v-slot.vue'
11+
12+
export default {
13+
name: 'ComponentWithVSlotSyntax',
14+
15+
components: { ComponentWithVSlot }
16+
}
17+
</script>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<template>
2+
<div>
3+
<slot name="newSyntax" />
4+
</div>
5+
</template>
6+
7+
<script>
8+
export default {
9+
name: 'ComponentWithVSlot'
10+
}
11+
</script>
+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import { describeWithShallowAndMount } from '~resources/utils'
2+
3+
describeWithShallowAndMount('options.watch', mountingMethod => {
4+
it('overrides a default watch handler', async () => {
5+
const TestComponent = {
6+
props: ['someProp'],
7+
template: '<div>{{ foo }}</div>',
8+
data() {
9+
return {
10+
foo: 'bar'
11+
}
12+
},
13+
watch: {
14+
someProp: {
15+
handler() {
16+
this.foo = 'updated-bar'
17+
}
18+
}
19+
}
20+
}
21+
const wrapper = mountingMethod(TestComponent, {
22+
watch: {
23+
someProp: {
24+
handler() {
25+
// do nothing
26+
}
27+
}
28+
}
29+
})
30+
31+
wrapper.setProps({ someProp: 'some-new-val' })
32+
await wrapper.vm.$nextTick()
33+
34+
expect(wrapper.text()).to.equal('bar')
35+
})
36+
})

test/specs/shallow-mount.spec.js

+38
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import ComponentWithNestedChildren from '~resources/components/component-with-ne
77
import ComponentWithLifecycleHooks from '~resources/components/component-with-lifecycle-hooks.vue'
88
import ComponentWithoutName from '~resources/components/component-without-name.vue'
99
import ComponentAsAClassWithChild from '~resources/components/component-as-a-class-with-child.vue'
10+
import ComponentWithVSlotSyntax from '~resources/components/component-with-v-slot-syntax.vue'
11+
import ComponentWithVSlot from '~resources/components/component-with-v-slot.vue'
1012
import RecursiveComponent from '~resources/components/recursive-component.vue'
1113
import { vueVersion } from '~resources/utils'
1214
import { describeRunIf, itDoNotRunIf } from 'conditional-specs'
@@ -96,6 +98,42 @@ describeRunIf(process.env.TEST_ENV !== 'node', 'shallowMount', () => {
9698
)
9799
})
98100

101+
it('renders SFC with named slots with v-slot syntax', () => {
102+
const wrapper = shallowMount(ComponentWithVSlotSyntax)
103+
104+
expect(wrapper.find(ComponentWithVSlot).exists()).to.equal(true)
105+
expect(wrapper.find('.new-example').exists()).to.equal(true)
106+
expect(wrapper.html()).to.equal(
107+
'<componentwithvslot-stub>\n' +
108+
' <p class="new-example">new slot syntax</p>\n' +
109+
'</componentwithvslot-stub>'
110+
)
111+
})
112+
113+
it('renders named slots with v-slot syntax', () => {
114+
const localVue = createLocalVue()
115+
localVue.component('Foo', {
116+
template: '<div><slot name="newSyntax" /></div>'
117+
})
118+
const TestComponent = {
119+
template: `
120+
<Foo>
121+
<template v-slot:newSyntax>
122+
<p class="new-example">text</p>
123+
</template>
124+
</Foo>
125+
`
126+
}
127+
const wrapper = shallowMount(TestComponent, {
128+
localVue
129+
})
130+
expect(wrapper.find({ name: 'Foo' }).exists()).to.equal(true)
131+
expect(wrapper.find('.new-example').exists()).to.equal(true)
132+
expect(wrapper.html()).to.equal(
133+
'<foo-stub>\n' + ' <p class="new-example">text</p>\n' + '</foo-stub>'
134+
)
135+
})
136+
99137
it('renders no children if none supplied', () => {
100138
const TestComponent = {
101139
template: '<child />',

0 commit comments

Comments
 (0)