From 6c296d59a01efe9a86b3e06fdc04fa887420ab99 Mon Sep 17 00:00:00 2001 From: eddyerburgh Date: Mon, 10 Dec 2018 20:46:18 +0000 Subject: [PATCH 01/10] fix: use Vue async option for sync mode --- flow/config.flow.js | 1 - package.json | 6 ++-- .../extract-instance-options.js | 1 - packages/server-test-utils/types/index.d.ts | 1 - .../types/test/renderToString.ts | 1 - packages/shared/consts.js | 3 ++ packages/shared/merge-options.js | 1 - packages/test-utils/src/mount.js | 32 ++++++++++++++++- packages/test-utils/src/vue-wrapper.js | 3 +- packages/test-utils/src/wrapper.js | 11 +++--- scripts/test-compat-all.sh | 2 +- test/specs/config.spec.js | 34 ++++--------------- test/specs/mounting-options/sync.spec.js | 31 +++++++++++++++-- test/specs/shallow-mount.spec.js | 4 +-- yarn.lock | 33 ++++++++++++++++-- 15 files changed, 114 insertions(+), 50 deletions(-) diff --git a/flow/config.flow.js b/flow/config.flow.js index c94e79325..90a422a1f 100644 --- a/flow/config.flow.js +++ b/flow/config.flow.js @@ -3,6 +3,5 @@ declare type Config = { mocks?: Object, methods?: { [name: string]: Function }, provide?: Object, - logModifiedComponents?: boolean, silent?: boolean }; diff --git a/package.json b/package.json index b4c34e494..5e1d68b04 100644 --- a/package.json +++ b/package.json @@ -65,12 +65,12 @@ "sinon-chai": "^2.10.0", "typescript": "^3.0.1", "vee-validate": "^2.1.3", - "vue": "2.5.16", + "vue": "2.5.20", "vue-class-component": "^6.1.2", "vue-loader": "^13.6.2", "vue-router": "^3.0.1", - "vue-server-renderer": "2.5.16", - "vue-template-compiler": "2.5.16", + "vue-server-renderer": "2.5.20", + "vue-template-compiler": "2.5.20", "vuepress": "^0.14.2", "vuepress-theme-vue": "^1.0.3", "vuex": "^3.0.1", diff --git a/packages/create-instance/extract-instance-options.js b/packages/create-instance/extract-instance-options.js index 5d7d3b5e5..6b0ee8005 100644 --- a/packages/create-instance/extract-instance-options.js +++ b/packages/create-instance/extract-instance-options.js @@ -11,7 +11,6 @@ const MOUNTING_OPTIONS = [ 'attrs', 'listeners', 'propsData', - 'logModifiedComponents', 'sync', 'shouldProxy' ] diff --git a/packages/server-test-utils/types/index.d.ts b/packages/server-test-utils/types/index.d.ts index 2089bfb82..d527a5038 100644 --- a/packages/server-test-utils/types/index.d.ts +++ b/packages/server-test-utils/types/index.d.ts @@ -50,7 +50,6 @@ interface VueTestUtilsConfigOptions { mocks?: object methods?: Record provide?: object, - logModifiedComponents?: Boolean silent?: Boolean } diff --git a/packages/server-test-utils/types/test/renderToString.ts b/packages/server-test-utils/types/test/renderToString.ts index 77a0892e1..17ac8e41f 100644 --- a/packages/server-test-utils/types/test/renderToString.ts +++ b/packages/server-test-utils/types/test/renderToString.ts @@ -62,5 +62,4 @@ config.methods = { config.provide = { foo: {} } -config.logModifiedComponents = true config.silent = true diff --git a/packages/shared/consts.js b/packages/shared/consts.js index 30b437426..ea6a82696 100644 --- a/packages/shared/consts.js +++ b/packages/shared/consts.js @@ -6,6 +6,9 @@ export const COMPONENT_SELECTOR = 'COMPONENT_SELECTOR' export const REF_SELECTOR = 'REF_SELECTOR' export const DOM_SELECTOR = 'DOM_SELECTOR' export const INVALID_SELECTOR = 'INVALID_SELECTOR' + +export const COMPAT_SYNC_MODE = 'COMPAT_SYNC_MODE' + export const VUE_VERSION = Number( `${Vue.version.split('.')[0]}.${Vue.version.split('.')[1]}` ) diff --git a/packages/shared/merge-options.js b/packages/shared/merge-options.js index 7c4b71b92..7462bdcb3 100644 --- a/packages/shared/merge-options.js +++ b/packages/shared/merge-options.js @@ -26,7 +26,6 @@ export function mergeOptions (options: Options, config: Config): Options { const provide = ((getOption(options.provide, config.provide)): Object) return { ...options, - logModifiedComponents: config.logModifiedComponents, stubs: getOption(normalizeStubs(options.stubs), config.stubs), mocks, methods, diff --git a/packages/test-utils/src/mount.js b/packages/test-utils/src/mount.js index a9c752e86..2fb7ef02f 100644 --- a/packages/test-utils/src/mount.js +++ b/packages/test-utils/src/mount.js @@ -13,9 +13,39 @@ import config from './config' import warnIfNoWindow from './warn-if-no-window' import createWrapper from './create-wrapper' import createLocalVue from './create-local-vue' +import { semVerGreaterThan, warn } from 'shared/util' +import { COMPAT_SYNC_MODE } from 'shared/consts' + Vue.config.productionTip = false Vue.config.devtools = false +function getSyncOption (syncOption) { + if (syncOption === false) { + Vue.config.async = true + return false + } + if (!semVerGreaterThan(Vue.version, '2.5.17')) { + warn( + `Vue Test Utils runs in sync mode by default. Due to bugs, sync mode ` + + `requires Vue > 2.5.18. In Vue Test Utils 1.0 sync mode will only be ` + + `supported with Vue 2.5.18 running in development mode. If you are ` + + `unable to upgrade, you should rewrite your tests to run synchronously` + + `you can do this by setting the sync mounting option to false.` + ) + return COMPAT_SYNC_MODE + } + + if (typeof Vue.config.async === 'undefined') { + warn( + `Sync mode only works when Vue runs in dev mode. ` + + `Please set Vue to run in dev mode, or set sync to false` + ) + } + + Vue.config.async = false + return true +} + export default function mount ( component: Component, options: Options = {} @@ -49,7 +79,7 @@ export default function mount ( const wrapperOptions = { attachedToDocument: !!mergedOptions.attachToDocument, - sync: mergedOptions.sync + sync: getSyncOption(mergedOptions.sync) } const root = vm.$options._isFunctionalContainer ? vm._vnode diff --git a/packages/test-utils/src/vue-wrapper.js b/packages/test-utils/src/vue-wrapper.js index 9fb6b871a..726ea7c84 100644 --- a/packages/test-utils/src/vue-wrapper.js +++ b/packages/test-utils/src/vue-wrapper.js @@ -4,6 +4,7 @@ import Wrapper from './wrapper' import { throwError } from 'shared/util' import { setWatchersToSync } from './set-watchers-to-sync' import { orderWatchers } from './order-watchers' +import { COMPAT_SYNC_MODE } from 'shared/consts' export default class VueWrapper extends Wrapper implements BaseWrapper { constructor (vm: Component, options: WrapperOptions) { @@ -28,7 +29,7 @@ export default class VueWrapper extends Wrapper implements BaseWrapper { get: () => vm, set: () => throwError('wrapper.vm is read-only') }) - if (options.sync) { + if (options.sync === COMPAT_SYNC_MODE) { setWatchersToSync(vm) orderWatchers(vm) } diff --git a/packages/test-utils/src/wrapper.js b/packages/test-utils/src/wrapper.js index 4d13e0c25..ac9966ee2 100644 --- a/packages/test-utils/src/wrapper.js +++ b/packages/test-utils/src/wrapper.js @@ -4,7 +4,8 @@ import Vue from 'vue' import getSelector from './get-selector' import { REF_SELECTOR, - FUNCTIONAL_OPTIONS + FUNCTIONAL_OPTIONS, + COMPAT_SYNC_MODE } from 'shared/consts' import config from './config' import WrapperArray from './wrapper-array' @@ -758,8 +759,10 @@ export default class Wrapper implements BaseWrapper { }) // $FlowIgnore : Problem with possibly null this.vm this.vm.$forceUpdate() - // $FlowIgnore : Problem with possibly null this.vm - orderWatchers(this.vm || this.vnode.context.$root) + if (this.options.sync === COMPAT_SYNC_MODE) { + // $FlowIgnore : Problem with possibly null this.vm + orderWatchers(this.vm || this.vnode.context.$root) + } Vue.config.silent = originalConfig } @@ -832,7 +835,7 @@ export default class Wrapper implements BaseWrapper { const event = createDOMEvent(type, options) this.element.dispatchEvent(event) - if (this.vnode) { + if (this.vnode && this.options.sync === COMPAT_SYNC_MODE) { orderWatchers(this.vm || this.vnode.context.$root) } } diff --git a/scripts/test-compat-all.sh b/scripts/test-compat-all.sh index 7485d912b..258666f83 100755 --- a/scripts/test-compat-all.sh +++ b/scripts/test-compat-all.sh @@ -7,4 +7,4 @@ scripts/test-compat.sh "2.1.10" scripts/test-compat.sh "2.2.6" scripts/test-compat.sh "2.3.4" scripts/test-compat.sh "2.4.2" -scripts/test-compat.sh "2.5.16" +scripts/test-compat.sh "2.5.20" diff --git a/test/specs/config.spec.js b/test/specs/config.spec.js index 5dacf4adb..4261aa198 100644 --- a/test/specs/config.spec.js +++ b/test/specs/config.spec.js @@ -1,29 +1,28 @@ -import { describeWithShallowAndMount, vueVersion } from '~resources/utils' +import { describeWithShallowAndMount } from '~resources/utils' import ComponentWithProps from '~resources/components/component-with-props.vue' -import { itDoNotRunIf, itSkipIf } from 'conditional-specs' +import { itDoNotRunIf } from 'conditional-specs' import { config, TransitionStub, TransitionGroupStub, createLocalVue } from '~vue/test-utils' -import Vue from 'vue' describeWithShallowAndMount('config', mountingMethod => { - let configStubsSave, consoleError, configLogSave, configSilentSave + let configStubsSave, configLogSave, configSilentSave beforeEach(() => { configStubsSave = config.stubs configLogSave = config.logModifiedComponents configSilentSave = config.silent - consoleError = sinon.stub(console, 'error') + sinon.stub(console, 'error').callThrough() }) afterEach(() => { config.stubs = configStubsSave config.logModifiedComponents = configLogSave config.silent = configSilentSave - consoleError.restore() + console.error.restore() }) itDoNotRunIf( @@ -150,7 +149,7 @@ describeWithShallowAndMount('config', mountingMethod => { wrapper.setProps({ prop1: 'new value' }) - expect(consoleError.called).to.equal(false) + expect(console.error).not.calledWith(sinon.match('[Vue warn]')) }) it('does throw Vue warning when silent is set to false', () => { @@ -166,25 +165,6 @@ describeWithShallowAndMount('config', mountingMethod => { wrapper.setProps({ prop1: 'new value' }) - expect(consoleError.called).to.equal(true) + expect(console.error).calledWith(sinon.match('[Vue warn]')) }) - - itSkipIf( - vueVersion < 2.3, - 'does not log when component is extended if logModifiedComponents is false', - () => { - const ChildComponent = Vue.extend({ - template: '' - }) - const TestComponent = { - template: '', - components: { - ChildComponent - } - } - config.logModifiedComponents = false - mountingMethod(TestComponent) - expect(consoleError.called).to.equal(false) - } - ) }) diff --git a/test/specs/mounting-options/sync.spec.js b/test/specs/mounting-options/sync.spec.js index fab7cc3d7..80c348040 100644 --- a/test/specs/mounting-options/sync.spec.js +++ b/test/specs/mounting-options/sync.spec.js @@ -1,7 +1,16 @@ import sinon from 'sinon' -import { describeWithShallowAndMount } from '~resources/utils' +import { describeWithShallowAndMount, vueVersion } from '~resources/utils' +import { itDoNotRunIf } from 'conditional-specs' describeWithShallowAndMount('options.sync', mountingMethod => { + beforeEach(() => { + sinon.stub(console, 'error').callThrough() + }) + + afterEach(() => { + console.error.restore() + }) + it('sets watchers to sync if set to true', () => { const TestComponent = { template: '
{{someData}}
', @@ -12,11 +21,12 @@ describeWithShallowAndMount('options.sync', mountingMethod => { const wrapper = mountingMethod(TestComponent, { sync: true }) + const syncValue = vueVersion < 2.5 ? 'COMPAT_SYNC_MODE' : true expect(wrapper.text()).to.equal('hello') wrapper.vm.someData = 'world' expect(wrapper.text()).to.equal('world') - expect(wrapper.options.sync).to.equal(true) + expect(wrapper.options.sync).to.equal(syncValue) }) it('sets watchers to sync if undefined', () => { @@ -27,11 +37,12 @@ describeWithShallowAndMount('options.sync', mountingMethod => { }) } const wrapper = mountingMethod(TestComponent) + const syncValue = vueVersion < 2.5 ? 'COMPAT_SYNC_MODE' : true expect(wrapper.text()).to.equal('hello') wrapper.vm.someData = 'world' expect(wrapper.text()).to.equal('world') - expect(wrapper.options.sync).to.equal(true) + expect(wrapper.options.sync).to.equal(syncValue) }) it('handles methods that update watchers', () => { @@ -145,4 +156,18 @@ describeWithShallowAndMount('options.sync', mountingMethod => { expect(childComponentSpy.calledOnce).to.equal(true) expect(wrapper.html()).to.equal('
bar
bar
') }) + + itDoNotRunIf( + vueVersion > 2.4, + 'warns if Vue version is less than 2.5.18', + () => { + const TestComponent = { + template: '
' + } + mountingMethod(TestComponent) + expect(console.error) + .calledWith( + sinon.match('Vue Test Utils runs in sync mode by default') + ) + }) }) diff --git a/test/specs/shallow-mount.spec.js b/test/specs/shallow-mount.spec.js index d135f9308..8ca801bfb 100644 --- a/test/specs/shallow-mount.spec.js +++ b/test/specs/shallow-mount.spec.js @@ -147,7 +147,7 @@ describeRunIf(process.env.TEST_ENV !== 'node', 'shallowMount', () => { } } shallowMount(TestComponent) - expect(console.error).not.called + expect(console.error).not.calledWith(sinon.match('[Vue warn]')) } ) @@ -248,7 +248,7 @@ describeRunIf(process.env.TEST_ENV !== 'node', 'shallowMount', () => { } const wrapper = shallowMount(TestComponent) expect(wrapper.html()).to.contain('') - expect(console.error).not.called + expect(console.error).not.calledWith('[Vue warn]') }) it('does not call stubbed children lifecycle hooks', () => { diff --git a/yarn.lock b/yarn.lock index 2e4fb3af1..3bf327f25 100644 --- a/yarn.lock +++ b/yarn.lock @@ -9813,7 +9813,21 @@ vue-router@^3.0.1: version "3.0.1" resolved "https://registry.yarnpkg.com/vue-router/-/vue-router-3.0.1.tgz#d9b05ad9c7420ba0f626d6500d693e60092cc1e9" -vue-server-renderer@2.5.16, vue-server-renderer@^2.5.16: +vue-server-renderer@2.5.20: + version "2.5.20" + resolved "https://registry.yarnpkg.com/vue-server-renderer/-/vue-server-renderer-2.5.20.tgz#b4d4718949592f7138d7fa2b370f2a00b967af37" + integrity sha512-q3ulfGr3a8UUbLs2tQWEBeQfl8HwUWoXF5N7H1ZGo+eL4y+xIpjpV1z14Hx8tQGoY64xja7QdSyjNWVuGmLjXg== + dependencies: + chalk "^1.1.3" + hash-sum "^1.0.2" + he "^1.1.0" + lodash.template "^4.4.0" + lodash.uniq "^4.5.0" + resolve "^1.2.0" + serialize-javascript "^1.3.0" + source-map "0.5.6" + +vue-server-renderer@^2.5.16: version "2.5.16" resolved "https://registry.yarnpkg.com/vue-server-renderer/-/vue-server-renderer-2.5.16.tgz#279ef8e37e502a0de3a9ae30758cc04a472eaac0" dependencies: @@ -9840,7 +9854,15 @@ vue-style-loader@^4.1.0: hash-sum "^1.0.2" loader-utils "^1.0.2" -vue-template-compiler@2.5.16, vue-template-compiler@^2.5.16: +vue-template-compiler@2.5.20: + version "2.5.20" + resolved "https://registry.yarnpkg.com/vue-template-compiler/-/vue-template-compiler-2.5.20.tgz#b9c01741b7e0261d1c5aac5937c93bde98f880f0" + integrity sha512-aGJRLd1bJZi6oerGwCQVaDqvQ1T3dhCbNg9C2gNwzoKnyA3BmYfAWy8OQ3OhOebTri8o4YcLeXfwOOxtOKFfmA== + dependencies: + de-indent "^1.0.2" + he "^1.1.0" + +vue-template-compiler@^2.5.16: version "2.5.16" resolved "https://registry.yarnpkg.com/vue-template-compiler/-/vue-template-compiler-2.5.16.tgz#93b48570e56c720cdf3f051cc15287c26fbd04cb" dependencies: @@ -9851,7 +9873,12 @@ vue-template-es2015-compiler@^1.6.0: version "1.6.0" resolved "https://registry.yarnpkg.com/vue-template-es2015-compiler/-/vue-template-es2015-compiler-1.6.0.tgz#dc42697133302ce3017524356a6c61b7b69b4a18" -vue@2.5.16, vue@^2.5.16: +vue@2.5.20: + version "2.5.20" + resolved "https://registry.yarnpkg.com/vue/-/vue-2.5.20.tgz#79fff9ccaa10cc37e7a7239b4c7adfac94df81ba" + integrity sha512-kVLZi8RWOk8qwAt+a0bVDy9VV5Zzcnj0fLCMyKLx1dmEBjqmYJYRWHvPwiypiJBtJkdmROy5NP5hyDqTdfBcvQ== + +vue@^2.5.16: version "2.5.16" resolved "https://registry.yarnpkg.com/vue/-/vue-2.5.16.tgz#07edb75e8412aaeed871ebafa99f4672584a0085" From 0b516fe478093f7ef5ffcc674c09c47520443e53 Mon Sep 17 00:00:00 2001 From: eddyerburgh Date: Tue, 11 Dec 2018 21:07:29 +0000 Subject: [PATCH 02/10] fix: handle scoped slots --- packages/test-utils/src/mount.js | 7 +++--- .../mounting-options/scopedSlots.spec.js | 23 +++++++++++++++++++ 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/packages/test-utils/src/mount.js b/packages/test-utils/src/mount.js index 2fb7ef02f..c9f050532 100644 --- a/packages/test-utils/src/mount.js +++ b/packages/test-utils/src/mount.js @@ -50,15 +50,16 @@ export default function mount ( component: Component, options: Options = {} ): VueWrapper | Wrapper { + const mergedOptions = mergeOptions(options, config) + const sync = getSyncOption(mergedOptions.sync) const existingErrorHandler = Vue.config.errorHandler + Vue.config.errorHandler = errorHandler warnIfNoWindow() const elm = options.attachToDocument ? createElement() : undefined - const mergedOptions = mergeOptions(options, config) - const parentVm = createInstance( component, mergedOptions, @@ -79,7 +80,7 @@ export default function mount ( const wrapperOptions = { attachedToDocument: !!mergedOptions.attachToDocument, - sync: getSyncOption(mergedOptions.sync) + sync } const root = vm.$options._isFunctionalContainer ? vm._vnode diff --git a/test/specs/mounting-options/scopedSlots.spec.js b/test/specs/mounting-options/scopedSlots.spec.js index b4392dc32..823a99d3a 100644 --- a/test/specs/mounting-options/scopedSlots.spec.js +++ b/test/specs/mounting-options/scopedSlots.spec.js @@ -234,4 +234,27 @@ describeWithShallowAndMount('scopedSlots', mountingMethod => { .with.property('message', message) } ) + + it('renders scoped slots in sync mode by default', () => { + const TestComponent = { + data () { + return { + val: null + } + }, + mounted () { + this.val = 123 + }, + render () { + return this.$scopedSlots.default(this.val) + } + } + const stub = sinon.stub() + mountingMethod(TestComponent, { + scopedSlots: { + default: stub + } + }) + expect(stub).calledWith(123) + }) }) From c8ff9616aec90618f50871fccfa36578ea07a811 Mon Sep 17 00:00:00 2001 From: eddyerburgh Date: Tue, 11 Dec 2018 21:08:43 +0000 Subject: [PATCH 03/10] test: only run in Vue 2.5 --- .../mounting-options/scopedSlots.spec.js | 40 ++++++++++--------- 1 file changed, 21 insertions(+), 19 deletions(-) diff --git a/test/specs/mounting-options/scopedSlots.spec.js b/test/specs/mounting-options/scopedSlots.spec.js index 823a99d3a..4c2faf43f 100644 --- a/test/specs/mounting-options/scopedSlots.spec.js +++ b/test/specs/mounting-options/scopedSlots.spec.js @@ -235,26 +235,28 @@ describeWithShallowAndMount('scopedSlots', mountingMethod => { } ) - it('renders scoped slots in sync mode by default', () => { - const TestComponent = { - data () { - return { - val: null + itDoNotRunIf( + vueVersion < 2.5, + 'renders scoped slots in sync mode by default', () => { + const TestComponent = { + data () { + return { + val: null + } + }, + mounted () { + this.val = 123 + }, + render () { + return this.$scopedSlots.default(this.val) } - }, - mounted () { - this.val = 123 - }, - render () { - return this.$scopedSlots.default(this.val) - } - } - const stub = sinon.stub() - mountingMethod(TestComponent, { - scopedSlots: { - default: stub } + const stub = sinon.stub() + mountingMethod(TestComponent, { + scopedSlots: { + default: stub + } + }) + expect(stub).calledWith(123) }) - expect(stub).calledWith(123) - }) }) From be4b6e0e8f2c9eae56692fda02827b28f5a7a245 Mon Sep 17 00:00:00 2001 From: Winnie Hellmann <31919422+gitlab-winnie@users.noreply.github.com> Date: Tue, 15 Jan 2019 08:19:38 +0000 Subject: [PATCH 04/10] docs: fix wording in warning Co-Authored-By: eddyerburgh --- packages/test-utils/src/mount.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/test-utils/src/mount.js b/packages/test-utils/src/mount.js index c9f050532..0dac9c503 100644 --- a/packages/test-utils/src/mount.js +++ b/packages/test-utils/src/mount.js @@ -29,7 +29,7 @@ function getSyncOption (syncOption) { `Vue Test Utils runs in sync mode by default. Due to bugs, sync mode ` + `requires Vue > 2.5.18. In Vue Test Utils 1.0 sync mode will only be ` + `supported with Vue 2.5.18 running in development mode. If you are ` + - `unable to upgrade, you should rewrite your tests to run synchronously` + + `unable to upgrade, you should rewrite your tests to run asynchronously` + `you can do this by setting the sync mounting option to false.` ) return COMPAT_SYNC_MODE From d4fbc99043fb82244a5fb4e6c7442c27f6da8be7 Mon Sep 17 00:00:00 2001 From: eddyerburgh Date: Sat, 2 Feb 2019 07:30:47 +0000 Subject: [PATCH 05/10] test: update test --- package.json | 6 ++-- packages/create-instance/create-instance.js | 3 +- packages/test-utils/src/wrapper.js | 7 +++- test/specs/mount.spec.js | 36 ++++++++++--------- yarn.lock | 38 ++++++++++----------- 5 files changed, 50 insertions(+), 40 deletions(-) diff --git a/package.json b/package.json index 259027c50..540112fd7 100644 --- a/package.json +++ b/package.json @@ -68,12 +68,12 @@ "sinon-chai": "^2.10.0", "typescript": "^3.0.1", "vee-validate": "^2.1.3", - "vue": "2.5.20", + "vue": "^2.5.22", "vue-class-component": "^6.1.2", "vue-loader": "^13.6.2", "vue-router": "^3.0.1", - "vue-server-renderer": "2.5.20", - "vue-template-compiler": "2.5.20", + "vue-server-renderer": "^2.5.22", + "vue-template-compiler": "^2.5.22", "vuepress": "^0.14.2", "vuepress-theme-vue": "^1.0.3", "vuex": "^3.0.1", diff --git a/packages/create-instance/create-instance.js b/packages/create-instance/create-instance.js index 27a63d5b0..b0869002b 100644 --- a/packages/create-instance/create-instance.js +++ b/packages/create-instance/create-instance.js @@ -72,10 +72,11 @@ export default function createInstance( componentOptions.$_vueTestUtils_original = component // make sure all extends are based on this instance - componentOptions._base = _Vue const Constructor = _Vue.extend(componentOptions).extend(instanceOptions) + Constructor.options._base = _Vue + const scopedSlots = createScopedSlots(options.scopedSlots, _Vue) const parentComponentOptions = options.parentComponent || {} diff --git a/packages/test-utils/src/wrapper.js b/packages/test-utils/src/wrapper.js index fd9e9bdb1..4982d791b 100644 --- a/packages/test-utils/src/wrapper.js +++ b/packages/test-utils/src/wrapper.js @@ -2,7 +2,12 @@ import Vue from 'vue' import getSelector from './get-selector' -import { REF_SELECTOR, FUNCTIONAL_OPTIONS, VUE_VERSION, COMPAT_SYNC_MODE } from 'shared/consts' +import { + REF_SELECTOR, + FUNCTIONAL_OPTIONS, + VUE_VERSION, + COMPAT_SYNC_MODE +} from 'shared/consts' import config from './config' import WrapperArray from './wrapper-array' import ErrorWrapper from './error-wrapper' diff --git a/test/specs/mount.spec.js b/test/specs/mount.spec.js index 87359814b..882457568 100644 --- a/test/specs/mount.spec.js +++ b/test/specs/mount.spec.js @@ -412,21 +412,25 @@ describeRunIf(process.env.TEST_ENV !== 'node', 'mount', () => { }) }) - it('throws if component throws during update', () => { - const TestComponent = { - template: '
', - updated() { - throw new Error('err') - }, - data: () => ({ - a: 1 - }) - } - const wrapper = mount(TestComponent) - const fn = () => { - wrapper.vm.a = 2 + itDoNotRunIf( + vueVersion >= 2.5, + 'throws if component throws during update', + () => { + const TestComponent = { + template: '
', + updated() { + throw new Error('err') + }, + data: () => ({ + a: 1 + }) + } + const wrapper = mount(TestComponent) + const fn = () => { + wrapper.vm.a = 2 + } + expect(fn).to.throw() + wrapper.destroy() } - expect(fn).to.throw() - wrapper.destroy() - }) + ) }) diff --git a/yarn.lock b/yarn.lock index 89a2a830b..bfc6a85d8 100644 --- a/yarn.lock +++ b/yarn.lock @@ -9823,10 +9823,9 @@ vue-router@^3.0.1: version "3.0.1" resolved "https://registry.yarnpkg.com/vue-router/-/vue-router-3.0.1.tgz#d9b05ad9c7420ba0f626d6500d693e60092cc1e9" -vue-server-renderer@2.5.20: - version "2.5.20" - resolved "https://registry.yarnpkg.com/vue-server-renderer/-/vue-server-renderer-2.5.20.tgz#b4d4718949592f7138d7fa2b370f2a00b967af37" - integrity sha512-q3ulfGr3a8UUbLs2tQWEBeQfl8HwUWoXF5N7H1ZGo+eL4y+xIpjpV1z14Hx8tQGoY64xja7QdSyjNWVuGmLjXg== +vue-server-renderer@^2.5.16: + version "2.5.16" + resolved "https://registry.yarnpkg.com/vue-server-renderer/-/vue-server-renderer-2.5.16.tgz#279ef8e37e502a0de3a9ae30758cc04a472eaac0" dependencies: chalk "^1.1.3" hash-sum "^1.0.2" @@ -9837,9 +9836,10 @@ vue-server-renderer@2.5.20: serialize-javascript "^1.3.0" source-map "0.5.6" -vue-server-renderer@^2.5.16: - version "2.5.16" - resolved "https://registry.yarnpkg.com/vue-server-renderer/-/vue-server-renderer-2.5.16.tgz#279ef8e37e502a0de3a9ae30758cc04a472eaac0" +vue-server-renderer@^2.5.22: + version "2.5.22" + resolved "https://registry.yarnpkg.com/vue-server-renderer/-/vue-server-renderer-2.5.22.tgz#f119efef289c865adc22fda0ae7595299bedbdcf" + integrity sha512-PQ0PubA6b2MyZud/gepWeiUuDFSbRfa6h1qYINcbwXRr4Z3yLTHprEQuFnWikdkTkZpeLFYUqZrDxPbDcJ71mA== dependencies: chalk "^1.1.3" hash-sum "^1.0.2" @@ -9864,17 +9864,17 @@ vue-style-loader@^4.1.0: hash-sum "^1.0.2" loader-utils "^1.0.2" -vue-template-compiler@2.5.20: - version "2.5.20" - resolved "https://registry.yarnpkg.com/vue-template-compiler/-/vue-template-compiler-2.5.20.tgz#b9c01741b7e0261d1c5aac5937c93bde98f880f0" - integrity sha512-aGJRLd1bJZi6oerGwCQVaDqvQ1T3dhCbNg9C2gNwzoKnyA3BmYfAWy8OQ3OhOebTri8o4YcLeXfwOOxtOKFfmA== +vue-template-compiler@^2.5.16: + version "2.5.16" + resolved "https://registry.yarnpkg.com/vue-template-compiler/-/vue-template-compiler-2.5.16.tgz#93b48570e56c720cdf3f051cc15287c26fbd04cb" dependencies: de-indent "^1.0.2" he "^1.1.0" -vue-template-compiler@^2.5.16: - version "2.5.16" - resolved "https://registry.yarnpkg.com/vue-template-compiler/-/vue-template-compiler-2.5.16.tgz#93b48570e56c720cdf3f051cc15287c26fbd04cb" +vue-template-compiler@^2.5.22: + version "2.5.22" + resolved "https://registry.yarnpkg.com/vue-template-compiler/-/vue-template-compiler-2.5.22.tgz#c3d3c02c65f1908205c4fbd3b0ef579e51239955" + integrity sha512-1VTw/NPTUeHNiwhkq6NkFzO7gYLjFCueBN0FX8NEiQIemd5EUMQ5hxrF7O0zCPo5tae+U9S/scETPea+hIz8Eg== dependencies: de-indent "^1.0.2" he "^1.1.0" @@ -9883,15 +9883,15 @@ vue-template-es2015-compiler@^1.6.0: version "1.6.0" resolved "https://registry.yarnpkg.com/vue-template-es2015-compiler/-/vue-template-es2015-compiler-1.6.0.tgz#dc42697133302ce3017524356a6c61b7b69b4a18" -vue@2.5.20: - version "2.5.20" - resolved "https://registry.yarnpkg.com/vue/-/vue-2.5.20.tgz#79fff9ccaa10cc37e7a7239b4c7adfac94df81ba" - integrity sha512-kVLZi8RWOk8qwAt+a0bVDy9VV5Zzcnj0fLCMyKLx1dmEBjqmYJYRWHvPwiypiJBtJkdmROy5NP5hyDqTdfBcvQ== - vue@^2.5.16: version "2.5.16" resolved "https://registry.yarnpkg.com/vue/-/vue-2.5.16.tgz#07edb75e8412aaeed871ebafa99f4672584a0085" +vue@^2.5.22: + version "2.5.22" + resolved "https://registry.yarnpkg.com/vue/-/vue-2.5.22.tgz#3bf88041af08b8539c37b268b70ca79245e9cc30" + integrity sha512-pxY3ZHlXNJMFQbkjEgGVMaMMkSV1ONpz+4qB55kZuJzyJOhn6MSy/YZdzhdnumegNzVTL/Dn3Pp4UrVBYt1j/g== + vuepress-html-webpack-plugin@^3.2.0: version "3.2.0" resolved "https://registry.yarnpkg.com/vuepress-html-webpack-plugin/-/vuepress-html-webpack-plugin-3.2.0.tgz#219be272ad510faa8750d2d4e70fd028bfd1c16e" From fa9e0584d9804f16c72c2b17ac638cdbfcba7d73 Mon Sep 17 00:00:00 2001 From: eddyerburgh Date: Sat, 2 Feb 2019 07:52:43 +0000 Subject: [PATCH 06/10] fix: remove logModfiedComponents option --- packages/shared/merge-options.js | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/shared/merge-options.js b/packages/shared/merge-options.js index d2c4d3dfe..6ad19f2aa 100644 --- a/packages/shared/merge-options.js +++ b/packages/shared/merge-options.js @@ -28,7 +28,6 @@ export function mergeOptions(options: Options, config: Config): Options { return { ...options, provide: normalizeProvide(provide), - logModifiedComponents: config.logModifiedComponents, stubs: getOption(normalizeStubs(options.stubs), config.stubs), mocks, methods, From ac452a2135934cb42cb7a89c7e47cfee0af79795 Mon Sep 17 00:00:00 2001 From: eddyerburgh Date: Sat, 2 Feb 2019 09:09:30 +0000 Subject: [PATCH 07/10] Use latest Vue version --- package.json | 6 +++--- yarn.lock | 38 +++++++++++++++++++------------------- 2 files changed, 22 insertions(+), 22 deletions(-) diff --git a/package.json b/package.json index 540112fd7..3a4052a92 100644 --- a/package.json +++ b/package.json @@ -68,12 +68,12 @@ "sinon-chai": "^2.10.0", "typescript": "^3.0.1", "vee-validate": "^2.1.3", - "vue": "^2.5.22", + "vue": "2.5.22", "vue-class-component": "^6.1.2", "vue-loader": "^13.6.2", "vue-router": "^3.0.1", - "vue-server-renderer": "^2.5.22", - "vue-template-compiler": "^2.5.22", + "vue-server-renderer": "2.5.22", + "vue-template-compiler": "2.5.22", "vuepress": "^0.14.2", "vuepress-theme-vue": "^1.0.3", "vuex": "^3.0.1", diff --git a/yarn.lock b/yarn.lock index bfc6a85d8..a6e5e9acb 100644 --- a/yarn.lock +++ b/yarn.lock @@ -9823,9 +9823,10 @@ vue-router@^3.0.1: version "3.0.1" resolved "https://registry.yarnpkg.com/vue-router/-/vue-router-3.0.1.tgz#d9b05ad9c7420ba0f626d6500d693e60092cc1e9" -vue-server-renderer@^2.5.16: - version "2.5.16" - resolved "https://registry.yarnpkg.com/vue-server-renderer/-/vue-server-renderer-2.5.16.tgz#279ef8e37e502a0de3a9ae30758cc04a472eaac0" +vue-server-renderer@2.5.22: + version "2.5.22" + resolved "https://registry.yarnpkg.com/vue-server-renderer/-/vue-server-renderer-2.5.22.tgz#f119efef289c865adc22fda0ae7595299bedbdcf" + integrity sha512-PQ0PubA6b2MyZud/gepWeiUuDFSbRfa6h1qYINcbwXRr4Z3yLTHprEQuFnWikdkTkZpeLFYUqZrDxPbDcJ71mA== dependencies: chalk "^1.1.3" hash-sum "^1.0.2" @@ -9836,10 +9837,9 @@ vue-server-renderer@^2.5.16: serialize-javascript "^1.3.0" source-map "0.5.6" -vue-server-renderer@^2.5.22: - version "2.5.22" - resolved "https://registry.yarnpkg.com/vue-server-renderer/-/vue-server-renderer-2.5.22.tgz#f119efef289c865adc22fda0ae7595299bedbdcf" - integrity sha512-PQ0PubA6b2MyZud/gepWeiUuDFSbRfa6h1qYINcbwXRr4Z3yLTHprEQuFnWikdkTkZpeLFYUqZrDxPbDcJ71mA== +vue-server-renderer@^2.5.16: + version "2.5.16" + resolved "https://registry.yarnpkg.com/vue-server-renderer/-/vue-server-renderer-2.5.16.tgz#279ef8e37e502a0de3a9ae30758cc04a472eaac0" dependencies: chalk "^1.1.3" hash-sum "^1.0.2" @@ -9864,17 +9864,17 @@ vue-style-loader@^4.1.0: hash-sum "^1.0.2" loader-utils "^1.0.2" -vue-template-compiler@^2.5.16: - version "2.5.16" - resolved "https://registry.yarnpkg.com/vue-template-compiler/-/vue-template-compiler-2.5.16.tgz#93b48570e56c720cdf3f051cc15287c26fbd04cb" +vue-template-compiler@2.5.22: + version "2.5.22" + resolved "https://registry.yarnpkg.com/vue-template-compiler/-/vue-template-compiler-2.5.22.tgz#c3d3c02c65f1908205c4fbd3b0ef579e51239955" + integrity sha512-1VTw/NPTUeHNiwhkq6NkFzO7gYLjFCueBN0FX8NEiQIemd5EUMQ5hxrF7O0zCPo5tae+U9S/scETPea+hIz8Eg== dependencies: de-indent "^1.0.2" he "^1.1.0" -vue-template-compiler@^2.5.22: - version "2.5.22" - resolved "https://registry.yarnpkg.com/vue-template-compiler/-/vue-template-compiler-2.5.22.tgz#c3d3c02c65f1908205c4fbd3b0ef579e51239955" - integrity sha512-1VTw/NPTUeHNiwhkq6NkFzO7gYLjFCueBN0FX8NEiQIemd5EUMQ5hxrF7O0zCPo5tae+U9S/scETPea+hIz8Eg== +vue-template-compiler@^2.5.16: + version "2.5.16" + resolved "https://registry.yarnpkg.com/vue-template-compiler/-/vue-template-compiler-2.5.16.tgz#93b48570e56c720cdf3f051cc15287c26fbd04cb" dependencies: de-indent "^1.0.2" he "^1.1.0" @@ -9883,15 +9883,15 @@ vue-template-es2015-compiler@^1.6.0: version "1.6.0" resolved "https://registry.yarnpkg.com/vue-template-es2015-compiler/-/vue-template-es2015-compiler-1.6.0.tgz#dc42697133302ce3017524356a6c61b7b69b4a18" -vue@^2.5.16: - version "2.5.16" - resolved "https://registry.yarnpkg.com/vue/-/vue-2.5.16.tgz#07edb75e8412aaeed871ebafa99f4672584a0085" - -vue@^2.5.22: +vue@2.5.22: version "2.5.22" resolved "https://registry.yarnpkg.com/vue/-/vue-2.5.22.tgz#3bf88041af08b8539c37b268b70ca79245e9cc30" integrity sha512-pxY3ZHlXNJMFQbkjEgGVMaMMkSV1ONpz+4qB55kZuJzyJOhn6MSy/YZdzhdnumegNzVTL/Dn3Pp4UrVBYt1j/g== +vue@^2.5.16: + version "2.5.16" + resolved "https://registry.yarnpkg.com/vue/-/vue-2.5.16.tgz#07edb75e8412aaeed871ebafa99f4672584a0085" + vuepress-html-webpack-plugin@^3.2.0: version "3.2.0" resolved "https://registry.yarnpkg.com/vuepress-html-webpack-plugin/-/vuepress-html-webpack-plugin-3.2.0.tgz#219be272ad510faa8750d2d4e70fd028bfd1c16e" From 6669d9e71d35e77e3232db5221e6e5fc7b2bb434 Mon Sep 17 00:00:00 2001 From: eddyerburgh Date: Sat, 2 Feb 2019 09:21:34 +0000 Subject: [PATCH 08/10] chore: use yarn.lock checksum to restore cache --- .circleci/config.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index e09c1b569..8d5e7bbff 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -9,8 +9,6 @@ restore_node_modules: &restore_node_modules name: Restore node_modules cache keys: - v1-dependencies-{{ .Branch }}-{{ checksum "yarn.lock" }} - - v1-dependencies-{{ .Branch }}- - - v1-dependencies- jobs: install: <<: *defaults From a14365af84a363a51d39b7580ad3316fbf847203 Mon Sep 17 00:00:00 2001 From: eddyerburgh Date: Sat, 2 Feb 2019 10:51:45 +0000 Subject: [PATCH 09/10] refactor: use Vue 2.5.21 --- package.json | 6 +++--- yarn.lock | 24 ++++++++++++------------ 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/package.json b/package.json index 3a4052a92..6c501aaa2 100644 --- a/package.json +++ b/package.json @@ -68,12 +68,12 @@ "sinon-chai": "^2.10.0", "typescript": "^3.0.1", "vee-validate": "^2.1.3", - "vue": "2.5.22", + "vue": "2.5.21", "vue-class-component": "^6.1.2", "vue-loader": "^13.6.2", "vue-router": "^3.0.1", - "vue-server-renderer": "2.5.22", - "vue-template-compiler": "2.5.22", + "vue-server-renderer": "2.5.21", + "vue-template-compiler": "2.5.21", "vuepress": "^0.14.2", "vuepress-theme-vue": "^1.0.3", "vuex": "^3.0.1", diff --git a/yarn.lock b/yarn.lock index a6e5e9acb..c6b21eee1 100644 --- a/yarn.lock +++ b/yarn.lock @@ -9823,10 +9823,10 @@ vue-router@^3.0.1: version "3.0.1" resolved "https://registry.yarnpkg.com/vue-router/-/vue-router-3.0.1.tgz#d9b05ad9c7420ba0f626d6500d693e60092cc1e9" -vue-server-renderer@2.5.22: - version "2.5.22" - resolved "https://registry.yarnpkg.com/vue-server-renderer/-/vue-server-renderer-2.5.22.tgz#f119efef289c865adc22fda0ae7595299bedbdcf" - integrity sha512-PQ0PubA6b2MyZud/gepWeiUuDFSbRfa6h1qYINcbwXRr4Z3yLTHprEQuFnWikdkTkZpeLFYUqZrDxPbDcJ71mA== +vue-server-renderer@2.5.21: + version "2.5.21" + resolved "https://registry.yarnpkg.com/vue-server-renderer/-/vue-server-renderer-2.5.21.tgz#7c2b611d2e8558359cdb84dcd3080845c07121b4" + integrity sha512-bAkOYZ5DnmQKv3RboNbmCB4LReF2tIE20EgUeWrz/87aVkpMihf3FVK+8DT45nyN4k9iSQOhsyem49fq++cF8w== dependencies: chalk "^1.1.3" hash-sum "^1.0.2" @@ -9864,10 +9864,10 @@ vue-style-loader@^4.1.0: hash-sum "^1.0.2" loader-utils "^1.0.2" -vue-template-compiler@2.5.22: - version "2.5.22" - resolved "https://registry.yarnpkg.com/vue-template-compiler/-/vue-template-compiler-2.5.22.tgz#c3d3c02c65f1908205c4fbd3b0ef579e51239955" - integrity sha512-1VTw/NPTUeHNiwhkq6NkFzO7gYLjFCueBN0FX8NEiQIemd5EUMQ5hxrF7O0zCPo5tae+U9S/scETPea+hIz8Eg== +vue-template-compiler@2.5.21: + version "2.5.21" + resolved "https://registry.yarnpkg.com/vue-template-compiler/-/vue-template-compiler-2.5.21.tgz#a57ceb903177e8f643560a8d639a0f8db647054a" + integrity sha512-Vmk5Cv7UcmI99B9nXJEkaK262IQNnHp5rJYo+EwYpe2epTAXqcVyExhV6pk8jTkxQK2vRc8v8KmZBAwdmUZvvw== dependencies: de-indent "^1.0.2" he "^1.1.0" @@ -9883,10 +9883,10 @@ vue-template-es2015-compiler@^1.6.0: version "1.6.0" resolved "https://registry.yarnpkg.com/vue-template-es2015-compiler/-/vue-template-es2015-compiler-1.6.0.tgz#dc42697133302ce3017524356a6c61b7b69b4a18" -vue@2.5.22: - version "2.5.22" - resolved "https://registry.yarnpkg.com/vue/-/vue-2.5.22.tgz#3bf88041af08b8539c37b268b70ca79245e9cc30" - integrity sha512-pxY3ZHlXNJMFQbkjEgGVMaMMkSV1ONpz+4qB55kZuJzyJOhn6MSy/YZdzhdnumegNzVTL/Dn3Pp4UrVBYt1j/g== +vue@2.5.21: + version "2.5.21" + resolved "https://registry.yarnpkg.com/vue/-/vue-2.5.21.tgz#3d33dcd03bb813912ce894a8303ab553699c4a85" + integrity sha512-Aejvyyfhn0zjVeLvXd70h4hrE4zZDx1wfZqia6ekkobLmUZ+vNFQer53B4fu0EjWBSiqApxPejzkO1Znt3joxQ== vue@^2.5.16: version "2.5.16" From 324e2de33b92f2710188bbf2f811f7bcf1c8e2cc Mon Sep 17 00:00:00 2001 From: eddyerburgh Date: Sat, 2 Feb 2019 17:10:38 +0000 Subject: [PATCH 10/10] refactor: use semver.lt function --- packages/test-utils/src/mount.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/test-utils/src/mount.js b/packages/test-utils/src/mount.js index cc3b46628..458aead11 100644 --- a/packages/test-utils/src/mount.js +++ b/packages/test-utils/src/mount.js @@ -23,11 +23,11 @@ function getSyncOption(syncOption) { Vue.config.async = true return false } - if (!semver.gt(Vue.version, '2.5.17')) { + if (semver.lt(Vue.version, '2.5.18')) { warn( `Vue Test Utils runs in sync mode by default. Due to bugs, sync mode ` + `requires Vue > 2.5.18. In Vue Test Utils 1.0 sync mode will only be ` + - `supported with Vue 2.5.18 running in development mode. If you are ` + + `supported with Vue 2.5.18+ running in development mode. If you are ` + `unable to upgrade, you should rewrite your tests to run asynchronously` + `you can do this by setting the sync mounting option to false.` )