From 0c07653ddff92fbbc8852256ee99e1c41476e6ab Mon Sep 17 00:00:00 2001 From: Edd Yerburgh Date: Sun, 3 Feb 2019 18:21:55 +0000 Subject: [PATCH] test: use sandbox to avoid memory leaks in test (#1128) --- package.json | 10 +- .../create-instance/create-component-stubs.js | 11 +- packages/create-instance/create-instance.js | 2 +- .../create-instance/patch-create-element.js | 1 + .../components/component-with-events.vue | 1 - .../components/recursive-component.vue | 4 +- test/specs/components/TransitionStub.spec.js | 9 +- test/specs/config.spec.js | 16 +- test/specs/error-wrapper.spec.js | 7 +- test/specs/mount.spec.js | 24 +- test/specs/mounting-options/attrs.spec.js | 8 +- test/specs/mounting-options/listeners.spec.js | 7 +- test/specs/mounting-options/localVue.spec.js | 2 +- test/specs/mounting-options/mocks.spec.js | 8 +- .../mounting-options/scopedSlots.spec.js | 6 +- test/specs/mounting-options/stubs.spec.js | 15 +- test/specs/mounting-options/sync.spec.js | 12 +- test/specs/shallow-mount.spec.js | 13 +- test/specs/wrapper-array.spec.js | 21 +- test/specs/wrapper-array/at.spec.js | 13 +- test/specs/wrapper-array/attributes.spec.js | 13 +- test/specs/wrapper-array/classes.spec.js | 13 +- test/specs/wrapper-array/contains.spec.js | 23 +- test/specs/wrapper-array/find.spec.js | 15 +- test/specs/wrapper-array/trigger.spec.js | 13 +- test/specs/wrapper/destroy.spec.js | 20 +- test/specs/wrapper/setData.spec.js | 9 +- test/specs/wrapper/setProps.spec.js | 10 +- test/specs/wrapper/trigger.spec.js | 23 +- yarn.lock | 266 ++++++++---------- 30 files changed, 305 insertions(+), 290 deletions(-) diff --git a/package.json b/package.json index 540112fd7..d7221678c 100644 --- a/package.json +++ b/package.json @@ -26,7 +26,7 @@ "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 && TARGET=browser karma start test/setup/karma.conf.js --single-run", "test:unit:node": "npm run build:test && npm run test:unit:node:only", - "test:unit:node:only": "TEST_ENV=node mocha-webpack --webpack-config test/setup/webpack.test.config.js test/specs --recursive --require test/setup/mocha.setup.js", + "test:unit:node:only": "cross-env TEST_ENV=node mocha-webpack --webpack-config test/setup/webpack.test.config.js test/specs --recursive --require test/setup/mocha.setup.js", "test:types": "tsc -p packages/test-utils/types && tsc -p packages/server-test-utils/types" }, "devDependencies": { @@ -54,18 +54,18 @@ "karma": "^1.7.0", "karma-mocha": "^1.3.0", "karma-phantomjs-launcher": "^1.0.4", - "karma-sinon-chai": "^1.3.1", + "karma-sinon-chai": "^2.0.2", "karma-sourcemap-loader": "^0.3.7", "karma-spec-reporter": "^0.0.31", "karma-webpack": "^2.0.3", "lerna": "2", "markdown-it-include": "^1.0.0", - "mocha": "^3.5.0", + "mocha": "^5.2.0", "mocha-webpack": "^1.0.1", "prettier": "^1.16.0", "rollup": "^0.58.2", - "sinon": "^2.3.2", - "sinon-chai": "^2.10.0", + "sinon": "^7.2.3", + "sinon-chai": "^3.3.0", "typescript": "^3.0.1", "vee-validate": "^2.1.3", "vue": "^2.5.22", diff --git a/packages/create-instance/create-component-stubs.js b/packages/create-instance/create-component-stubs.js index 70b275b17..d2dc4ce07 100644 --- a/packages/create-instance/create-component-stubs.js +++ b/packages/create-instance/create-component-stubs.js @@ -65,9 +65,13 @@ function resolveOptions(component, _Vue) { return {} } - return isConstructor(component) - ? component.options - : _Vue.extend(component).options + if (isConstructor(component)) { + return component.options + } + const options = _Vue.extend(component).options + component._Ctor = {} + + return options } export function createStubFromComponent( @@ -165,6 +169,7 @@ export function createStubsFromStubsObject( } acc[stubName] = stub + stub._Ctor = {} return acc }, {}) diff --git a/packages/create-instance/create-instance.js b/packages/create-instance/create-instance.js index bc859ce9f..562c1f852 100644 --- a/packages/create-instance/create-instance.js +++ b/packages/create-instance/create-instance.js @@ -74,7 +74,7 @@ export default function createInstance( // make sure all extends are based on this instance const Constructor = _Vue.extend(componentOptions).extend(instanceOptions) - + componentOptions._Ctor = {} Constructor.options._base = _Vue const scopedSlots = createScopedSlots(options.scopedSlots, _Vue) diff --git a/packages/create-instance/patch-create-element.js b/packages/create-instance/patch-create-element.js index dc152996e..3f234cca6 100644 --- a/packages/create-instance/patch-create-element.js +++ b/packages/create-instance/patch-create-element.js @@ -21,6 +21,7 @@ function shouldExtend(component, _Vue) { function extend(component, _Vue) { const componentOptions = component.options ? component.options : component const stub = _Vue.extend(componentOptions) + componentOptions._Ctor = {} stub.options.$_vueTestUtils_original = component stub.options._base = _Vue return stub diff --git a/test/resources/components/component-with-events.vue b/test/resources/components/component-with-events.vue index c3a207518..896c1a055 100644 --- a/test/resources/components/component-with-events.vue +++ b/test/resources/components/component-with-events.vue @@ -42,7 +42,6 @@ export default { mousedownHandler(event) { if (event.button === 0) { this.clickHandler() - console.info(event.defaultPrevented) } }, toggleActive() { diff --git a/test/resources/components/recursive-component.vue b/test/resources/components/recursive-component.vue index 1d19e0680..8c0a70b56 100644 --- a/test/resources/components/recursive-component.vue +++ b/test/resources/components/recursive-component.vue @@ -1,8 +1,8 @@