From 631e0a5e8b5bf6a03b62d8aa5b583f5089a28f95 Mon Sep 17 00:00:00 2001 From: Lachlan Miller Date: Thu, 29 Sep 2022 15:07:52 +1000 Subject: [PATCH 01/36] publish: 2.1.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 9dcbdca24..cdb342a07 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@vue/test-utils", - "version": "2.0.2", + "version": "2.1.0", "license": "MIT", "main": "dist/vue-test-utils.cjs.js", "unpkg": "dist/vue-test-utils.browser.js", From e754fd17885cdaca153461a3596d780725c2ba3d Mon Sep 17 00:00:00 2001 From: Illya Klymov Date: Sun, 2 Oct 2022 21:17:05 +0300 Subject: [PATCH 02/36] fix(compat): do not overwrite globalProperties merge them instead * globalProperties might not be empty due to them being gathered from Vue.prototype when using compat build --- src/mount.ts | 5 ++++- tests/features/compat.spec.ts | 18 +++++++++++++++++- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/src/mount.ts b/src/mount.ts index 36651e962..129ef1d38 100644 --- a/src/mount.ts +++ b/src/mount.ts @@ -30,6 +30,7 @@ import { import { MountingOptions, Slot } from './types' import { isFunctionalComponent, + isObject, isObjectComponent, mergeGlobalProperties } from './utils' @@ -474,7 +475,9 @@ export function mount( keyof Omit, any ][]) { - app.config[k] = v + app.config[k] = isObject(app.config[k]) + ? Object.assign(app.config[k]!, v) + : v } } diff --git a/tests/features/compat.spec.ts b/tests/features/compat.spec.ts index 92bf28ddf..34c337885 100644 --- a/tests/features/compat.spec.ts +++ b/tests/features/compat.spec.ts @@ -3,8 +3,9 @@ import * as mockVue from '@vue/compat' import { mount } from '../../src' vi.mock('vue', () => mockVue) - const { configureCompat, extend, defineComponent, h } = mockVue +// @ts-expect-error @vue/compat does not expose default export in types +const Vue = mockVue.default describe('@vue/compat build', () => { describe.each(['suppress-warning', false])( @@ -213,4 +214,19 @@ describe('@vue/compat build', () => { '
message
' ) }) + + it('does not erase globalProperties added by messing with Vue.prototype', () => { + configureCompat({ + MODE: 3, + GLOBAL_PROTOTYPE: 'suppress-warning' + }) + + Vue.prototype.$test = 1 + + const Component = { template: 'hello ' } + const wrapper = mount(Component) + + // @ts-expect-error $test "magically" appears from "Vue.prototype" in compat build + expect(wrapper.vm.$test).toBe(1) + }) }) From 6212c2cce8fcd5d72b0aff97867e1a15092de2d2 Mon Sep 17 00:00:00 2001 From: Illya Klymov Date: Mon, 3 Oct 2022 09:37:40 +0300 Subject: [PATCH 03/36] fix(element): return correct element * return correct element for component which renders other component while passing array of vnodes in default slot --- src/vueWrapper.ts | 12 ++++++------ tests/element.spec.ts | 10 ++++++++++ 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/src/vueWrapper.ts b/src/vueWrapper.ts index b398e12af..f0d2b5f0c 100644 --- a/src/vueWrapper.ts +++ b/src/vueWrapper.ts @@ -74,19 +74,19 @@ export class VueWrapper< const checkTree = (subTree: VNode): boolean => { // if the subtree is an array of children, we have multiple root nodes if (subTree.shapeFlag === ShapeFlags.ARRAY_CHILDREN) return true - if ( subTree.shapeFlag & ShapeFlags.STATEFUL_COMPONENT || subTree.shapeFlag & ShapeFlags.FUNCTIONAL_COMPONENT ) { - // Component has multiple children or slot with multiple children - if (subTree.shapeFlag & ShapeFlags.ARRAY_CHILDREN) { - return true - } - + // We are rendering other component, check it's tree instead if (subTree.component?.subTree) { return checkTree(subTree.component.subTree) } + + // Component has multiple children + if (subTree.shapeFlag & ShapeFlags.ARRAY_CHILDREN) { + return true + } } return false diff --git a/tests/element.spec.ts b/tests/element.spec.ts index 5e77ac720..d164caac0 100644 --- a/tests/element.spec.ts +++ b/tests/element.spec.ts @@ -105,4 +105,14 @@ describe('element', () => { '
foo
bar
baz
' ) }) + + it('returns correct element for component which renders other component with array of vnodes in default slot', () => { + const Nested = { + template: '
' + } + const Root = () => h(Nested, {}, [h('div', {}, 'foo'), h('div', {}, 'bar')]) + + const wrapper = mount(Root) + expect(wrapper.element.innerHTML).toBe('
foo
bar
') + }) }) From 5c1dceb268b00e856431088075bf7954689eebb6 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Mon, 3 Oct 2022 23:47:26 +0000 Subject: [PATCH 04/36] chore(deps): update dependency rollup-plugin-typescript2 to v0.34.1 --- package.json | 2 +- pnpm-lock.yaml | 9 +++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index cdb342a07..67a9f9b59 100644 --- a/package.json +++ b/package.json @@ -49,7 +49,7 @@ "pretty": "2.0.0", "reflect-metadata": "0.1.13", "rollup": "2.79.1", - "rollup-plugin-typescript2": "0.34.0", + "rollup-plugin-typescript2": "0.34.1", "tslib": "2.4.0", "typescript": "4.8.4", "unplugin-vue-components": "0.22.7", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index aa535f4ce..c4de2a354 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -28,7 +28,7 @@ specifiers: pretty: 2.0.0 reflect-metadata: 0.1.13 rollup: 2.79.1 - rollup-plugin-typescript2: 0.34.0 + rollup-plugin-typescript2: 0.34.1 tslib: 2.4.0 typescript: 4.8.4 unplugin-vue-components: 0.22.7 @@ -69,7 +69,7 @@ devDependencies: pretty: 2.0.0 reflect-metadata: 0.1.13 rollup: 2.79.1 - rollup-plugin-typescript2: 0.34.0_gypgyaqhine6mwjfvh7icfhviq + rollup-plugin-typescript2: 0.34.1_gypgyaqhine6mwjfvh7icfhviq tslib: 2.4.0 typescript: 4.8.4 unplugin-vue-components: 0.22.7_vue@3.2.40 @@ -3332,8 +3332,8 @@ packages: glob: 7.2.3 dev: true - /rollup-plugin-typescript2/0.34.0_gypgyaqhine6mwjfvh7icfhviq: - resolution: {integrity: sha512-dGtOz2kL6nQVgfIOmnA4Xh+5cFrs3bdu4jja/ej7WKR92RzOOixsn71LY5ZFFmKe1R677nUh+k2++NiY3un2PQ==} + /rollup-plugin-typescript2/0.34.1_gypgyaqhine6mwjfvh7icfhviq: + resolution: {integrity: sha512-P4cHLtGikESmqi1CA+tdMDUv8WbQV48mzPYt77TSTOPJpERyZ9TXdDgjSDix8Fkqce6soYz3+fa4lrC93IEkcw==} peerDependencies: rollup: '>=1.26.3' typescript: '>=2.4.0' @@ -3342,6 +3342,7 @@ packages: find-cache-dir: 3.3.2 fs-extra: 10.1.0 rollup: 2.79.1 + semver: 7.3.7 tslib: 2.4.0 typescript: 4.8.4 dev: true From 149e11f34474dde6025a5eb2727201968fd34d0a Mon Sep 17 00:00:00 2001 From: freakzlike Date: Tue, 4 Oct 2022 16:55:23 +0200 Subject: [PATCH 05/36] fix: cleanup event listeners on unmount --- src/vueWrapper.ts | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/vueWrapper.ts b/src/vueWrapper.ts index f0d2b5f0c..a20356e3f 100644 --- a/src/vueWrapper.ts +++ b/src/vueWrapper.ts @@ -35,6 +35,7 @@ export class VueWrapper< private rootVM: ComponentPublicInstance | undefined | null private __app: App | null private __setProps: ((props: Record) => void) | undefined + private cleanUpCallbacks: Array<() => void> = [] constructor( app: App | null, @@ -149,8 +150,12 @@ export class VueWrapper< // @see https://github.com/vuejs/rfcs/blob/master/active-rfcs/0030-emits-option.md#fallthrough-control if (emits.includes(eventName)) continue - element.addEventListener(eventName, (...args) => { + const eventListener: EventListener = (...args) => { recordEvent(vm.$, eventName, args) + } + element.addEventListener(eventName, eventListener) + this.cleanUpCallbacks.push(() => { + element.removeEventListener(eventName, eventListener) }) } } @@ -214,6 +219,9 @@ export class VueWrapper< // Clear emitted events cache for this component instance removeEventHistory(this.vm) + this.cleanUpCallbacks.forEach((cb) => cb()) + this.cleanUpCallbacks = [] + this.__app.unmount() } } From 47733580d0a96709dab4baf11e82f1a347b8f3e2 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Wed, 5 Oct 2022 01:51:10 +0000 Subject: [PATCH 06/36] chore(deps): update all non-major dependencies --- package.json | 8 +- pnpm-lock.yaml | 209 ++++++++++++++++++++++++------------------------- 2 files changed, 105 insertions(+), 112 deletions(-) diff --git a/package.json b/package.json index 67a9f9b59..df9d9ad85 100644 --- a/package.json +++ b/package.json @@ -28,9 +28,9 @@ "@rollup/plugin-replace": "4.0.0", "@types/node": "18.0.6", "@types/pretty": "2.0.1", - "@typescript-eslint/eslint-plugin": "5.38.1", - "@typescript-eslint/parser": "5.38.1", - "@vitejs/plugin-vue": "3.1.0", + "@typescript-eslint/eslint-plugin": "5.39.0", + "@typescript-eslint/parser": "5.39.0", + "@vitejs/plugin-vue": "3.1.2", "@vitejs/plugin-vue-jsx": "2.0.1", "@vitest/coverage-c8": "0.23.0", "@vue/compat": "3.2.40", @@ -42,7 +42,7 @@ "eslint-config-prettier": "8.5.0", "eslint-plugin-prettier": "4.2.1", "husky": "8.0.1", - "jsdom": "20.0.0", + "jsdom": "20.0.1", "jsdom-global": "3.0.2", "lint-staged": "13.0.3", "prettier": "2.7.1", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index c4de2a354..298dcba93 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -7,9 +7,9 @@ specifiers: '@rollup/plugin-replace': 4.0.0 '@types/node': 18.0.6 '@types/pretty': 2.0.1 - '@typescript-eslint/eslint-plugin': 5.38.1 - '@typescript-eslint/parser': 5.38.1 - '@vitejs/plugin-vue': 3.1.0 + '@typescript-eslint/eslint-plugin': 5.39.0 + '@typescript-eslint/parser': 5.39.0 + '@vitejs/plugin-vue': 3.1.2 '@vitejs/plugin-vue-jsx': 2.0.1 '@vitest/coverage-c8': 0.23.0 '@vue/compat': 3.2.40 @@ -21,7 +21,7 @@ specifiers: eslint-config-prettier: 8.5.0 eslint-plugin-prettier: 4.2.1 husky: 8.0.1 - jsdom: 20.0.0 + jsdom: 20.0.1 jsdom-global: 3.0.2 lint-staged: 13.0.3 prettier: 2.7.1 @@ -48,11 +48,11 @@ devDependencies: '@rollup/plugin-replace': 4.0.0_rollup@2.79.1 '@types/node': 18.0.6 '@types/pretty': 2.0.1 - '@typescript-eslint/eslint-plugin': 5.38.1_c7qepppml3d4ahu5cnfwqe6ltq - '@typescript-eslint/parser': 5.38.1_ypn2ylkkyfa5i233caldtndbqa - '@vitejs/plugin-vue': 3.1.0_vite@3.1.4+vue@3.2.40 + '@typescript-eslint/eslint-plugin': 5.39.0_xyciw6oqjoiiono4dhv3uhn5my + '@typescript-eslint/parser': 5.39.0_ypn2ylkkyfa5i233caldtndbqa + '@vitejs/plugin-vue': 3.1.2_vite@3.1.4+vue@3.2.40 '@vitejs/plugin-vue-jsx': 2.0.1_vite@3.1.4+vue@3.2.40 - '@vitest/coverage-c8': 0.23.0_jsdom@20.0.0 + '@vitest/coverage-c8': 0.23.0_jsdom@20.0.1 '@vue/compat': 3.2.40_vue@3.2.40 '@vue/compiler-dom': 3.2.40 '@vue/compiler-sfc': 3.2.40 @@ -62,8 +62,8 @@ devDependencies: eslint-config-prettier: 8.5.0_eslint@8.24.0 eslint-plugin-prettier: 4.2.1_cfn5x6ujhhgzv3423d6k7r2zzm husky: 8.0.1 - jsdom: 20.0.0 - jsdom-global: 3.0.2_jsdom@20.0.0 + jsdom: 20.0.1 + jsdom-global: 3.0.2_jsdom@20.0.1 lint-staged: 13.0.3 prettier: 2.7.1 pretty: 2.0.0 @@ -75,7 +75,7 @@ devDependencies: unplugin-vue-components: 0.22.7_vue@3.2.40 vite: 3.1.4 vitepress: 0.22.4 - vitest: 0.22.1_jsdom@20.0.0 + vitest: 0.22.1_jsdom@20.0.1 vue: 3.2.40 vue-class-component: 8.0.0-rc.1_vue@3.2.40 vue-router: 4.1.5_vue@3.2.40 @@ -778,8 +778,8 @@ packages: '@types/node': 18.0.6 dev: true - /@typescript-eslint/eslint-plugin/5.38.1_c7qepppml3d4ahu5cnfwqe6ltq: - resolution: {integrity: sha512-ky7EFzPhqz3XlhS7vPOoMDaQnQMn+9o5ICR9CPr/6bw8HrFkzhMSxuA3gRfiJVvs7geYrSeawGJjZoZQKCOglQ==} + /@typescript-eslint/eslint-plugin/5.39.0_xyciw6oqjoiiono4dhv3uhn5my: + resolution: {integrity: sha512-xVfKOkBm5iWMNGKQ2fwX5GVgBuHmZBO1tCRwXmY5oAIsPscfwm2UADDuNB8ZVYCtpQvJK4xpjrK7jEhcJ0zY9A==} engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0} peerDependencies: '@typescript-eslint/parser': ^5.0.0 @@ -789,10 +789,10 @@ packages: typescript: optional: true dependencies: - '@typescript-eslint/parser': 5.38.1_ypn2ylkkyfa5i233caldtndbqa - '@typescript-eslint/scope-manager': 5.38.1 - '@typescript-eslint/type-utils': 5.38.1_ypn2ylkkyfa5i233caldtndbqa - '@typescript-eslint/utils': 5.38.1_ypn2ylkkyfa5i233caldtndbqa + '@typescript-eslint/parser': 5.39.0_ypn2ylkkyfa5i233caldtndbqa + '@typescript-eslint/scope-manager': 5.39.0 + '@typescript-eslint/type-utils': 5.39.0_ypn2ylkkyfa5i233caldtndbqa + '@typescript-eslint/utils': 5.39.0_ypn2ylkkyfa5i233caldtndbqa debug: 4.3.4 eslint: 8.24.0 ignore: 5.2.0 @@ -804,8 +804,8 @@ packages: - supports-color dev: true - /@typescript-eslint/parser/5.38.1_ypn2ylkkyfa5i233caldtndbqa: - resolution: {integrity: sha512-LDqxZBVFFQnQRz9rUZJhLmox+Ep5kdUmLatLQnCRR6523YV+XhRjfYzStQ4MheFA8kMAfUlclHSbu+RKdRwQKw==} + /@typescript-eslint/parser/5.39.0_ypn2ylkkyfa5i233caldtndbqa: + resolution: {integrity: sha512-PhxLjrZnHShe431sBAGHaNe6BDdxAASDySgsBCGxcBecVCi8NQWxQZMcizNA4g0pN51bBAn/FUfkWG3SDVcGlA==} engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0} peerDependencies: eslint: ^6.0.0 || ^7.0.0 || ^8.0.0 @@ -814,9 +814,9 @@ packages: typescript: optional: true dependencies: - '@typescript-eslint/scope-manager': 5.38.1 - '@typescript-eslint/types': 5.38.1 - '@typescript-eslint/typescript-estree': 5.38.1_typescript@4.8.4 + '@typescript-eslint/scope-manager': 5.39.0 + '@typescript-eslint/types': 5.39.0 + '@typescript-eslint/typescript-estree': 5.39.0_typescript@4.8.4 debug: 4.3.4 eslint: 8.24.0 typescript: 4.8.4 @@ -824,16 +824,16 @@ packages: - supports-color dev: true - /@typescript-eslint/scope-manager/5.38.1: - resolution: {integrity: sha512-BfRDq5RidVU3RbqApKmS7RFMtkyWMM50qWnDAkKgQiezRtLKsoyRKIvz1Ok5ilRWeD9IuHvaidaLxvGx/2eqTQ==} + /@typescript-eslint/scope-manager/5.39.0: + resolution: {integrity: sha512-/I13vAqmG3dyqMVSZPjsbuNQlYS082Y7OMkwhCfLXYsmlI0ca4nkL7wJ/4gjX70LD4P8Hnw1JywUVVAwepURBw==} engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0} dependencies: - '@typescript-eslint/types': 5.38.1 - '@typescript-eslint/visitor-keys': 5.38.1 + '@typescript-eslint/types': 5.39.0 + '@typescript-eslint/visitor-keys': 5.39.0 dev: true - /@typescript-eslint/type-utils/5.38.1_ypn2ylkkyfa5i233caldtndbqa: - resolution: {integrity: sha512-UU3j43TM66gYtzo15ivK2ZFoDFKKP0k03MItzLdq0zV92CeGCXRfXlfQX5ILdd4/DSpHkSjIgLLLh1NtkOJOAw==} + /@typescript-eslint/type-utils/5.39.0_ypn2ylkkyfa5i233caldtndbqa: + resolution: {integrity: sha512-KJHJkOothljQWzR3t/GunL0TPKY+fGJtnpl+pX+sJ0YiKTz3q2Zr87SGTmFqsCMFrLt5E0+o+S6eQY0FAXj9uA==} engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0} peerDependencies: eslint: '*' @@ -842,8 +842,8 @@ packages: typescript: optional: true dependencies: - '@typescript-eslint/typescript-estree': 5.38.1_typescript@4.8.4 - '@typescript-eslint/utils': 5.38.1_ypn2ylkkyfa5i233caldtndbqa + '@typescript-eslint/typescript-estree': 5.39.0_typescript@4.8.4 + '@typescript-eslint/utils': 5.39.0_ypn2ylkkyfa5i233caldtndbqa debug: 4.3.4 eslint: 8.24.0 tsutils: 3.21.0_typescript@4.8.4 @@ -852,13 +852,13 @@ packages: - supports-color dev: true - /@typescript-eslint/types/5.38.1: - resolution: {integrity: sha512-QTW1iHq1Tffp9lNfbfPm4WJabbvpyaehQ0SrvVK2yfV79SytD9XDVxqiPvdrv2LK7DGSFo91TB2FgWanbJAZXg==} + /@typescript-eslint/types/5.39.0: + resolution: {integrity: sha512-gQMZrnfEBFXK38hYqt8Lkwt8f4U6yq+2H5VDSgP/qiTzC8Nw8JO3OuSUOQ2qW37S/dlwdkHDntkZM6SQhKyPhw==} engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0} dev: true - /@typescript-eslint/typescript-estree/5.38.1_typescript@4.8.4: - resolution: {integrity: sha512-99b5e/Enoe8fKMLdSuwrfH/C0EIbpUWmeEKHmQlGZb8msY33qn1KlkFww0z26o5Omx7EVjzVDCWEfrfCDHfE7g==} + /@typescript-eslint/typescript-estree/5.39.0_typescript@4.8.4: + resolution: {integrity: sha512-qLFQP0f398sdnogJoLtd43pUgB18Q50QSA+BTE5h3sUxySzbWDpTSdgt4UyxNSozY/oDK2ta6HVAzvGgq8JYnA==} engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0} peerDependencies: typescript: '*' @@ -866,8 +866,8 @@ packages: typescript: optional: true dependencies: - '@typescript-eslint/types': 5.38.1 - '@typescript-eslint/visitor-keys': 5.38.1 + '@typescript-eslint/types': 5.39.0 + '@typescript-eslint/visitor-keys': 5.39.0 debug: 4.3.4 globby: 11.1.0 is-glob: 4.0.3 @@ -878,16 +878,16 @@ packages: - supports-color dev: true - /@typescript-eslint/utils/5.38.1_ypn2ylkkyfa5i233caldtndbqa: - resolution: {integrity: sha512-oIuUiVxPBsndrN81oP8tXnFa/+EcZ03qLqPDfSZ5xIJVm7A9V0rlkQwwBOAGtrdN70ZKDlKv+l1BeT4eSFxwXA==} + /@typescript-eslint/utils/5.39.0_ypn2ylkkyfa5i233caldtndbqa: + resolution: {integrity: sha512-+DnY5jkpOpgj+EBtYPyHRjXampJfC0yUZZzfzLuUWVZvCuKqSdJVC8UhdWipIw7VKNTfwfAPiOWzYkAwuIhiAg==} engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0} peerDependencies: eslint: ^6.0.0 || ^7.0.0 || ^8.0.0 dependencies: '@types/json-schema': 7.0.11 - '@typescript-eslint/scope-manager': 5.38.1 - '@typescript-eslint/types': 5.38.1 - '@typescript-eslint/typescript-estree': 5.38.1_typescript@4.8.4 + '@typescript-eslint/scope-manager': 5.39.0 + '@typescript-eslint/types': 5.39.0 + '@typescript-eslint/typescript-estree': 5.39.0_typescript@4.8.4 eslint: 8.24.0 eslint-scope: 5.1.1 eslint-utils: 3.0.0_eslint@8.24.0 @@ -896,11 +896,11 @@ packages: - typescript dev: true - /@typescript-eslint/visitor-keys/5.38.1: - resolution: {integrity: sha512-bSHr1rRxXt54+j2n4k54p4fj8AHJ49VDWtjpImOpzQj4qjAiOpPni+V1Tyajh19Api1i844F757cur8wH3YvOA==} + /@typescript-eslint/visitor-keys/5.39.0: + resolution: {integrity: sha512-yyE3RPwOG+XJBLrhvsxAidUgybJVQ/hG8BhiJo0k8JSAYfk/CshVcxf0HwP4Jt7WZZ6vLmxdo1p6EyN3tzFTkg==} engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0} dependencies: - '@typescript-eslint/types': 5.38.1 + '@typescript-eslint/types': 5.39.0 eslint-visitor-keys: 3.3.0 dev: true @@ -932,8 +932,8 @@ packages: vue: 3.2.40 dev: true - /@vitejs/plugin-vue/3.1.0_vite@3.1.4+vue@3.2.40: - resolution: {integrity: sha512-fmxtHPjSOEIRg6vHYDaem+97iwCUg/uSIaTzp98lhELt2ISOQuDo2hbkBdXod0g15IhfPMQmAxh4heUks2zvDA==} + /@vitejs/plugin-vue/3.1.2_vite@3.1.4+vue@3.2.40: + resolution: {integrity: sha512-3zxKNlvA3oNaKDYX0NBclgxTQ1xaFdL7PzwF6zj9tGFziKwmBa3Q/6XcJQxudlT81WxDjEhHmevvIC4Orc1LhQ==} engines: {node: ^14.18.0 || >=16.0.0} peerDependencies: vite: ^3.0.0 @@ -943,11 +943,11 @@ packages: vue: 3.2.40 dev: true - /@vitest/coverage-c8/0.23.0_jsdom@20.0.0: + /@vitest/coverage-c8/0.23.0_jsdom@20.0.1: resolution: {integrity: sha512-8vhn1xViCNI1rx8dzncuzePZsN2eiQN8xFtsXy4sW2nZjH4UcIQlD1nwIY6Yei/RwFalay9F1sq588a/OPMjwg==} dependencies: c8: 7.12.0 - vitest: 0.23.0_jsdom@20.0.0 + vitest: 0.23.0_jsdom@20.0.1 transitivePeerDependencies: - '@edge-runtime/vm' - '@vitest/browser' @@ -1145,11 +1145,11 @@ packages: resolution: {integrity: sha512-nne9/IiQ/hzIhY6pdDnbBtz7DjPTKrY00P/zvPSm5pOFkl6xuGrGnXn/VtTNNfNtAfZ9/1RtehkszU9qcTii0Q==} dev: true - /acorn-globals/6.0.0: - resolution: {integrity: sha512-ZQl7LOWaF5ePqqcX4hLuv/bLXYQNfNWw2c0/yX/TsPRKamzHcTGQnlCjHT3TsmkOUVEPS3crCxiPfdzE/Trlhg==} + /acorn-globals/7.0.1: + resolution: {integrity: sha512-umOSDSDrfHbTNPuNpC2NSnnA3LUrqpevPb4T9jRx4MagXNS0rs+gwiTcAvqCRmsD6utzsrzNt+ebm00SNWiC3Q==} dependencies: - acorn: 7.4.1 - acorn-walk: 7.2.0 + acorn: 8.8.0 + acorn-walk: 8.2.0 dev: true /acorn-jsx/5.3.2_acorn@8.8.0: @@ -1160,21 +1160,9 @@ packages: acorn: 8.8.0 dev: true - /acorn-walk/7.2.0: - resolution: {integrity: sha512-OPdCF6GsMIP+Az+aWfAAOEt2/+iVDKE7oy6lJ098aoe59oAmK76qV6Gw60SbZ8jHuG2wH058GF4pLFbYamYrVA==} - engines: {node: '>=0.4.0'} - dev: true - - /acorn/7.4.1: - resolution: {integrity: sha512-nQyp0o1/mNdbTO1PO6kHkwSrmgZ0MT/jCCpNiwbUjGoRN4dlBhqJtoQuCnEOKzgTVwg0ZWiCoQy6SxMebQVh8A==} + /acorn-walk/8.2.0: + resolution: {integrity: sha512-k+iyHEuPgSw6SbuDpGQM+06HQUa04DZ3o+F6CSzXMvvI5KMvnaEqXe+YVe555R9nn6GPt404fos4wcgpw12SDA==} engines: {node: '>=0.4.0'} - hasBin: true - dev: true - - /acorn/8.7.1: - resolution: {integrity: sha512-Xx54uLJQZ19lKygFXOWsscKUbsBZW0CPykPhVQdhIeIwrbPmJzqeASDInc8nKBnp/JT6igTs82qPXz069H8I/A==} - engines: {node: '>=0.4.0'} - hasBin: true dev: true /acorn/8.8.0: @@ -1323,10 +1311,6 @@ packages: fill-range: 7.0.1 dev: true - /browser-process-hrtime/1.0.0: - resolution: {integrity: sha512-9o5UecI3GhkpM6DrXr69PblIuWxPKk9Y0jHBRhdocZ2y7YECBFCsHm79Pr3OyR2AvjhDkabFJaDJMYRazHgsow==} - dev: true - /browserslist/4.21.1: resolution: {integrity: sha512-Nq8MFCSrnJXSc88yliwlzQe3qNe3VntIjhsArW9IJOEPSHNx23FalwApUVbzAWABLhYJJ7y8AynWI/XM8OdfjQ==} engines: {node: ^6 || ^7 || ^8 || ^9 || ^10 || ^11 || ^12 || >=13.7} @@ -1581,8 +1565,8 @@ packages: ms: 2.1.2 dev: true - /decimal.js/10.3.1: - resolution: {integrity: sha512-V0pfhfr8suzyPGOx3nmq4aHqabehUZn6Ch9kyFpV79TGDTWFmHqUqXdabR7QHqxzrYolF4+tVmJhUG4OURg5dQ==} + /decimal.js/10.4.1: + resolution: {integrity: sha512-F29o+vci4DodHYT9UrR5IEbfBw9pE5eSapIJdTqXK5+6hq+t8VRxwQyKlW2i+KDKFkkJQRvFyI/QXD83h8LyQw==} dev: true /deep-eql/3.0.1: @@ -1653,8 +1637,8 @@ packages: resolution: {integrity: sha512-L18DaJsXSUk2+42pv8mLs5jJT2hqFkFE4j21wOmgbUqsZ2hL72NsUU785g9RXgo3s0ZNgVl42TiHp3ZtOv/Vyg==} dev: true - /entities/4.3.1: - resolution: {integrity: sha512-o4q/dYJlmyjP2zfnaWDUC6A3BQFmVTX+tZPezK7k0GLSU9QYCauscf5Y+qcEPzKL+EixVouYDgLQK5H9GrLpkg==} + /entities/4.4.0: + resolution: {integrity: sha512-oYp7156SP8LkeGD0GF85ad1X9Ai79WtRsZ2gxJqtBuzH+98YUV6jkHEKlZkMbcrjJjIVJNIDP/3WL9wQkoPbWA==} engines: {node: '>=0.12'} dev: true @@ -2731,16 +2715,16 @@ packages: argparse: 2.0.1 dev: true - /jsdom-global/3.0.2_jsdom@20.0.0: + /jsdom-global/3.0.2_jsdom@20.0.1: resolution: {integrity: sha512-t1KMcBkz/pT5JrvcJbpUR2u/w1kO9jXctaaGJ0vZDzwFnIvGWw9IDSRciT83kIs8Bnw4qpOl8bQK08V01YgMPg==} peerDependencies: jsdom: '>=10.0.0' dependencies: - jsdom: 20.0.0 + jsdom: 20.0.1 dev: true - /jsdom/20.0.0: - resolution: {integrity: sha512-x4a6CKCgx00uCmP+QakBDFXwjAJ69IkkIWHmtmjd3wvXPcdOS44hfX2vqkOQrVrq8l9DhNNADZRXaCEWvgXtVA==} + /jsdom/20.0.1: + resolution: {integrity: sha512-pksjj7Rqoa+wdpkKcLzQRHhJCEE42qQhl/xLMUKHgoSejaKOdaXEAnqs6uDNwMl/fciHTzKeR8Wm8cw7N+g98A==} engines: {node: '>=14'} peerDependencies: canvas: ^2.5.0 @@ -2749,12 +2733,12 @@ packages: optional: true dependencies: abab: 2.0.6 - acorn: 8.7.1 - acorn-globals: 6.0.0 + acorn: 8.8.0 + acorn-globals: 7.0.1 cssom: 0.5.0 cssstyle: 2.3.0 data-urls: 3.0.2 - decimal.js: 10.3.1 + decimal.js: 10.4.1 domexception: 4.0.0 escodegen: 2.0.0 form-data: 4.0.0 @@ -2762,18 +2746,17 @@ packages: http-proxy-agent: 5.0.0 https-proxy-agent: 5.0.1 is-potential-custom-element-name: 1.0.1 - nwsapi: 2.2.1 - parse5: 7.0.0 + nwsapi: 2.2.2 + parse5: 7.1.1 saxes: 6.0.0 symbol-tree: 3.2.4 - tough-cookie: 4.0.0 - w3c-hr-time: 1.0.2 + tough-cookie: 4.1.2 w3c-xmlserializer: 3.0.0 webidl-conversions: 7.0.0 whatwg-encoding: 2.0.0 whatwg-mimetype: 3.0.0 whatwg-url: 11.0.0 - ws: 8.8.0 + ws: 8.9.0 xml-name-validator: 4.0.0 transitivePeerDependencies: - bufferutil @@ -3042,8 +3025,8 @@ packages: path-key: 4.0.0 dev: true - /nwsapi/2.2.1: - resolution: {integrity: sha512-JYOWTeFoS0Z93587vRJgASD5Ut11fYl5NyihP3KrYBvMe1FRRs6RN7m20SA/16GM4P6hTnZjT+UmDOt38UeXNg==} + /nwsapi/2.2.2: + resolution: {integrity: sha512-90yv+6538zuvUMnN+zCr8LuV6bPFdq50304114vJYJ8RDyK8D5O9Phpbd6SZWgI7PwzmmfN1upeOJlvybDSgCw==} dev: true /object-inspect/1.12.2: @@ -3141,10 +3124,10 @@ packages: callsites: 3.1.0 dev: true - /parse5/7.0.0: - resolution: {integrity: sha512-y/t8IXSPWTuRZqXc0ajH/UwDj4mnqLEbSttNbThcFhGrZuOyoyvNBO85PBp2jQa55wY9d07PBNjsK8ZP3K5U6g==} + /parse5/7.1.1: + resolution: {integrity: sha512-kwpuwzB+px5WUg9pyK0IcK/shltJN5/OVhQagxhCQNtT9Y9QRZqNY2e1cmbu/paRh5LMnz/oVTVLBpjFmMZhSg==} dependencies: - entities: 4.3.1 + entities: 4.4.0 dev: true /path-exists/4.0.0: @@ -3269,6 +3252,10 @@ packages: engines: {node: '>=6'} dev: true + /querystringify/2.2.0: + resolution: {integrity: sha512-FIqgj2EUvTa7R50u0rGsyTftzjYmv/a3hO345bZNrqabNqjtgiDMgmo4mkUjd+nzU5oF3dClKqFIPUKybUyqoQ==} + dev: true + /queue-microtask/1.2.3: resolution: {integrity: sha512-NuaNSa6flKT5JaSYQzJok04JzTL1CA6aGhv5rfLW3PgqA+M2ChpZQnAC8h8i4ZFkBS8X5RqkDBHA7r4hej3K9A==} dev: true @@ -3294,6 +3281,10 @@ packages: engines: {node: '>=0.10.0'} dev: true + /requires-port/1.0.0: + resolution: {integrity: sha512-KigOCHcocU3XODJxsu8i/j8T9tzT4adHiecwORRQ0ZZFcp7ahwXuRU1m+yuO90C5ZUyGeGfocHDI14M3L3yDAQ==} + dev: true + /resolve-from/4.0.0: resolution: {integrity: sha512-pb/MYmXstAkysRFx8piNI1tGFNQIFA3vkE3Gq4EuA1dF6gHp/+vgZqsCGJapvy8N3Q+4o7FwvquPJcnZ7RYy4g==} engines: {node: '>=4'} @@ -3597,13 +3588,14 @@ packages: is-number: 7.0.0 dev: true - /tough-cookie/4.0.0: - resolution: {integrity: sha512-tHdtEpQCMrc1YLrMaqXXcj6AxhYi/xgit6mZu1+EDWUn+qhUf8wMQoFIy9NXuq23zAwtcB0t/MjACGR18pcRbg==} + /tough-cookie/4.1.2: + resolution: {integrity: sha512-G9fqXWoYFZgTc2z8Q5zaHy/vJMjm+WV0AkAeHxVCQiEB1b+dGvWzFW6QV07cY5jQ5gRkeid2qIkzkxUnmoQZUQ==} engines: {node: '>=6'} dependencies: psl: 1.9.0 punycode: 2.1.1 - universalify: 0.1.2 + universalify: 0.2.0 + url-parse: 1.5.10 dev: true /tr46/3.0.0: @@ -3666,8 +3658,8 @@ packages: hasBin: true dev: true - /universalify/0.1.2: - resolution: {integrity: sha512-rBJeI5CXAlmy1pV+617WB9J63U6XcazHHF2f2dbJix4XzpUF0RS3Zbj0FGIOCAva5P/d/GBOYaACQ1w+0azUkg==} + /universalify/0.2.0: + resolution: {integrity: sha512-CJ1QgKmNg3CwvAv/kOFmtnEN05f0D/cn9QntgNOQlQF9dgvVTHj3t+8JPdjqawCHk7V/KA+fbUqzZ9XWhcqPUg==} engines: {node: '>= 4.0.0'} dev: true @@ -3727,6 +3719,13 @@ packages: punycode: 2.1.1 dev: true + /url-parse/1.5.10: + resolution: {integrity: sha512-WypcfiRhfeUP9vvF0j6rw0J3hrWrw6iZv3+22h6iRMJ/8z1Tj6XfLP4DsUix5MhMPnXpiHDoKyoZ/bdCkwBCiQ==} + dependencies: + querystringify: 2.2.0 + requires-port: 1.0.0 + dev: true + /v8-to-istanbul/9.0.1: resolution: {integrity: sha512-74Y4LqY74kLE6IFyIjPtkSTWzUZmj8tdHT9Ii/26dvQ6K9Dl2NbEfj0XgU2sHCtKgt5VupqhlO/5aWuqS+IY1w==} engines: {node: '>=10.12.0'} @@ -3808,7 +3807,7 @@ packages: - stylus dev: true - /vitest/0.22.1_jsdom@20.0.0: + /vitest/0.22.1_jsdom@20.0.1: resolution: {integrity: sha512-+x28YTnSLth4KbXg7MCzoDAzPJlJex7YgiZbUh6YLp0/4PqVZ7q7/zyfdL0OaPtKTpNiQFPpMC8Y2MSzk8F7dw==} engines: {node: '>=v14.16.0'} hasBin: true @@ -3835,7 +3834,7 @@ packages: '@types/node': 18.0.6 chai: 4.3.6 debug: 4.3.4 - jsdom: 20.0.0 + jsdom: 20.0.1 local-pkg: 0.4.2 tinypool: 0.2.4 tinyspy: 1.0.2 @@ -3848,7 +3847,7 @@ packages: - terser dev: true - /vitest/0.23.0_jsdom@20.0.0: + /vitest/0.23.0_jsdom@20.0.1: resolution: {integrity: sha512-I3ctlfiXYprA2tID1qP+m6pmgmKx3HYfRe66MetGOHKCHLY7hz74ihiwIEtN7LReJgF3U5cM735iYPkn/Go1iQ==} engines: {node: '>=v14.16.0'} hasBin: true @@ -3875,7 +3874,7 @@ packages: '@types/node': 18.0.6 chai: 4.3.6 debug: 4.3.4 - jsdom: 20.0.0 + jsdom: 20.0.1 local-pkg: 0.4.2 strip-literal: 0.4.0 tinybench: 2.1.4 @@ -3937,12 +3936,6 @@ packages: vue: 3.2.40 dev: true - /w3c-hr-time/1.0.2: - resolution: {integrity: sha512-z8P5DvDNjKDoFIHK7q8r8lackT6l+jo/Ye3HOle7l9nICP9lf1Ci25fy9vHd0JOWewkIFzXIEig3TdKT7JQ5fQ==} - dependencies: - browser-process-hrtime: 1.0.0 - dev: true - /w3c-xmlserializer/3.0.0: resolution: {integrity: sha512-3WFqGEgSXIyGhOmAFtlicJNMjEps8b1MG31NCA0/vOF9+nKMUW1ckhi9cnNHmf88Rzw5V+dwIwsm2C7X8k9aQg==} engines: {node: '>=12'} @@ -4019,8 +4012,8 @@ packages: resolution: {integrity: sha512-l4Sp/DRseor9wL6EvV2+TuQn63dMkPjZ/sp9XkghTEbV9KlPS1xUsZ3u7/IQO4wxtcFB4bgpQPRcR3QCvezPcQ==} dev: true - /ws/8.8.0: - resolution: {integrity: sha512-JDAgSYQ1ksuwqfChJusw1LSJ8BizJ2e/vVu5Lxjq3YvNJNlROv1ui4i+c/kUUrPheBvQl4c5UbERhTwKa6QBJQ==} + /ws/8.9.0: + resolution: {integrity: sha512-Ja7nszREasGaYUYCI2k4lCKIRTt+y7XuqVoHR44YpI49TtryyqbqvDMn5eqfW7e6HzTukDRIsXqzVHScqRcafg==} engines: {node: '>=10.0.0'} peerDependencies: bufferutil: ^4.0.1 From 77bfbe2ee2370dcf329b4f420bc2a03e1088457f Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Wed, 5 Oct 2022 10:22:29 +0000 Subject: [PATCH 07/36] chore(deps): update dependency unplugin-vue-components to v0.22.8 --- package.json | 2 +- pnpm-lock.yaml | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/package.json b/package.json index df9d9ad85..bcfce762a 100644 --- a/package.json +++ b/package.json @@ -52,7 +52,7 @@ "rollup-plugin-typescript2": "0.34.1", "tslib": "2.4.0", "typescript": "4.8.4", - "unplugin-vue-components": "0.22.7", + "unplugin-vue-components": "0.22.8", "vite": "3.1.4", "vitepress": "0.22.4", "vitest": "0.22.1", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 298dcba93..8c750b53a 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -31,7 +31,7 @@ specifiers: rollup-plugin-typescript2: 0.34.1 tslib: 2.4.0 typescript: 4.8.4 - unplugin-vue-components: 0.22.7 + unplugin-vue-components: 0.22.8 vite: 3.1.4 vitepress: 0.22.4 vitest: 0.22.1 @@ -72,7 +72,7 @@ devDependencies: rollup-plugin-typescript2: 0.34.1_gypgyaqhine6mwjfvh7icfhviq tslib: 2.4.0 typescript: 4.8.4 - unplugin-vue-components: 0.22.7_vue@3.2.40 + unplugin-vue-components: 0.22.8_vue@3.2.40 vite: 3.1.4 vitepress: 0.22.4 vitest: 0.22.1_jsdom@20.0.1 @@ -2921,8 +2921,8 @@ packages: sourcemap-codec: 1.4.8 dev: true - /magic-string/0.26.4: - resolution: {integrity: sha512-e5uXtVJ22aEpK9u1+eQf0fSxHeqwyV19K+uGnlROCxUhzwRip9tBsaMViK/0vC3viyPd5Gtucp3UmEp/Q2cPTQ==} + /magic-string/0.26.5: + resolution: {integrity: sha512-yXUIYOOQnEHKHOftp5shMWpB9ImfgfDJpapa38j/qMtTj5QHWucvxP4lUtuRmHT9vAzvtpHkWKXW9xBwimXeNg==} engines: {node: '>=12'} dependencies: sourcemap-codec: 1.4.8 @@ -3668,8 +3668,8 @@ packages: engines: {node: '>= 10.0.0'} dev: true - /unplugin-vue-components/0.22.7_vue@3.2.40: - resolution: {integrity: sha512-MJEAKJF9bRykTRvJ4WXF0FNMAyt1PX3iwpu2NN+li35sAKjQv6sC1col5aZDLiwDZDo2AGwxNkzLJFKaun9qHw==} + /unplugin-vue-components/0.22.8_vue@3.2.40: + resolution: {integrity: sha512-Musnwdtr6uj9Zopo4oeh4lp9+fJ2ArXVDzSiZxF4YC9v+pLnasKVKEEAjdXuQQ3u3KtntVw6PCscyAt52eS75g==} engines: {node: '>=14'} peerDependencies: '@babel/parser': ^7.15.8 @@ -3684,7 +3684,7 @@ packages: debug: 4.3.4 fast-glob: 3.2.12 local-pkg: 0.4.2 - magic-string: 0.26.4 + magic-string: 0.26.5 minimatch: 5.1.0 resolve: 1.22.1 unplugin: 0.9.6 From 5c59fa29983ce6f39200efdf9958a7a5ce455ba8 Mon Sep 17 00:00:00 2001 From: Marco Weber <49274286+mrcwbr@users.noreply.github.com> Date: Thu, 6 Oct 2022 17:55:32 +0200 Subject: [PATCH 08/36] docs: added typescript documentation to plugins.md (#1796) --- docs/guide/extending-vtu/plugins.md | 19 ++++++++++++++++--- src/baseWrapper.ts | 2 +- src/vueWrapper.ts | 10 ++++++---- 3 files changed, 23 insertions(+), 8 deletions(-) diff --git a/docs/guide/extending-vtu/plugins.md b/docs/guide/extending-vtu/plugins.md index 921ea30dc..8e908f07f 100644 --- a/docs/guide/extending-vtu/plugins.md +++ b/docs/guide/extending-vtu/plugins.md @@ -6,9 +6,9 @@ functionality. Some use cases for plugins: -1. Aliasing existing public methods -1. Attaching matchers to the Wrapper instance -1. Attaching functionality to the Wrapper +1. Aliasing existing public methods +2. Attaching matchers to the Wrapper instance +3. Attaching functionality to the Wrapper ## Wrapper Plugin @@ -168,6 +168,19 @@ const wrapper = mount(Component, { }) ``` +## Using the plugin with TypeScript + +To use your custom wrapper plugin with [TypeScript](https://www.typescriptlang.org/) you have to declare your custom wrapper function. Therefore, add a file named `vue-test-utils.d.ts` with the following content: +```typescript +import { DOMWrapper } from '@vue/test-utils'; + +declare module '@vue/test-utils' { + export class VueWrapper { + findByTestId(testId: string): DOMWrapper[]; + } +} +``` + ## Featuring Your Plugin If you're missing functionality, consider writing a plugin to extend Vue Test diff --git a/src/baseWrapper.ts b/src/baseWrapper.ts index 662941fe2..03150e34e 100644 --- a/src/baseWrapper.ts +++ b/src/baseWrapper.ts @@ -41,7 +41,7 @@ export default abstract class BaseWrapper return this.wrapperElement } - constructor(element: ElementType) { + protected constructor(element: ElementType) { this.wrapperElement = element } diff --git a/src/vueWrapper.ts b/src/vueWrapper.ts index a20356e3f..01ce15ef6 100644 --- a/src/vueWrapper.ts +++ b/src/vueWrapper.ts @@ -31,10 +31,12 @@ export class VueWrapper< $emit: (event: any, ...args: any[]) => void } & ComponentCustomProperties = ComponentPublicInstance > extends BaseWrapper { - private componentVM: T - private rootVM: ComponentPublicInstance | undefined | null - private __app: App | null - private __setProps: ((props: Record) => void) | undefined + private readonly componentVM: T + private readonly rootVM: ComponentPublicInstance | undefined | null + private readonly __app: App | null + private readonly __setProps: + | ((props: Record) => void) + | undefined private cleanUpCallbacks: Array<() => void> = [] constructor( From 4633375dc81fdf83bbee34646a5490bfd83a11b2 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Fri, 7 Oct 2022 15:40:56 +0000 Subject: [PATCH 09/36] chore(deps): update dependency vue-tsc to v1 --- package.json | 2 +- pnpm-lock.yaml | 100 +++++++++++++++++++++++++++---------------------- 2 files changed, 56 insertions(+), 46 deletions(-) diff --git a/package.json b/package.json index bcfce762a..6d2972a71 100644 --- a/package.json +++ b/package.json @@ -59,7 +59,7 @@ "vue": "3.2.40", "vue-class-component": "8.0.0-rc.1", "vue-router": "4.1.5", - "vue-tsc": "0.40.13", + "vue-tsc": "1.0.0", "vuex": "4.0.2" }, "peerDependencies": { diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 8c750b53a..295e29148 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -38,7 +38,7 @@ specifiers: vue: 3.2.40 vue-class-component: 8.0.0-rc.1 vue-router: 4.1.5 - vue-tsc: 0.40.13 + vue-tsc: 1.0.0 vuex: 4.0.2 devDependencies: @@ -79,7 +79,7 @@ devDependencies: vue: 3.2.40 vue-class-component: 8.0.0-rc.1_vue@3.2.40 vue-router: 4.1.5_vue@3.2.40 - vue-tsc: 0.40.13_typescript@4.8.4 + vue-tsc: 1.0.0_typescript@4.8.4 vuex: 4.0.2_vue@3.2.40 packages: @@ -961,42 +961,51 @@ packages: - terser dev: true - /@volar/code-gen/0.40.13: - resolution: {integrity: sha512-4gShBWuMce868OVvgyA1cU5WxHbjfEme18Tw6uVMfweZCF5fB2KECG0iPrA9D54vHk3FeHarODNwgIaaFfUBlA==} + /@volar/language-core/1.0.0: + resolution: {integrity: sha512-gUeIyRmPD9dtCAADK+ZCr0n4n1lbwsGJ+ulQn//phfD+p9B1E9B4o2WRoeOOAkcqXZTEFmCxtg+S6Pa0pwUVHA==} dependencies: - '@volar/source-map': 0.40.13 + '@volar/source-map': 1.0.0 + '@vue/reactivity': 3.2.40 + muggle-string: 0.1.0 dev: true - /@volar/source-map/0.40.13: - resolution: {integrity: sha512-dbdkAB2Nxb0wLjAY5O64o3ywVWlAGONnBIoKAkXSf6qkGZM+nJxcizsoiI66K+RHQG0XqlyvjDizfnTxr+6PWg==} + /@volar/source-map/1.0.0: + resolution: {integrity: sha512-EyIauGZmii2d4FicOw9eUnjq5nX/lqxKoPDPAZSGfkYOI/zfhhRydjLWR/BTbtPEV+Pqu6p5QjV3ts2/jQtKPw==} dependencies: - '@vue/reactivity': 3.2.38 + muggle-string: 0.1.0 dev: true - /@volar/typescript-faster/0.40.13: - resolution: {integrity: sha512-uy+TlcFkKoNlKEnxA4x5acxdxLyVDIXGSc8cYDNXpPKjBKXrQaetzCzlO3kVBqu1VLMxKNGJMTKn35mo+ILQmw==} + /@volar/typescript-faster/1.0.0: + resolution: {integrity: sha512-QsKMB2bEfWMKaPKW5HDmvBsusIgGx0WG1U30EaHwpnME25XZSJh1a5BZh9uUQcZteLkjtEfAmCI2PkfDgz1zew==} dependencies: semver: 7.3.7 dev: true - /@volar/vue-language-core/0.40.13: - resolution: {integrity: sha512-QkCb8msi2KUitTdM6Y4kAb7/ZlEvuLcbBFOC2PLBlFuoZwyxvSP7c/dBGmKGtJlEvMX0LdCyrg5V2aBYxD38/Q==} + /@volar/typescript/1.0.0: + resolution: {integrity: sha512-0BsNJnN/VuQ3WQ3RmdJo7Xf8pwT0JCV0xdtgH9okEMeuXBLPZjg7tKwDHT3TY8ord1mVk0tjNnzyQJAhaQ8t0w==} + dependencies: + '@volar/language-core': 1.0.0 + '@volar/typescript-faster': 1.0.0 + dev: true + + /@volar/vue-language-core/1.0.0: + resolution: {integrity: sha512-BYJvROEGNMDxTbyT7j9B9i8VDeLzEwDijNy2WactsK4mhruYRp911BwI9UNia4dD6RgMhyIShExRNoCwtCNMtw==} dependencies: - '@volar/code-gen': 0.40.13 - '@volar/source-map': 0.40.13 - '@vue/compiler-core': 3.2.38 + '@volar/language-core': 1.0.0 + '@volar/source-map': 1.0.0 '@vue/compiler-dom': 3.2.40 '@vue/compiler-sfc': 3.2.40 - '@vue/reactivity': 3.2.38 - '@vue/shared': 3.2.38 + '@vue/reactivity': 3.2.40 + '@vue/shared': 3.2.40 + minimatch: 5.1.0 + vue-template-compiler: 2.7.10 dev: true - /@volar/vue-typescript/0.40.13: - resolution: {integrity: sha512-o7bNztwjs8JmbQjVkrnbZUOfm7q4B8ZYssETISN1tRaBdun6cfNqgpkvDYd+VUBh1O4CdksvN+5BUNnwAz4oCQ==} + /@volar/vue-typescript/1.0.0: + resolution: {integrity: sha512-W9qU96gdApnEgHZf6i9BKQVDJqreYKVsXDRdJPtJEeykSwi6an0LYwgkpCfDjW3pyeVYSYAxVegYE8rSo9k4IA==} dependencies: - '@volar/code-gen': 0.40.13 - '@volar/typescript-faster': 0.40.13 - '@volar/vue-language-core': 0.40.13 + '@volar/typescript': 1.0.0 + '@volar/vue-language-core': 1.0.0 dev: true /@vue/babel-helper-vue-transform-on/1.0.2: @@ -1031,15 +1040,6 @@ packages: vue: 3.2.40 dev: true - /@vue/compiler-core/3.2.38: - resolution: {integrity: sha512-/FsvnSu7Z+lkd/8KXMa4yYNUiqQrI22135gfsQYVGuh5tqEgOB0XqrUdb/KnCLa5+TmQLPwvyUnKMyCpu+SX3Q==} - dependencies: - '@babel/parser': 7.19.0 - '@vue/shared': 3.2.38 - estree-walker: 2.0.2 - source-map: 0.6.1 - dev: true - /@vue/compiler-core/3.2.40: resolution: {integrity: sha512-2Dc3Stk0J/VyQ4OUr2yEC53kU28614lZS+bnrCbFSAIftBJ40g/2yQzf4mPBiFuqguMB7hyHaujdgZAQ67kZYA==} dependencies: @@ -1092,12 +1092,6 @@ packages: magic-string: 0.25.9 dev: true - /@vue/reactivity/3.2.38: - resolution: {integrity: sha512-6L4myYcH9HG2M25co7/BSo0skKFHpAN8PhkNPM4xRVkyGl1K5M3Jx4rp5bsYhvYze2K4+l+pioN4e6ZwFLUVtw==} - dependencies: - '@vue/shared': 3.2.38 - dev: true - /@vue/reactivity/3.2.40: resolution: {integrity: sha512-N9qgGLlZmtUBMHF9xDT4EkD9RdXde1Xbveb+niWMXuHVWQP5BzgRmE3SFyUBBcyayG4y1lhoz+lphGRRxxK4RA==} dependencies: @@ -1129,10 +1123,6 @@ packages: vue: 3.2.40 dev: true - /@vue/shared/3.2.38: - resolution: {integrity: sha512-dTyhTIRmGXBjxJE+skC8tTWCGLCVc4wQgRRLt8+O9p5ewBAjoBwtCAkLPrtToSr1xltoe3st21Pv953aOZ7alg==} - dev: true - /@vue/shared/3.2.40: resolution: {integrity: sha512-0PLQ6RUtZM0vO3teRfzGi4ltLUO5aO+kLgwh4Um3THSR03rpQWLTuRCkuO5A41ITzwdWeKdPHtSARuPkoo5pCQ==} dev: true @@ -1553,6 +1543,10 @@ packages: whatwg-url: 11.0.0 dev: true + /de-indent/1.0.2: + resolution: {integrity: sha512-e/1zu3xH5MQryN2zdVaF0OrdNLUbvWxzMbi+iNA6Bky7l1RoP8a2fIbRocyHclXt/arDrrR6lL3TqFD9pMQTsg==} + dev: true + /debug/4.3.4: resolution: {integrity: sha512-PRWFHuSU3eDtQJPvnNY7Jcket1j0t5OuOsFzPPzsekD52Zl8qUfFIPEiswXqIvHWGVHOgX+7G/vCNNhehwxfkQ==} engines: {node: '>=6.0'} @@ -2490,6 +2484,11 @@ packages: function-bind: 1.1.1 dev: true + /he/1.2.0: + resolution: {integrity: sha512-F/1DnUGPopORZi0ni+CvrCgHQ5FyEAHRLSApuYWMmrbSwoN2Mn/7k+Gl38gJnR7yyDZk6WLXwiGod1JOWNDKGw==} + hasBin: true + dev: true + /html-encoding-sniffer/3.0.0: resolution: {integrity: sha512-oWv4T4yJ52iKrufjnyZPkrN0CH3QnrUqdB6In1g5Fe1mia8GmF36gnfNySxoZtxD5+NmYw1EElVXiBk93UeskA==} engines: {node: '>=12'} @@ -2991,6 +2990,10 @@ packages: resolution: {integrity: sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==} dev: true + /muggle-string/0.1.0: + resolution: {integrity: sha512-Tr1knR3d2mKvvWthlk7202rywKbiOm4rVFLsfAaSIhJ6dt9o47W4S+JMtWhd/PW9Wrdew2/S2fSvhz3E2gkfEg==} + dev: true + /nanoid/3.3.4: resolution: {integrity: sha512-MqBkQh/OHTS2egovRtLk45wEyNXwF+cokD+1YPf9u5VfJiRdAiRwB2froX5Co9Rh20xs4siNPm8naNotSD6RBw==} engines: {node: ^10 || ^12 || ^13.7 || ^14 || >=15.0.1} @@ -3906,14 +3909,21 @@ packages: vue: 3.2.40 dev: true - /vue-tsc/0.40.13_typescript@4.8.4: - resolution: {integrity: sha512-xzuN3g5PnKfJcNrLv4+mAjteMd5wLm5fRhW0034OfNJZY4WhB07vhngea/XeGn7wNYt16r7syonzvW/54dcNiA==} + /vue-template-compiler/2.7.10: + resolution: {integrity: sha512-QO+8R9YRq1Gudm8ZMdo/lImZLJVUIAM8c07Vp84ojdDAf8HmPJc7XB556PcXV218k2AkKznsRz6xB5uOjAC4EQ==} + dependencies: + de-indent: 1.0.2 + he: 1.2.0 + dev: true + + /vue-tsc/1.0.0_typescript@4.8.4: + resolution: {integrity: sha512-QtQunVlF8SLs75s9FTCOOLXx6Fb5ccN6r3xDT4rUzznPzP6xfRC/iWhrJImEBRz74fhqXWPUMfujcmibnwYyXw==} hasBin: true peerDependencies: typescript: '*' dependencies: - '@volar/vue-language-core': 0.40.13 - '@volar/vue-typescript': 0.40.13 + '@volar/vue-language-core': 1.0.0 + '@volar/vue-typescript': 1.0.0 typescript: 4.8.4 dev: true From 77d1bbdc79cc1b609ffedd92453fef30ebed8dd6 Mon Sep 17 00:00:00 2001 From: Illya Klymov Date: Fri, 7 Oct 2022 23:10:05 +0300 Subject: [PATCH 10/36] chore(stubs): reorganize stubs logic to separate folder Stubs file does too much things. It is responsible for * creating new stubs * performing transformation of vnodes for ALL types * caching * maintaining registry of stubbed components This becomes hard to follow and maintain. This commit introduces new level of abstraction (createVNodeTransformer) which is responsible for: * transparently passing all non-component vnodes * invoking transformers (new might follow soon) * transformers now express that in VTU we only care about node type and instance (basically for retrieving instance name) --- src/config.ts | 2 +- src/mount.ts | 22 +- src/utils/find.ts | 2 +- .../stubComponentsTransformer.ts} | 240 +++++++++--------- src/vnodeTransformers/util.ts | 40 +++ 5 files changed, 174 insertions(+), 132 deletions(-) rename src/{stubs.ts => vnodeTransformers/stubComponentsTransformer.ts} (52%) create mode 100644 src/vnodeTransformers/util.ts diff --git a/src/config.ts b/src/config.ts index 63c507b19..b68adc163 100644 --- a/src/config.ts +++ b/src/config.ts @@ -1,7 +1,7 @@ import { GlobalMountOptions, Stub } from './types' import { VueWrapper } from './vueWrapper' import { DOMWrapper } from './domWrapper' -import { CustomCreateStub } from './stubs' +import { CustomCreateStub } from './vnodeTransformers/stubComponentsTransformer' export interface GlobalConfigOptions { global: Required> & { diff --git a/src/mount.ts b/src/mount.ts index 129ef1d38..31ddda39d 100644 --- a/src/mount.ts +++ b/src/mount.ts @@ -24,7 +24,8 @@ import { ComponentPropsOptions, ComponentOptions, ConcreteComponent, - Prop + Prop, + transformVNodeArgs } from 'vue' import { MountingOptions, Slot } from './types' @@ -37,7 +38,12 @@ import { import { processSlot } from './utils/compileSlots' import { VueWrapper } from './vueWrapper' import { attachEmitListener } from './emit' -import { stubComponents, addToDoNotStubComponents, registerStub } from './stubs' +import { createVNodeTransformer } from './vnodeTransformers/util' +import { + createStubComponentsTransformer, + addToDoNotStubComponents, + registerStub +} from './vnodeTransformers/stubComponentsTransformer' import { isLegacyFunctionalComponent, unwrapLegacyVueExtendComponent @@ -522,7 +528,17 @@ export function mount( // stubs // even if we are using `mount`, we will still // stub out Transition and Transition Group by default. - stubComponents(global.stubs, options?.shallow, global?.renderStubDefaultSlot) + transformVNodeArgs( + createVNodeTransformer({ + transformers: [ + createStubComponentsTransformer({ + stubs: global.stubs, + shallow: options?.shallow, + renderStubDefaultSlot: global.renderStubDefaultSlot + }) + ] + }) + ) // users expect stubs to work with globally registered // components so we register stubs as global components to avoid diff --git a/src/utils/find.ts b/src/utils/find.ts index 388225621..ad7785cb1 100644 --- a/src/utils/find.ts +++ b/src/utils/find.ts @@ -9,7 +9,7 @@ import { FindAllComponentsSelector } from '../types' import { getOriginalStubFromSpecializedStub, getOriginalVNodeTypeFromStub -} from '../stubs' +} from '../vnodeTransformers/stubComponentsTransformer' import { isComponent } from '../utils' import { matchName } from './matchName' import { unwrapLegacyVueExtendComponent } from './vueCompatSupport' diff --git a/src/stubs.ts b/src/vnodeTransformers/stubComponentsTransformer.ts similarity index 52% rename from src/stubs.ts rename to src/vnodeTransformers/stubComponentsTransformer.ts index eb1cde375..227fb2a2c 100644 --- a/src/stubs.ts +++ b/src/vnodeTransformers/stubComponentsTransformer.ts @@ -1,5 +1,5 @@ +import type { VTUVNodeTypeTransformer } from './util' import { - transformVNodeArgs, Transition, TransitionGroup, BaseTransition, @@ -12,17 +12,16 @@ import { ComponentObjectPropsOptions, DefineComponent } from 'vue' -import { hyphenate } from './utils/vueShared' -import { matchName } from './utils/matchName' -import { isComponent, isFunctionalComponent } from './utils' -import { ComponentInternalInstance } from '@vue/runtime-core' -import { unwrapLegacyVueExtendComponent } from './utils/vueCompatSupport' -import { Stub, Stubs } from './types' +import { hyphenate } from '../utils/vueShared' +import { matchName } from '../utils/matchName' +import { isComponent, isFunctionalComponent } from '../utils' +import { unwrapLegacyVueExtendComponent } from '../utils/vueCompatSupport' +import { Stub, Stubs } from '../types' import { getComponentName, getComponentRegisteredName -} from './utils/componentName' -import { config } from './config' +} from '../utils/componentName' +import { config } from '../config' export type CustomCreateStub = (params: { name: string @@ -144,11 +143,17 @@ function createStubOnceForType( return stub } -export function stubComponents( - stubs: Stubs = {}, +interface CreateStubComponentsTransformerConfig { + stubs?: Stubs + shallow?: boolean + renderStubDefaultSlot: boolean +} + +export function createStubComponentsTransformer({ + stubs = {}, shallow = false, renderStubDefaultSlot = false -) { +}: CreateStubComponentsTransformerConfig): VTUVNodeTypeTransformer { const createdStubsMap: WeakMap = new WeakMap() @@ -157,144 +162,125 @@ export function stubComponents( factoryFn: () => ConcreteComponent ) => createStubOnceForType(type, factoryFn, createdStubsMap) - transformVNodeArgs((args, instance: ComponentInternalInstance | null) => { - const [nodeType, props, children, patchFlag, dynamicProps] = args - const type = nodeType as VNodeTypes | typeof Teleport + return function componentsTransformer(type, instance) { + // stub teleport by default via config.global.stubs + if ((type as any) === Teleport && 'teleport' in stubs) { + if (stubs.teleport === false) return type + + return createStub({ + name: 'teleport', + type, + renderStubDefaultSlot: true + }) + } // stub transition by default via config.global.stubs if ( (type === Transition || type === BaseTransition) && 'transition' in stubs ) { - if (stubs.transition === false) return args - - return [ - createStub({ - name: 'transition', - type, - renderStubDefaultSlot: true - }), - props, - children - ] + if (stubs.transition === false) return type + + return createStub({ + name: 'transition', + type, + renderStubDefaultSlot: true + }) } // stub transition-group by default via config.global.stubs if (type === TransitionGroup && 'transition-group' in stubs) { - if (stubs['transition-group'] === false) return args - - return [ - createStub({ - name: 'transition-group', - type, - renderStubDefaultSlot: true - }), - props, - children - ] - } + if (stubs['transition-group'] === false) return type - // stub teleport by default via config.global.stubs - if (type === Teleport && 'teleport' in stubs) { - if (stubs.teleport === false) return args - - return [ - createStub({ - name: 'teleport', - type, - renderStubDefaultSlot: true - }), - props, - () => children - ] + return createStub({ + name: 'transition-group', + type, + renderStubDefaultSlot: true + }) } - if (isComponent(type) || isFunctionalComponent(type)) { - if (shouldNotStub(type)) { - return args - } + if (shouldNotStub(type)) { + return type + } - const registeredName = getComponentRegisteredName(instance, type) - const componentName = getComponentName(instance, type) + const registeredName = getComponentRegisteredName(instance, type) + const componentName = getComponentName(instance, type) - let stub = null - let name = null + let stub = null + let name = null - // Prio 1 using the key in locally registered components in the parent - if (registeredName) { - stub = resolveComponentStubByName(registeredName, stubs) - if (stub) { - name = registeredName - } + // Prio 1 using the key in locally registered components in the parent + if (registeredName) { + stub = resolveComponentStubByName(registeredName, stubs) + if (stub) { + name = registeredName } + } - // Prio 2 using the name attribute in the component - if (!stub && componentName) { - stub = resolveComponentStubByName(componentName, stubs) - if (stub) { - name = componentName - } + // Prio 2 using the name attribute in the component + if (!stub && componentName) { + stub = resolveComponentStubByName(componentName, stubs) + if (stub) { + name = componentName } + } - // case 2: custom implementation - if (isComponent(stub)) { - const unwrappedStub = unwrapLegacyVueExtendComponent(stub) - const stubFn = isFunctionalComponent(unwrappedStub) - ? unwrappedStub - : null - const specializedStubComponent: ConcreteComponent = stubFn - ? (...args) => stubFn(...args) - : { ...unwrappedStub } - specializedStubComponent.props = unwrappedStub.props - - const specializedStub = createStubOnce( - type, - () => specializedStubComponent - ) - specializedStub.props = unwrappedStub.props - registerStub({ - source: type, - stub: specializedStub, - originalStub: stub - }) - // pass the props and children, for advanced stubbing - return [specializedStub, props, children, patchFlag, dynamicProps] - } + // case 2: custom implementation + if (isComponent(stub)) { + const unwrappedStub = unwrapLegacyVueExtendComponent(stub) + const stubFn = isFunctionalComponent(unwrappedStub) ? unwrappedStub : null + const specializedStubComponent: ConcreteComponent = stubFn + ? (...args) => stubFn(...args) + : { ...unwrappedStub } + specializedStubComponent.props = unwrappedStub.props + + const specializedStub = createStubOnce( + type, + () => specializedStubComponent + ) + specializedStub.props = unwrappedStub.props + registerStub({ + source: type, + stub: specializedStub, + originalStub: stub + }) + // pass the props and children, for advanced stubbing + return specializedStub + } - if (stub === false) { - // we explicitly opt out of stubbing this component - return args - } + if (stub === false) { + // we explicitly opt out of stubbing this component + return type + } - // we return a stub by matching Vue's `h` function - // where the signature is h(Component, props, slots) - // case 1: default stub - if (stub === true || shallow) { - // Set name when using shallow without stub - const stubName = name || registeredName || componentName - - if (!isComponent(type)) { - throw new Error('Attempted to stub a non-component') - } - - const newStub = createStubOnce(type, () => - config.plugins.createStubs - ? config.plugins.createStubs({ - name: stubName, - component: type - }) - : createStub({ - name: stubName, - type, - renderStubDefaultSlot - }) - ) - registerStub({ source: type, stub: newStub }) - return [newStub, props, children, patchFlag, dynamicProps] + // we return a stub by matching Vue's `h` function + // where the signature is h(Component, props, slots) + // case 1: default stub + if (stub === true || shallow) { + // Set name when using shallow without stub + const stubName = name || registeredName || componentName + + if (!isComponent(type)) { + throw new Error('Attempted to stub a non-component') } + + const newStub = createStubOnce( + type, + () => + config.plugins.createStubs?.({ + name: stubName, + component: type + }) ?? + createStub({ + name: stubName, + type, + renderStubDefaultSlot + }) + ) + registerStub({ source: type, stub: newStub }) + return newStub } - // do not stub anything what is not a component - return args - }) + return type + } } diff --git a/src/vnodeTransformers/util.ts b/src/vnodeTransformers/util.ts new file mode 100644 index 000000000..ed76f016b --- /dev/null +++ b/src/vnodeTransformers/util.ts @@ -0,0 +1,40 @@ +import { isComponent } from '../utils' +import { ConcreteComponent, transformVNodeArgs } from 'vue' + +type VNodeArgsTransformerFn = NonNullable< + Parameters[0] +> +type TransformVNodeArgs = Parameters +type VNodeTransformerArgsType = TransformVNodeArgs[0] +type InstanceArgsType = TransformVNodeArgs[1] +type VNodeTransformerInputType = VNodeTransformerArgsType[0] + +type VNodeTransformerInputComponentType = VNodeTransformerInputType & + ConcreteComponent + +export type VTUVNodeTypeTransformer = ( + inputType: VNodeTransformerInputComponentType, + instance: InstanceArgsType +) => VNodeTransformerInputComponentType + +export const createVNodeTransformer = ({ + transformers +}: { + transformers: VTUVNodeTypeTransformer[] +}): VNodeArgsTransformerFn => { + return (args: VNodeTransformerArgsType, instance: InstanceArgsType) => { + const [originalType, ...restVNodeArgs] = args + + if (!isComponent(originalType)) { + return [originalType, ...restVNodeArgs] + } + + const componentType: VNodeTransformerInputComponentType = originalType + + const transformedType = transformers.reduce( + (type, transformer) => transformer(type, instance), + componentType + ) + return [transformedType, ...restVNodeArgs] + } +} From 70f673714b115414ca7ff328022f49c2b406d062 Mon Sep 17 00:00:00 2001 From: Illya Klymov Date: Fri, 7 Oct 2022 23:50:29 +0300 Subject: [PATCH 11/36] chore(stubs): refactor caching logic move caching logic from stub function to top level transformer --- .../stubComponentsTransformer.ts | 56 ++++--------------- src/vnodeTransformers/util.ts | 12 ++++ 2 files changed, 24 insertions(+), 44 deletions(-) diff --git a/src/vnodeTransformers/stubComponentsTransformer.ts b/src/vnodeTransformers/stubComponentsTransformer.ts index 227fb2a2c..4d4cbdec9 100644 --- a/src/vnodeTransformers/stubComponentsTransformer.ts +++ b/src/vnodeTransformers/stubComponentsTransformer.ts @@ -128,21 +128,6 @@ const resolveComponentStubByName = (componentName: string, stubs: Stubs) => { } } -function createStubOnceForType( - type: ConcreteComponent, - factoryFn: () => ConcreteComponent, - cache: WeakMap -): ConcreteComponent { - const cachedStub = cache.get(type) - if (cachedStub) { - return cachedStub - } - - const stub = factoryFn() - cache.set(type, stub) - return stub -} - interface CreateStubComponentsTransformerConfig { stubs?: Stubs shallow?: boolean @@ -154,14 +139,6 @@ export function createStubComponentsTransformer({ shallow = false, renderStubDefaultSlot = false }: CreateStubComponentsTransformerConfig): VTUVNodeTypeTransformer { - const createdStubsMap: WeakMap = - new WeakMap() - - const createStubOnce = ( - type: ConcreteComponent, - factoryFn: () => ConcreteComponent - ) => createStubOnceForType(type, factoryFn, createdStubsMap) - return function componentsTransformer(type, instance) { // stub teleport by default via config.global.stubs if ((type as any) === Teleport && 'teleport' in stubs) { @@ -234,18 +211,12 @@ export function createStubComponentsTransformer({ : { ...unwrappedStub } specializedStubComponent.props = unwrappedStub.props - const specializedStub = createStubOnce( - type, - () => specializedStubComponent - ) - specializedStub.props = unwrappedStub.props registerStub({ source: type, - stub: specializedStub, + stub: specializedStubComponent, originalStub: stub }) - // pass the props and children, for advanced stubbing - return specializedStub + return specializedStubComponent } if (stub === false) { @@ -264,19 +235,16 @@ export function createStubComponentsTransformer({ throw new Error('Attempted to stub a non-component') } - const newStub = createStubOnce( - type, - () => - config.plugins.createStubs?.({ - name: stubName, - component: type - }) ?? - createStub({ - name: stubName, - type, - renderStubDefaultSlot - }) - ) + const newStub = + config.plugins.createStubs?.({ + name: stubName, + component: type + }) ?? + createStub({ + name: stubName, + type, + renderStubDefaultSlot + }) registerStub({ source: type, stub: newStub }) return newStub } diff --git a/src/vnodeTransformers/util.ts b/src/vnodeTransformers/util.ts index ed76f016b..563143ab6 100644 --- a/src/vnodeTransformers/util.ts +++ b/src/vnodeTransformers/util.ts @@ -22,6 +22,11 @@ export const createVNodeTransformer = ({ }: { transformers: VTUVNodeTypeTransformer[] }): VNodeArgsTransformerFn => { + const transformationCache: WeakMap< + VNodeTransformerInputComponentType, + VNodeTransformerInputComponentType + > = new WeakMap() + return (args: VNodeTransformerArgsType, instance: InstanceArgsType) => { const [originalType, ...restVNodeArgs] = args @@ -29,12 +34,19 @@ export const createVNodeTransformer = ({ return [originalType, ...restVNodeArgs] } + const cachedTransformation = transformationCache.get(originalType) + if (cachedTransformation) { + return [cachedTransformation, ...restVNodeArgs] + } + const componentType: VNodeTransformerInputComponentType = originalType const transformedType = transformers.reduce( (type, transformer) => transformer(type, instance), componentType ) + transformationCache.set(originalType, transformedType) + return [transformedType, ...restVNodeArgs] } } From 8b0177fb35a982d0ed23d63d12579977228dfcf9 Mon Sep 17 00:00:00 2001 From: Illya Klymov Date: Sat, 8 Oct 2022 00:53:35 +0300 Subject: [PATCH 12/36] chore(stubs): remove useless check --- src/directives.ts | 73 +++++++++++++++++++ .../stubComponentsTransformer.ts | 4 - 2 files changed, 73 insertions(+), 4 deletions(-) create mode 100644 src/directives.ts diff --git a/src/directives.ts b/src/directives.ts new file mode 100644 index 000000000..7e202e6b7 --- /dev/null +++ b/src/directives.ts @@ -0,0 +1,73 @@ +import { + transformVNodeArgs, + Directive, + ComponentInternalInstance, + VNodeTypes +} from 'vue' +import { isObject } from './utils' + +interface CreateDirectivesTransformerConfig { + directives?: Record +} +type VNodeArgsTransformer = NonNullable< + Parameters[0] +> + +export function createDirectivesTransformer({ + directives = {} +}: CreateDirectivesTransformerConfig): VNodeArgsTransformer { + const directivesTransformerCache: WeakMap< + VNodeTypes & object, + VNodeTypes & object + > = new WeakMap() + + if (Object.keys(directives).length === 0) { + return (args) => args + } + + return function directivesTransformer( + args, + instance: ComponentInternalInstance | null + ) { + // We care about + // * object components + // * functional components + // * legacy components + // * legacy functional components + // * class components (sigh) + + const [nodeType, props, children, patchFlag, dynamicProps] = args + + if (!isObject(nodeType)) { + return args + } + + if ((nodeType as any).__PATCHED) { + console.log('wtf') + } + + const cachedTransformation = directivesTransformerCache.get(nodeType) + if (cachedTransformation) { + return [cachedTransformation, props, children, patchFlag, dynamicProps] + } + + const nodeTypeWithDirectives = { + __PATCHED: true, + ...nodeType, + directives: { + ...((nodeType as any)?.directives ?? {}), + ...directives + } + } + + directivesTransformerCache.set(nodeType, nodeTypeWithDirectives as any) + + return [ + nodeTypeWithDirectives as any, + props, + children, + patchFlag, + dynamicProps + ] + } +} diff --git a/src/vnodeTransformers/stubComponentsTransformer.ts b/src/vnodeTransformers/stubComponentsTransformer.ts index 4d4cbdec9..62affe12d 100644 --- a/src/vnodeTransformers/stubComponentsTransformer.ts +++ b/src/vnodeTransformers/stubComponentsTransformer.ts @@ -231,10 +231,6 @@ export function createStubComponentsTransformer({ // Set name when using shallow without stub const stubName = name || registeredName || componentName - if (!isComponent(type)) { - throw new Error('Attempted to stub a non-component') - } - const newStub = config.plugins.createStubs?.({ name: stubName, From 3f49e9759c60b17148ea8d406caa92444543e756 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Sun, 9 Oct 2022 04:04:15 +0000 Subject: [PATCH 13/36] chore(deps): update dependency @rollup/plugin-commonjs to v23 --- package.json | 2 +- pnpm-lock.yaml | 33 +++++++++++++++++++++++---------- 2 files changed, 24 insertions(+), 11 deletions(-) diff --git a/package.json b/package.json index 6d2972a71..4207f3824 100644 --- a/package.json +++ b/package.json @@ -22,7 +22,7 @@ "dist/index.d.ts" ], "devDependencies": { - "@rollup/plugin-commonjs": "22.0.2", + "@rollup/plugin-commonjs": "23.0.0", "@rollup/plugin-json": "4.1.0", "@rollup/plugin-node-resolve": "14.1.0", "@rollup/plugin-replace": "4.0.0", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 295e29148..1497ddc51 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -1,7 +1,7 @@ lockfileVersion: 5.4 specifiers: - '@rollup/plugin-commonjs': 22.0.2 + '@rollup/plugin-commonjs': 23.0.0 '@rollup/plugin-json': 4.1.0 '@rollup/plugin-node-resolve': 14.1.0 '@rollup/plugin-replace': 4.0.0 @@ -42,7 +42,7 @@ specifiers: vuex: 4.0.2 devDependencies: - '@rollup/plugin-commonjs': 22.0.2_rollup@2.79.1 + '@rollup/plugin-commonjs': 23.0.0_rollup@2.79.1 '@rollup/plugin-json': 4.1.0_rollup@2.79.1 '@rollup/plugin-node-resolve': 14.1.0_rollup@2.79.1 '@rollup/plugin-replace': 4.0.0_rollup@2.79.1 @@ -663,19 +663,21 @@ packages: fastq: 1.13.0 dev: true - /@rollup/plugin-commonjs/22.0.2_rollup@2.79.1: - resolution: {integrity: sha512-//NdP6iIwPbMTcazYsiBMbJW7gfmpHom33u1beiIoHDEM0Q9clvtQB1T0efvMqHeKsGohiHo97BCPCkBXdscwg==} - engines: {node: '>= 12.0.0'} + /@rollup/plugin-commonjs/23.0.0_rollup@2.79.1: + resolution: {integrity: sha512-JbrTRyDNtLQj/rhl7RFUuYXwQ2fac+33oLDAu2k++WD95zweyo28UAomLVA0JMGx4vmCa7Nw4T6k/1F6lelExg==} + engines: {node: '>=14.0.0'} peerDependencies: - rollup: ^2.68.0 + rollup: ^2.68.0||^3.0.0 + peerDependenciesMeta: + rollup: + optional: true dependencies: - '@rollup/pluginutils': 3.1.0_rollup@2.79.1 + '@rollup/pluginutils': 4.2.1 commondir: 1.0.1 estree-walker: 2.0.2 - glob: 7.2.3 + glob: 8.0.3 is-reference: 1.2.1 - magic-string: 0.25.9 - resolve: 1.22.1 + magic-string: 0.26.5 rollup: 2.79.1 dev: true @@ -2435,6 +2437,17 @@ packages: path-is-absolute: 1.0.1 dev: true + /glob/8.0.3: + resolution: {integrity: sha512-ull455NHSHI/Y1FqGaaYFaLGkNMMJbavMrEGFXG/PGrg6y7sutWHUHrz6gy6WEBH6akM1M414dWKCNs+IhKdiQ==} + engines: {node: '>=12'} + dependencies: + fs.realpath: 1.0.0 + inflight: 1.0.6 + inherits: 2.0.4 + minimatch: 5.1.0 + once: 1.4.0 + dev: true + /globals/11.12.0: resolution: {integrity: sha512-WOBp/EEGUiIsJSp7wcv/y6MO+lV9UoncWqxuFfm8eBwzWNgyfBd6Gz+IeKQ9jCmyhoH99g15M3T+QaVHFjizVA==} engines: {node: '>=4'} From 1904fe6b3c885dd6241844899242d31987dcdc9a Mon Sep 17 00:00:00 2001 From: Illya Klymov Date: Sun, 9 Oct 2022 21:09:25 +0300 Subject: [PATCH 14/36] chore: remove occasionally added file --- src/directives.ts | 73 ----------------------------------------------- 1 file changed, 73 deletions(-) delete mode 100644 src/directives.ts diff --git a/src/directives.ts b/src/directives.ts deleted file mode 100644 index 7e202e6b7..000000000 --- a/src/directives.ts +++ /dev/null @@ -1,73 +0,0 @@ -import { - transformVNodeArgs, - Directive, - ComponentInternalInstance, - VNodeTypes -} from 'vue' -import { isObject } from './utils' - -interface CreateDirectivesTransformerConfig { - directives?: Record -} -type VNodeArgsTransformer = NonNullable< - Parameters[0] -> - -export function createDirectivesTransformer({ - directives = {} -}: CreateDirectivesTransformerConfig): VNodeArgsTransformer { - const directivesTransformerCache: WeakMap< - VNodeTypes & object, - VNodeTypes & object - > = new WeakMap() - - if (Object.keys(directives).length === 0) { - return (args) => args - } - - return function directivesTransformer( - args, - instance: ComponentInternalInstance | null - ) { - // We care about - // * object components - // * functional components - // * legacy components - // * legacy functional components - // * class components (sigh) - - const [nodeType, props, children, patchFlag, dynamicProps] = args - - if (!isObject(nodeType)) { - return args - } - - if ((nodeType as any).__PATCHED) { - console.log('wtf') - } - - const cachedTransformation = directivesTransformerCache.get(nodeType) - if (cachedTransformation) { - return [cachedTransformation, props, children, patchFlag, dynamicProps] - } - - const nodeTypeWithDirectives = { - __PATCHED: true, - ...nodeType, - directives: { - ...((nodeType as any)?.directives ?? {}), - ...directives - } - } - - directivesTransformerCache.set(nodeType, nodeTypeWithDirectives as any) - - return [ - nodeTypeWithDirectives as any, - props, - children, - patchFlag, - dynamicProps - ] - } -} From 852198b9dd6db7e8bb4370b6361246d2764a1958 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Mon, 10 Oct 2022 11:08:47 +0000 Subject: [PATCH 15/36] chore(deps): update dependency @rollup/plugin-json to v5 --- package.json | 2 +- pnpm-lock.yaml | 16 ++++++++++------ 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/package.json b/package.json index 4207f3824..90bed935e 100644 --- a/package.json +++ b/package.json @@ -23,7 +23,7 @@ ], "devDependencies": { "@rollup/plugin-commonjs": "23.0.0", - "@rollup/plugin-json": "4.1.0", + "@rollup/plugin-json": "5.0.0", "@rollup/plugin-node-resolve": "14.1.0", "@rollup/plugin-replace": "4.0.0", "@types/node": "18.0.6", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 1497ddc51..b7b169c88 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -2,7 +2,7 @@ lockfileVersion: 5.4 specifiers: '@rollup/plugin-commonjs': 23.0.0 - '@rollup/plugin-json': 4.1.0 + '@rollup/plugin-json': 5.0.0 '@rollup/plugin-node-resolve': 14.1.0 '@rollup/plugin-replace': 4.0.0 '@types/node': 18.0.6 @@ -43,7 +43,7 @@ specifiers: devDependencies: '@rollup/plugin-commonjs': 23.0.0_rollup@2.79.1 - '@rollup/plugin-json': 4.1.0_rollup@2.79.1 + '@rollup/plugin-json': 5.0.0_rollup@2.79.1 '@rollup/plugin-node-resolve': 14.1.0_rollup@2.79.1 '@rollup/plugin-replace': 4.0.0_rollup@2.79.1 '@types/node': 18.0.6 @@ -681,12 +681,16 @@ packages: rollup: 2.79.1 dev: true - /@rollup/plugin-json/4.1.0_rollup@2.79.1: - resolution: {integrity: sha512-yfLbTdNS6amI/2OpmbiBoW12vngr5NW2jCJVZSBEz+H5KfUJZ2M7sDjk0U6GOOdCWFVScShte29o9NezJ53TPw==} + /@rollup/plugin-json/5.0.0_rollup@2.79.1: + resolution: {integrity: sha512-LsWDA5wJs/ggzakVuKQhZo7HPRcQZgBa3jWIVxQSFxaRToUGNi8ZBh3+k/gQ+1eInVYJgn4WBRCUkmoDrmmGzw==} + engines: {node: '>=14.0.0'} peerDependencies: - rollup: ^1.20.0 || ^2.0.0 + rollup: ^1.20.0||^2.0.0||^3.0.0 + peerDependenciesMeta: + rollup: + optional: true dependencies: - '@rollup/pluginutils': 3.1.0_rollup@2.79.1 + '@rollup/pluginutils': 4.2.1 rollup: 2.79.1 dev: true From 152f6d421c8772e174df58b5267ee0ab3dd22df5 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Mon, 10 Oct 2022 13:39:24 +0000 Subject: [PATCH 16/36] chore(deps): update dependency @rollup/plugin-node-resolve to v15 --- package.json | 2 +- pnpm-lock.yaml | 31 ++++++++++++++++--------------- 2 files changed, 17 insertions(+), 16 deletions(-) diff --git a/package.json b/package.json index 90bed935e..efbe11668 100644 --- a/package.json +++ b/package.json @@ -24,7 +24,7 @@ "devDependencies": { "@rollup/plugin-commonjs": "23.0.0", "@rollup/plugin-json": "5.0.0", - "@rollup/plugin-node-resolve": "14.1.0", + "@rollup/plugin-node-resolve": "15.0.0", "@rollup/plugin-replace": "4.0.0", "@types/node": "18.0.6", "@types/pretty": "2.0.1", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index b7b169c88..7eadbbdbd 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -3,7 +3,7 @@ lockfileVersion: 5.4 specifiers: '@rollup/plugin-commonjs': 23.0.0 '@rollup/plugin-json': 5.0.0 - '@rollup/plugin-node-resolve': 14.1.0 + '@rollup/plugin-node-resolve': 15.0.0 '@rollup/plugin-replace': 4.0.0 '@types/node': 18.0.6 '@types/pretty': 2.0.1 @@ -44,7 +44,7 @@ specifiers: devDependencies: '@rollup/plugin-commonjs': 23.0.0_rollup@2.79.1 '@rollup/plugin-json': 5.0.0_rollup@2.79.1 - '@rollup/plugin-node-resolve': 14.1.0_rollup@2.79.1 + '@rollup/plugin-node-resolve': 15.0.0_rollup@2.79.1 '@rollup/plugin-replace': 4.0.0_rollup@2.79.1 '@types/node': 18.0.6 '@types/pretty': 2.0.1 @@ -694,16 +694,19 @@ packages: rollup: 2.79.1 dev: true - /@rollup/plugin-node-resolve/14.1.0_rollup@2.79.1: - resolution: {integrity: sha512-5G2niJroNCz/1zqwXtk0t9+twOSDlG00k1Wfd7bkbbXmwg8H8dvgHdIWAun53Ps/rckfvOC7scDBjuGFg5OaWw==} - engines: {node: '>= 10.0.0'} + /@rollup/plugin-node-resolve/15.0.0_rollup@2.79.1: + resolution: {integrity: sha512-iwJbzfTzlzDDQcGmkS7EkCKwe2kSkdBrjX87Fy/KrNjr6UNnLpod0t6X66e502LRe5JJCA4FFqrEscWPnZAkig==} + engines: {node: '>=14.0.0'} peerDependencies: - rollup: ^2.78.0 + rollup: ^2.78.0||^3.0.0 + peerDependenciesMeta: + rollup: + optional: true dependencies: - '@rollup/pluginutils': 3.1.0_rollup@2.79.1 - '@types/resolve': 1.17.1 + '@rollup/pluginutils': 4.2.1 + '@types/resolve': 1.20.2 deepmerge: 4.2.2 - is-builtin-module: 3.1.0 + is-builtin-module: 3.2.0 is-module: 1.0.0 resolve: 1.22.1 rollup: 2.79.1 @@ -778,10 +781,8 @@ packages: resolution: {integrity: sha512-l18spTC0Q2OEUIHGPyw37XBOacFI4Kng1fgfFjgDTg2FR9wqJ/NY9zWyXv87NRUlFDU6JA+E/GVnNJiWgyon6A==} dev: true - /@types/resolve/1.17.1: - resolution: {integrity: sha512-yy7HuzQhj0dhGpD8RLXSZWEkLsV9ibvxvi6EiJ3bkqLAO1RGo0WbkWQiwpRlSFymTJRz0d3k5LM3kkx8ArDbLw==} - dependencies: - '@types/node': 18.0.6 + /@types/resolve/1.20.2: + resolution: {integrity: sha512-60BCwRFOZCQhDncwQdxxeOEEkbc5dIMccYLwbxsS4TUNeVECQ/pBJ0j09mrHOl/JJvpRPGwO9SvE4nR2Nb/a4Q==} dev: true /@typescript-eslint/eslint-plugin/5.39.0_xyciw6oqjoiiono4dhv3uhn5my: @@ -2610,8 +2611,8 @@ packages: resolution: {integrity: sha512-NcdALwpXkTm5Zvvbk7owOUSvVvBKDgKP5/ewfXEznmQFfs4ZRmanOeKBTjRVjka3QFoN6XJ+9F3USqfHqTaU5w==} dev: true - /is-builtin-module/3.1.0: - resolution: {integrity: sha512-OV7JjAgOTfAFJmHZLvpSTb4qi0nIILDV1gWPYDnDJUTNFM5aGlRAhk4QcT8i7TuAleeEV5Fdkqn3t4mS+Q11fg==} + /is-builtin-module/3.2.0: + resolution: {integrity: sha512-phDA4oSGt7vl1n5tJvTWooWWAsXLY+2xCnxNqvKhGEzujg+A43wPlPOyDg3C8XQHN+6k/JTQWJ/j0dQh/qr+Hw==} engines: {node: '>=6'} dependencies: builtin-modules: 3.3.0 From f03d8243508c1a6325eb406e0a7517546584977e Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Mon, 10 Oct 2022 19:31:34 +0000 Subject: [PATCH 17/36] chore(deps): update dependency @rollup/plugin-replace to v5 --- package.json | 2 +- pnpm-lock.yaml | 38 +++++++++++--------------------------- 2 files changed, 12 insertions(+), 28 deletions(-) diff --git a/package.json b/package.json index efbe11668..dfdec848e 100644 --- a/package.json +++ b/package.json @@ -25,7 +25,7 @@ "@rollup/plugin-commonjs": "23.0.0", "@rollup/plugin-json": "5.0.0", "@rollup/plugin-node-resolve": "15.0.0", - "@rollup/plugin-replace": "4.0.0", + "@rollup/plugin-replace": "5.0.0", "@types/node": "18.0.6", "@types/pretty": "2.0.1", "@typescript-eslint/eslint-plugin": "5.39.0", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 7eadbbdbd..83bfef908 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -4,7 +4,7 @@ specifiers: '@rollup/plugin-commonjs': 23.0.0 '@rollup/plugin-json': 5.0.0 '@rollup/plugin-node-resolve': 15.0.0 - '@rollup/plugin-replace': 4.0.0 + '@rollup/plugin-replace': 5.0.0 '@types/node': 18.0.6 '@types/pretty': 2.0.1 '@typescript-eslint/eslint-plugin': 5.39.0 @@ -45,7 +45,7 @@ devDependencies: '@rollup/plugin-commonjs': 23.0.0_rollup@2.79.1 '@rollup/plugin-json': 5.0.0_rollup@2.79.1 '@rollup/plugin-node-resolve': 15.0.0_rollup@2.79.1 - '@rollup/plugin-replace': 4.0.0_rollup@2.79.1 + '@rollup/plugin-replace': 5.0.0_rollup@2.79.1 '@types/node': 18.0.6 '@types/pretty': 2.0.1 '@typescript-eslint/eslint-plugin': 5.39.0_xyciw6oqjoiiono4dhv3uhn5my @@ -712,25 +712,17 @@ packages: rollup: 2.79.1 dev: true - /@rollup/plugin-replace/4.0.0_rollup@2.79.1: - resolution: {integrity: sha512-+rumQFiaNac9y64OHtkHGmdjm7us9bo1PlbgQfdihQtuNxzjpaB064HbRnewUOggLQxVCCyINfStkgmBeQpv1g==} - peerDependencies: - rollup: ^1.20.0 || ^2.0.0 - dependencies: - '@rollup/pluginutils': 3.1.0_rollup@2.79.1 - magic-string: 0.25.9 - rollup: 2.79.1 - dev: true - - /@rollup/pluginutils/3.1.0_rollup@2.79.1: - resolution: {integrity: sha512-GksZ6pr6TpIjHm8h9lSQ8pi8BE9VeubNT0OMJ3B5uZJ8pz73NPiqOtCog/x2/QzM1ENChPKxMDhiQuRHsqc+lg==} - engines: {node: '>= 8.0.0'} + /@rollup/plugin-replace/5.0.0_rollup@2.79.1: + resolution: {integrity: sha512-TiPmjMuBjQM+KLWK16O5TAM/eW4yXBYyQ17FbfeNzBC1t2kzX2aXoa8AlS9XTSmg6/2TNvkER1lMEEeN4Lhavw==} + engines: {node: '>=14.0.0'} peerDependencies: - rollup: ^1.20.0||^2.0.0 + rollup: ^1.20.0||^2.0.0||^3.0.0 + peerDependenciesMeta: + rollup: + optional: true dependencies: - '@types/estree': 0.0.39 - estree-walker: 1.0.1 - picomatch: 2.3.1 + '@rollup/pluginutils': 4.2.1 + magic-string: 0.26.5 rollup: 2.79.1 dev: true @@ -757,10 +749,6 @@ packages: resolution: {integrity: sha512-hC7OMnszpxhZPduX+m+nrx+uFoLkWOMiR4oa/AZF3MuSETYTZmFfJAHqZEM8MVlvfG7BEUcgvtwoCTxBp6hm3g==} dev: true - /@types/estree/0.0.39: - resolution: {integrity: sha512-EYNwp3bU+98cpU4lAWYYL7Zz+2gryWH1qbdDTidVd6hkiR6weksdbMadyXKXNPEkQFhXM+hVO9ZygomHXp+AIw==} - dev: true - /@types/estree/0.0.52: resolution: {integrity: sha512-BZWrtCU0bMVAIliIV+HJO1f1PR41M7NKjfxrFJwwhKI1KwhwOxYw1SXg9ao+CIMt774nFuGiG6eU+udtbEI9oQ==} dev: true @@ -2237,10 +2225,6 @@ packages: engines: {node: '>=4.0'} dev: true - /estree-walker/1.0.1: - resolution: {integrity: sha512-1fMXF3YP4pZZVozF8j/ZLfvnR8NSIljt56UhbZ5PeeDmmGHpgpdwQt7ITlGvYaQukCvuBRMLEiKiYC+oeIg4cg==} - dev: true - /estree-walker/2.0.2: resolution: {integrity: sha512-Rfkk/Mp/DL7JVje3u18FxFujQlTNR2q6QfMSMB7AvCBx91NGj/ba3kCfza0f6dVDbw7YlRf/nDrn7pQrCCyQ/w==} dev: true From 07cf17508a9dbadec523936eb3ca50e9d8e21887 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Tue, 11 Oct 2022 06:50:18 +0000 Subject: [PATCH 18/36] chore(deps): update pnpm/action-setup action to v2.2.3 --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6e2fd9b02..3a71a98c4 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -21,7 +21,7 @@ jobs: steps: - uses: actions/checkout@v3 - name: Install pnpm - uses: pnpm/action-setup@v2.2.2 + uses: pnpm/action-setup@v2.2.3 with: version: 7.5.0 - name: Use Node.js ${{ matrix.node }} From b5484d2dd28d70b0113e1fb0204a55683309d422 Mon Sep 17 00:00:00 2001 From: Illya Klymov Date: Wed, 12 Oct 2022 23:15:47 +0300 Subject: [PATCH 19/36] chore(scripts): add prebuild script --- package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/package.json b/package.json index dfdec848e..8b2cbfd2f 100644 --- a/package.json +++ b/package.json @@ -76,6 +76,7 @@ "test:build": "vitest --mode test-build", "tsd": "tsc -p test-dts/tsconfig.tsd.json", "build": "rollup -c rollup.config.js", + "prepare": "rollup -c rollup.config.js", "lint": "eslint --ext .ts src/ tests/", "lint:fix": "pnpm run lint --fix", "docs:dev": "vitepress dev docs", From 980ee94efa266bdddbcd548a488dc5d294265b14 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Exbrayat?= Date: Wed, 12 Oct 2022 08:58:05 +0200 Subject: [PATCH 20/36] chore: use @rollup/plugin-typescript Replaces `rollup-plugin-typescript2` by the official core plugin for TS, which supports Rollup v3. --- package.json | 2 +- pnpm-lock.yaml | 115 +++++++++-------------------------------------- rollup.config.js | 15 +++---- 3 files changed, 29 insertions(+), 103 deletions(-) diff --git a/package.json b/package.json index 8b2cbfd2f..4bbe897af 100644 --- a/package.json +++ b/package.json @@ -26,6 +26,7 @@ "@rollup/plugin-json": "5.0.0", "@rollup/plugin-node-resolve": "15.0.0", "@rollup/plugin-replace": "5.0.0", + "@rollup/plugin-typescript": "9.0.1", "@types/node": "18.0.6", "@types/pretty": "2.0.1", "@typescript-eslint/eslint-plugin": "5.39.0", @@ -49,7 +50,6 @@ "pretty": "2.0.0", "reflect-metadata": "0.1.13", "rollup": "2.79.1", - "rollup-plugin-typescript2": "0.34.1", "tslib": "2.4.0", "typescript": "4.8.4", "unplugin-vue-components": "0.22.8", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 83bfef908..d841d70bd 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -5,6 +5,7 @@ specifiers: '@rollup/plugin-json': 5.0.0 '@rollup/plugin-node-resolve': 15.0.0 '@rollup/plugin-replace': 5.0.0 + '@rollup/plugin-typescript': 9.0.1 '@types/node': 18.0.6 '@types/pretty': 2.0.1 '@typescript-eslint/eslint-plugin': 5.39.0 @@ -28,7 +29,6 @@ specifiers: pretty: 2.0.0 reflect-metadata: 0.1.13 rollup: 2.79.1 - rollup-plugin-typescript2: 0.34.1 tslib: 2.4.0 typescript: 4.8.4 unplugin-vue-components: 0.22.8 @@ -46,6 +46,7 @@ devDependencies: '@rollup/plugin-json': 5.0.0_rollup@2.79.1 '@rollup/plugin-node-resolve': 15.0.0_rollup@2.79.1 '@rollup/plugin-replace': 5.0.0_rollup@2.79.1 + '@rollup/plugin-typescript': 9.0.1_hafrwlgfjmvsm7253l3bfjzhnq '@types/node': 18.0.6 '@types/pretty': 2.0.1 '@typescript-eslint/eslint-plugin': 5.39.0_xyciw6oqjoiiono4dhv3uhn5my @@ -69,7 +70,6 @@ devDependencies: pretty: 2.0.0 reflect-metadata: 0.1.13 rollup: 2.79.1 - rollup-plugin-typescript2: 0.34.1_gypgyaqhine6mwjfvh7icfhviq tslib: 2.4.0 typescript: 4.8.4 unplugin-vue-components: 0.22.8_vue@3.2.40 @@ -726,6 +726,26 @@ packages: rollup: 2.79.1 dev: true + /@rollup/plugin-typescript/9.0.1_hafrwlgfjmvsm7253l3bfjzhnq: + resolution: {integrity: sha512-fj+CTk8+HvFCEwwDQdNgWd0lIJVXtMQ0Z3vH/ZgzFSbK2s1zs5wjZrjzrhViTTN+UF49+P69/tybgKRdGHpj/Q==} + engines: {node: '>=14.0.0'} + peerDependencies: + rollup: ^2.14.0||^3.0.0 + tslib: '*' + typescript: '>=3.7.0' + peerDependenciesMeta: + rollup: + optional: true + tslib: + optional: true + dependencies: + '@rollup/pluginutils': 4.2.1 + resolve: 1.22.1 + rollup: 2.79.1 + tslib: 2.4.0 + typescript: 4.8.4 + dev: true + /@rollup/pluginutils/4.2.1: resolution: {integrity: sha512-iKnFXr7NkdZAIHiIWE+BX5ULi/ucVFYWD6TbAV+rZctiRTY2PL6tsIKhoIOaoskiWAkgu+VsbXgUVDNLHf+InQ==} engines: {node: '>= 8.0.0'} @@ -2303,23 +2323,6 @@ packages: to-regex-range: 5.0.1 dev: true - /find-cache-dir/3.3.2: - resolution: {integrity: sha512-wXZV5emFEjrridIgED11OoUKLxiYjAcqot/NJdAkOhlJ+vGzwhOAfcG5OX1jP+S0PcjEn8bdMJv+g2jwQ3Onig==} - engines: {node: '>=8'} - dependencies: - commondir: 1.0.1 - make-dir: 3.1.0 - pkg-dir: 4.2.0 - dev: true - - /find-up/4.1.0: - resolution: {integrity: sha512-PpOwAdQ/YlXQ2vj8a3h8IipDuYRi3wceVQQGYWxNINccq40Anw7BlsEXCMbt1Zt+OLA6Fq9suIpIWD0OsnISlw==} - engines: {node: '>=8'} - dependencies: - locate-path: 5.0.0 - path-exists: 4.0.0 - dev: true - /find-up/5.0.0: resolution: {integrity: sha512-78/PXT1wlLLDgTzDs7sjq9hzz0vXD+zn+7wypEe4fXQxCmdmqfGsEPQxmiCSQI3ajFV91bVSsvNtrJRiW6nGng==} engines: {node: '>=10'} @@ -2357,15 +2360,6 @@ packages: mime-types: 2.1.35 dev: true - /fs-extra/10.1.0: - resolution: {integrity: sha512-oRXApq54ETRj4eMiFzGnHWGy+zo5raudjuxN0b8H7s/RU2oW0Wvsx9O0ACRN/kRq9E8Vu/ReskGB5o3ji+FzHQ==} - engines: {node: '>=12'} - dependencies: - graceful-fs: 4.2.10 - jsonfile: 6.1.0 - universalify: 2.0.0 - dev: true - /fs.realpath/1.0.0: resolution: {integrity: sha512-OO0pH2lK6a0hZnAdau5ItzHPI6pUlvI7jMVnxUQRtw4owF2wk8lOSabtGDCTP4Ggrg2MbGnWO9X8K1t4+fGMDw==} dev: true @@ -2461,10 +2455,6 @@ packages: slash: 3.0.0 dev: true - /graceful-fs/4.2.10: - resolution: {integrity: sha512-9ByhssR2fPVsNZj478qUUbKfmL0+t5BDVyjShtyZZLiK7ZDAArFFfopyOTj0M05wE2tJPisA4iTnnXl2YoPvOA==} - dev: true - /grapheme-splitter/1.0.4: resolution: {integrity: sha512-bzh50DW9kTPM00T8y4o8vQg89Di9oLJVLW/KaOGIXJWP/iqCN6WKYkbNOF04vFLJhwcpYUh9ydh/+5vpOqV4YQ==} dev: true @@ -2785,14 +2775,6 @@ packages: hasBin: true dev: true - /jsonfile/6.1.0: - resolution: {integrity: sha512-5dgndWOriYSm5cnYaJNhalLNDKOqFwyDB/rr1E9ZsGciGvKPs8R2xYGCacuf3z6K1YKDz182fd+fY3cn3pMqXQ==} - dependencies: - universalify: 2.0.0 - optionalDependencies: - graceful-fs: 4.2.10 - dev: true - /kind-of/3.2.2: resolution: {integrity: sha512-NOW9QQXMoZGg/oqnVNoNTTIFEIid1627WCffUBJEdMxYApq7mNE7CpzucIPc+ZQg25Phej7IJSmX3hO+oblOtQ==} engines: {node: '>=0.10.0'} @@ -2868,13 +2850,6 @@ packages: engines: {node: '>=14'} dev: true - /locate-path/5.0.0: - resolution: {integrity: sha512-t7hw9pI+WvuwNJXwk5zVHpyhIqzg2qTlklJOf0mVxGSbe3Fp2VieZcduNYjaLDoy6p9uGpQEGWG87WpMKlNq8g==} - engines: {node: '>=8'} - dependencies: - p-locate: 4.1.0 - dev: true - /locate-path/6.0.0: resolution: {integrity: sha512-iPZK6eYjbxRu3uB4/WZ3EsEIMJFMqAoopl3R+zuq0UjcAm/MO6KCweDgPfP3elTztoKP3KtnVHxTn2NHBSDVUw==} engines: {node: '>=10'} @@ -3082,13 +3057,6 @@ packages: word-wrap: 1.2.3 dev: true - /p-limit/2.3.0: - resolution: {integrity: sha512-//88mFWSJx8lxCzwdAABTJL2MyWB12+eIY7MDL2SqLmAkeKU9qxRvWuSyTjm3FUmpBEMuFfckAIqEaVGUDxb6w==} - engines: {node: '>=6'} - dependencies: - p-try: 2.2.0 - dev: true - /p-limit/3.1.0: resolution: {integrity: sha512-TYOanM3wGwNGsZN2cVTYPArw454xnXj5qmWF1bEoAc4+cU/ol7GVh7odevjp1FNHduHc3KZMcFduxU5Xc6uJRQ==} engines: {node: '>=10'} @@ -3096,13 +3064,6 @@ packages: yocto-queue: 0.1.0 dev: true - /p-locate/4.1.0: - resolution: {integrity: sha512-R79ZZ/0wAxKGu3oYMlz8jy/kbhsNrS7SKZ7PxEHBgJ5+F2mtFW2fK2cOtBh1cHYkQsbzFV7I+EoRKe6Yt0oK7A==} - engines: {node: '>=8'} - dependencies: - p-limit: 2.3.0 - dev: true - /p-locate/5.0.0: resolution: {integrity: sha512-LaNjtRWUBY++zB5nE/NwcaoMylSPk+S+ZHNB1TzdbMJMny6dynpAGt7X/tl/QYq3TIeE6nxHppbo2LGymrG5Pw==} engines: {node: '>=10'} @@ -3117,11 +3078,6 @@ packages: aggregate-error: 3.1.0 dev: true - /p-try/2.2.0: - resolution: {integrity: sha512-R4nPAVTAU0B9D35/Gk3uJf/7XYbQcyohSKdvAxIRSNghFl4e71hVoGnBNQz9cWaXxO2I10KTC+3jMdvvoKw6dQ==} - engines: {node: '>=6'} - dev: true - /parent-module/1.0.1: resolution: {integrity: sha512-GQ2EWRpQV8/o+Aw8YqtfZZPfNRWZYkbidE9k5rpl/hC3vtHHBfGm2Ifi6qWV+coDGkrUKZAxE3Lot5kcsRlh+g==} engines: {node: '>=6'} @@ -3183,13 +3139,6 @@ packages: hasBin: true dev: true - /pkg-dir/4.2.0: - resolution: {integrity: sha512-HRDzbaKjC+AOWVXxAU/x54COGeIv9eb+6CkDSQoNTt4XyWoIJvuPsXizxu/Fr23EiekbtZwmh1IcIG/l/a10GQ==} - engines: {node: '>=8'} - dependencies: - find-up: 4.1.0 - dev: true - /postcss/8.4.16: resolution: {integrity: sha512-ipHE1XBvKzm5xI7hiHCZJCSugxvsdq2mPnsq5+UF+VHCjiBvtDrlxJfMBToWaP9D5XlgNmcFGqoHmUn0EYEaRQ==} engines: {node: ^10 || ^12 || >=14} @@ -3328,21 +3277,6 @@ packages: glob: 7.2.3 dev: true - /rollup-plugin-typescript2/0.34.1_gypgyaqhine6mwjfvh7icfhviq: - resolution: {integrity: sha512-P4cHLtGikESmqi1CA+tdMDUv8WbQV48mzPYt77TSTOPJpERyZ9TXdDgjSDix8Fkqce6soYz3+fa4lrC93IEkcw==} - peerDependencies: - rollup: '>=1.26.3' - typescript: '>=2.4.0' - dependencies: - '@rollup/pluginutils': 4.2.1 - find-cache-dir: 3.3.2 - fs-extra: 10.1.0 - rollup: 2.79.1 - semver: 7.3.7 - tslib: 2.4.0 - typescript: 4.8.4 - dev: true - /rollup/2.78.1: resolution: {integrity: sha512-VeeCgtGi4P+o9hIg+xz4qQpRl6R401LWEXBmxYKOV4zlF82lyhgh2hTZnheFUbANE8l2A41F458iwj2vEYaXJg==} engines: {node: '>=10.0.0'} @@ -3668,11 +3602,6 @@ packages: engines: {node: '>= 4.0.0'} dev: true - /universalify/2.0.0: - resolution: {integrity: sha512-hAZsKq7Yy11Zu1DE0OzWjw7nnLZmJZYTDZZyEFHZdUhV8FkH5MCfoU1XMaxXovpyW5nq5scPqq0ZDP9Zyl04oQ==} - engines: {node: '>= 10.0.0'} - dev: true - /unplugin-vue-components/0.22.8_vue@3.2.40: resolution: {integrity: sha512-Musnwdtr6uj9Zopo4oeh4lp9+fJ2ArXVDzSiZxF4YC9v+pLnasKVKEEAjdXuQQ3u3KtntVw6PCscyAt52eS75g==} engines: {node: '>=14'} diff --git a/rollup.config.js b/rollup.config.js index 81f7cc54d..a161cdc2a 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -1,4 +1,4 @@ -import ts from 'rollup-plugin-typescript2' +import ts from '@rollup/plugin-typescript' import resolve from '@rollup/plugin-node-resolve' import replace from '@rollup/plugin-replace' import commonjs from '@rollup/plugin-commonjs' @@ -65,14 +65,11 @@ function createEntry(options) { config.plugins.push( ts({ - check: format === 'es' && isBrowser, - tsconfigOverride: { - compilerOptions: { - declaration: format === 'es', - target: 'es5', // not sure what this should be? - module: format === 'cjs' ? 'es2015' : 'esnext' - }, - exclude: ['tests'] + include: ['src/**/*.ts', 'types/**/*.d.ts'], + compilerOptions: { + declaration: format === 'es', + target: 'es5', // not sure what this should be? + module: format === 'cjs' ? 'es2015' : 'esnext' } }) ) From 182748f6c82d9c4691d777d3f4d02c32b1757155 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Exbrayat?= Date: Fri, 14 Oct 2022 10:47:45 +0200 Subject: [PATCH 21/36] chore: use a typescript rollup config --- package.json | 4 ++-- rollup.config.js => rollup.config.ts | 0 2 files changed, 2 insertions(+), 2 deletions(-) rename rollup.config.js => rollup.config.ts (100%) diff --git a/package.json b/package.json index 4bbe897af..ca73019c7 100644 --- a/package.json +++ b/package.json @@ -75,8 +75,8 @@ "test:watch": "vitest --watch", "test:build": "vitest --mode test-build", "tsd": "tsc -p test-dts/tsconfig.tsd.json", - "build": "rollup -c rollup.config.js", - "prepare": "rollup -c rollup.config.js", + "build": "rollup -c rollup.config.ts", + "prepare": "rollup -c rollup.config.ts", "lint": "eslint --ext .ts src/ tests/", "lint:fix": "pnpm run lint --fix", "docs:dev": "vitepress dev docs", diff --git a/rollup.config.js b/rollup.config.ts similarity index 100% rename from rollup.config.js rename to rollup.config.ts From d0ac5e33c7747eaecc927ff74abc914538f4362b Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Fri, 14 Oct 2022 08:54:24 +0000 Subject: [PATCH 22/36] chore(deps): update dependency rollup to v3 --- package.json | 2 +- pnpm-lock.yaml | 42 +++++++++++++++++++++++++----------------- 2 files changed, 26 insertions(+), 18 deletions(-) diff --git a/package.json b/package.json index ca73019c7..1cb2e976a 100644 --- a/package.json +++ b/package.json @@ -49,7 +49,7 @@ "prettier": "2.7.1", "pretty": "2.0.0", "reflect-metadata": "0.1.13", - "rollup": "2.79.1", + "rollup": "3.1.0", "tslib": "2.4.0", "typescript": "4.8.4", "unplugin-vue-components": "0.22.8", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index d841d70bd..2e4e8303b 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -28,7 +28,7 @@ specifiers: prettier: 2.7.1 pretty: 2.0.0 reflect-metadata: 0.1.13 - rollup: 2.79.1 + rollup: 3.1.0 tslib: 2.4.0 typescript: 4.8.4 unplugin-vue-components: 0.22.8 @@ -42,11 +42,11 @@ specifiers: vuex: 4.0.2 devDependencies: - '@rollup/plugin-commonjs': 23.0.0_rollup@2.79.1 - '@rollup/plugin-json': 5.0.0_rollup@2.79.1 - '@rollup/plugin-node-resolve': 15.0.0_rollup@2.79.1 - '@rollup/plugin-replace': 5.0.0_rollup@2.79.1 - '@rollup/plugin-typescript': 9.0.1_hafrwlgfjmvsm7253l3bfjzhnq + '@rollup/plugin-commonjs': 23.0.0_rollup@3.1.0 + '@rollup/plugin-json': 5.0.0_rollup@3.1.0 + '@rollup/plugin-node-resolve': 15.0.0_rollup@3.1.0 + '@rollup/plugin-replace': 5.0.0_rollup@3.1.0 + '@rollup/plugin-typescript': 9.0.1_52y3o6nq3pi22pxbagne3lkikq '@types/node': 18.0.6 '@types/pretty': 2.0.1 '@typescript-eslint/eslint-plugin': 5.39.0_xyciw6oqjoiiono4dhv3uhn5my @@ -69,7 +69,7 @@ devDependencies: prettier: 2.7.1 pretty: 2.0.0 reflect-metadata: 0.1.13 - rollup: 2.79.1 + rollup: 3.1.0 tslib: 2.4.0 typescript: 4.8.4 unplugin-vue-components: 0.22.8_vue@3.2.40 @@ -663,7 +663,7 @@ packages: fastq: 1.13.0 dev: true - /@rollup/plugin-commonjs/23.0.0_rollup@2.79.1: + /@rollup/plugin-commonjs/23.0.0_rollup@3.1.0: resolution: {integrity: sha512-JbrTRyDNtLQj/rhl7RFUuYXwQ2fac+33oLDAu2k++WD95zweyo28UAomLVA0JMGx4vmCa7Nw4T6k/1F6lelExg==} engines: {node: '>=14.0.0'} peerDependencies: @@ -678,10 +678,10 @@ packages: glob: 8.0.3 is-reference: 1.2.1 magic-string: 0.26.5 - rollup: 2.79.1 + rollup: 3.1.0 dev: true - /@rollup/plugin-json/5.0.0_rollup@2.79.1: + /@rollup/plugin-json/5.0.0_rollup@3.1.0: resolution: {integrity: sha512-LsWDA5wJs/ggzakVuKQhZo7HPRcQZgBa3jWIVxQSFxaRToUGNi8ZBh3+k/gQ+1eInVYJgn4WBRCUkmoDrmmGzw==} engines: {node: '>=14.0.0'} peerDependencies: @@ -691,10 +691,10 @@ packages: optional: true dependencies: '@rollup/pluginutils': 4.2.1 - rollup: 2.79.1 + rollup: 3.1.0 dev: true - /@rollup/plugin-node-resolve/15.0.0_rollup@2.79.1: + /@rollup/plugin-node-resolve/15.0.0_rollup@3.1.0: resolution: {integrity: sha512-iwJbzfTzlzDDQcGmkS7EkCKwe2kSkdBrjX87Fy/KrNjr6UNnLpod0t6X66e502LRe5JJCA4FFqrEscWPnZAkig==} engines: {node: '>=14.0.0'} peerDependencies: @@ -709,10 +709,10 @@ packages: is-builtin-module: 3.2.0 is-module: 1.0.0 resolve: 1.22.1 - rollup: 2.79.1 + rollup: 3.1.0 dev: true - /@rollup/plugin-replace/5.0.0_rollup@2.79.1: + /@rollup/plugin-replace/5.0.0_rollup@3.1.0: resolution: {integrity: sha512-TiPmjMuBjQM+KLWK16O5TAM/eW4yXBYyQ17FbfeNzBC1t2kzX2aXoa8AlS9XTSmg6/2TNvkER1lMEEeN4Lhavw==} engines: {node: '>=14.0.0'} peerDependencies: @@ -723,10 +723,10 @@ packages: dependencies: '@rollup/pluginutils': 4.2.1 magic-string: 0.26.5 - rollup: 2.79.1 + rollup: 3.1.0 dev: true - /@rollup/plugin-typescript/9.0.1_hafrwlgfjmvsm7253l3bfjzhnq: + /@rollup/plugin-typescript/9.0.1_52y3o6nq3pi22pxbagne3lkikq: resolution: {integrity: sha512-fj+CTk8+HvFCEwwDQdNgWd0lIJVXtMQ0Z3vH/ZgzFSbK2s1zs5wjZrjzrhViTTN+UF49+P69/tybgKRdGHpj/Q==} engines: {node: '>=14.0.0'} peerDependencies: @@ -741,7 +741,7 @@ packages: dependencies: '@rollup/pluginutils': 4.2.1 resolve: 1.22.1 - rollup: 2.79.1 + rollup: 3.1.0 tslib: 2.4.0 typescript: 4.8.4 dev: true @@ -3293,6 +3293,14 @@ packages: fsevents: 2.3.2 dev: true + /rollup/3.1.0: + resolution: {integrity: sha512-GEvr+COcXicr4nuih6mpt2Eydq5lZ72z0RrKx1H4/Q2ouT34OHrIIJ9OUj2sZqUhq7QL8Hp8Q8BoWbjL/6ccRQ==} + engines: {node: '>=14.18.0', npm: '>=8.0.0'} + hasBin: true + optionalDependencies: + fsevents: 2.3.2 + dev: true + /run-parallel/1.2.0: resolution: {integrity: sha512-5l4VyZR86LZ/lDxZTR6jqL8AFE2S0IFLMP26AbjsLVADxHdhB/c0GUsH+y39UfCi3dzz8OlQuPmnaJOMoDHQBA==} dependencies: From c08d29fc5329fd2f901232a51d2b73b842a86723 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Exbrayat?= Date: Fri, 14 Oct 2022 11:09:33 +0200 Subject: [PATCH 23/36] chore: use --bundleConfigAsCjs to load rollup config Ideally, we'd like to use a `mjs` config, but that necessitates an import type assertion for the import of `package.json`, and this feature is not supported by node v14. So we'll be able to use a `rollup.config.mjs` config only when we'll stop supporting node v14. See https://github.com/vuejs/test-utils/pull/1815 --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 1cb2e976a..045c2b612 100644 --- a/package.json +++ b/package.json @@ -75,8 +75,8 @@ "test:watch": "vitest --watch", "test:build": "vitest --mode test-build", "tsd": "tsc -p test-dts/tsconfig.tsd.json", - "build": "rollup -c rollup.config.ts", - "prepare": "rollup -c rollup.config.ts", + "build": "rollup -c rollup.config.ts --bundleConfigAsCjs", + "prepare": "rollup -c rollup.config.ts --bundleConfigAsCjs", "lint": "eslint --ext .ts src/ tests/", "lint:fix": "pnpm run lint --fix", "docs:dev": "vitepress dev docs", From 231531ce566c2f03f9f9852879db285cc5395141 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Exbrayat?= Date: Fri, 14 Oct 2022 11:17:22 +0200 Subject: [PATCH 24/36] chore: support node v18 --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3a71a98c4..0a6e817dd 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -16,7 +16,7 @@ jobs: strategy: matrix: - node: [14, 16] + node: [14, 16, 18] steps: - uses: actions/checkout@v3 From b881c10df0bfccbd58f11b2a8fc2aaa82ac0b692 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Exbrayat?= Date: Fri, 14 Oct 2022 11:18:06 +0200 Subject: [PATCH 25/36] chore: remove build step on ci The build is now done in the `install` step, as we have a `prepare` script --- .github/workflows/ci.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0a6e817dd..b665a8fe5 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -32,7 +32,6 @@ jobs: - run: pnpm install - run: pnpm run lint - run: pnpm run test:coverage - - run: pnpm run build env: CI: true - run: pnpm run test:build From c91415c21d0e6add722fda0f369da86996ac9986 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Sat, 15 Oct 2022 19:17:08 +0000 Subject: [PATCH 26/36] chore(deps): update pnpm/action-setup action to v2.2.4 --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b665a8fe5..1eb7c1755 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -21,7 +21,7 @@ jobs: steps: - uses: actions/checkout@v3 - name: Install pnpm - uses: pnpm/action-setup@v2.2.3 + uses: pnpm/action-setup@v2.2.4 with: version: 7.5.0 - name: Use Node.js ${{ matrix.node }} From 348d65120f8424078b1737e924592f77f5bac960 Mon Sep 17 00:00:00 2001 From: Illya Klymov Date: Thu, 6 Oct 2022 13:56:04 +0300 Subject: [PATCH 27/36] fix(config): Do not use config.renderStubDefaultSlot * docs mention config.global.renderStubDefaultSlot * get rid of double definition --- docs/guide/advanced/stubs-shallow-mount.md | 6 +++--- docs/migration/index.md | 2 +- src/config.ts | 8 +++++--- src/utils.ts | 10 ++++++++-- tests/mountingOptions/global.stubs.spec.ts | 8 ++++---- 5 files changed, 21 insertions(+), 13 deletions(-) diff --git a/docs/guide/advanced/stubs-shallow-mount.md b/docs/guide/advanced/stubs-shallow-mount.md index dc43fe98c..b9cdf4c1b 100644 --- a/docs/guide/advanced/stubs-shallow-mount.md +++ b/docs/guide/advanced/stubs-shallow-mount.md @@ -275,11 +275,11 @@ For this use case, you can use `config.renderStubDefaultSlot`, which will render import { config, mount } from '@vue/test-utils' beforeAll(() => { - config.renderStubDefaultSlot = true + config.global.renderStubDefaultSlot = true }) afterAll(() => { - config.renderStubDefaultSlot = false + config.global.renderStubDefaultSlot = false }) test('shallow with stubs', () => { @@ -316,4 +316,4 @@ So regardless of which mounting method you choose, we suggest keeping these guid - use `global.stubs` to replace a component with a dummy one to simplify your tests - use `shallow: true` (or `shallowMount`) to stub out all child components -- use `config.renderStubDefaultSlot` to render the default `` for a stubbed component +- use `global.renderStubDefaultSlot` to render the default `` for a stubbed component diff --git a/docs/migration/index.md b/docs/migration/index.md index 889335a1d..a3f72ef86 100644 --- a/docs/migration/index.md +++ b/docs/migration/index.md @@ -206,7 +206,7 @@ You can enable the old behavior like this: ```js import { config } from '@vue/test-utils' -config.renderStubDefaultSlot = true +config.global.renderStubDefaultSlot = true ``` ### `destroy` is now `unmount` to match Vue 3 diff --git a/src/config.ts b/src/config.ts index b68adc163..44939a91c 100644 --- a/src/config.ts +++ b/src/config.ts @@ -12,7 +12,10 @@ export interface GlobalConfigOptions { DOMWrapper: Pluggable> createStubs?: CustomCreateStub } - renderStubDefaultSlot: boolean + /** + * @deprecated use global. + */ + renderStubDefaultSlot?: boolean } interface Plugin { @@ -80,6 +83,5 @@ export const config: GlobalConfigOptions = { plugins: { VueWrapper: new Pluggable(), DOMWrapper: new Pluggable() - }, - renderStubDefaultSlot: false + } } diff --git a/src/utils.ts b/src/utils.ts index 23c10ea61..a348f4124 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -40,8 +40,14 @@ export function mergeGlobalProperties( const renderStubDefaultSlot = mountGlobal.renderStubDefaultSlot ?? - config?.renderStubDefaultSlot ?? - configGlobal?.renderStubDefaultSlot + (configGlobal.renderStubDefaultSlot || config?.renderStubDefaultSlot) ?? + false + + if (config.renderStubDefaultSlot === true) { + console.warn( + 'config.renderStubDefaultSlot is deprecated, use config.global.renderStubDefaultSlot instead' + ) + } return { mixins: [...(configGlobal.mixins || []), ...(mountGlobal.mixins || [])], diff --git a/tests/mountingOptions/global.stubs.spec.ts b/tests/mountingOptions/global.stubs.spec.ts index f7534b0f6..473b03604 100644 --- a/tests/mountingOptions/global.stubs.spec.ts +++ b/tests/mountingOptions/global.stubs.spec.ts @@ -731,11 +731,11 @@ describe('mounting options: stubs', () => { } afterEach(() => { - config.renderStubDefaultSlot = false + config.global.renderStubDefaultSlot = false }) it('renders only the default stub slot only behind flag', () => { - config.renderStubDefaultSlot = true + config.global.renderStubDefaultSlot = true const wrapper = mount(Component, { global: { @@ -750,7 +750,7 @@ describe('mounting options: stubs', () => { }) it('renders none of the slots on a stub', () => { - config.renderStubDefaultSlot = false + config.global.renderStubDefaultSlot = false const wrapper = mount(Component, { global: { stubs: ['ComponentWithSlots'] @@ -764,7 +764,7 @@ describe('mounting options: stubs', () => { }) it('renders the default slot of deeply nested stubs when renderStubDefaultSlot=true', () => { - config.renderStubDefaultSlot = true + config.global.renderStubDefaultSlot = true const SimpleSlot = { name: 'SimpleSlot', From 22c7698425f2745c573d6b8154e171e158449d8e Mon Sep 17 00:00:00 2001 From: Illya Klymov Date: Sat, 15 Oct 2022 15:13:28 +0300 Subject: [PATCH 28/36] fix(stubs): Do not render function body in stub --- .../stubComponentsTransformer.ts | 15 ++++++++------- tests/props.spec.ts | 16 ++++++++++++++++ 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/src/vnodeTransformers/stubComponentsTransformer.ts b/src/vnodeTransformers/stubComponentsTransformer.ts index 62affe12d..75e7a1012 100644 --- a/src/vnodeTransformers/stubComponentsTransformer.ts +++ b/src/vnodeTransformers/stubComponentsTransformer.ts @@ -63,13 +63,16 @@ const shouldNotStub = (type: ConcreteComponent) => doNotStubComponents.has(type) export const addToDoNotStubComponents = (type: ConcreteComponent) => doNotStubComponents.add(type) -const stringifySymbols = (props: ComponentPropsOptions) => { +const normalizeStubProps = (props: ComponentPropsOptions) => { // props are always normalized to object syntax const $props = props as unknown as ComponentObjectPropsOptions return Object.keys($props).reduce((acc, key) => { if (typeof $props[key] === 'symbol') { return { ...acc, [key]: $props[key]?.toString() } } + if (typeof $props[key] === 'function') { + return { ...acc, [key]: '[Function]' } + } return { ...acc, [key]: $props[key] } }, {}) } @@ -100,13 +103,11 @@ export const createStub = ({ // causes an error. // Only a problem when shallow mounting. For this reason we iterate of the // props that will be passed and stringify any that are symbols. - const propsWithoutSymbols = stringifySymbols(props) + // Also having function text as attribute is useless and annoying so + // we replace it with "[Function]"" + const stubProps = normalizeStubProps(props) - return h( - tag, - propsWithoutSymbols, - renderStubDefaultSlot ? slots : undefined - ) + return h(tag, stubProps, renderStubDefaultSlot ? slots : undefined) } } }) diff --git a/tests/props.spec.ts b/tests/props.spec.ts index 87c5a2447..77b73c03a 100644 --- a/tests/props.spec.ts +++ b/tests/props.spec.ts @@ -274,6 +274,22 @@ describe('props', () => { expect(wrapper.text()).toEqual('hello') }) + it('stub function props when shallow mounting', () => { + const Comp = defineComponent({ + name: 'Comp', + template: `
Test
`, + props: ['fn'] + }) + + const wrapper = shallowMount({ + render() { + return h(Comp, { fn: () => {} }) + } + }) + + expect(wrapper.html()).toBe('') + }) + describe('edge case with symbol props and stubs', () => { it('works with Symbol as default', () => { const Comp = defineComponent({ From 99209d093807adfcbd409563b471bd2c1be3c93d Mon Sep 17 00:00:00 2001 From: Illya Klymov Date: Mon, 17 Oct 2022 08:29:48 +0300 Subject: [PATCH 29/36] feat(stubs): allow to stub directives (fixes #1800) (#1804) This adds stubbing directives functionality to @vue/test-utils Fixes #1800 --- docs/guide/advanced/stubs-shallow-mount.md | 76 ++++++++++- src/mount.ts | 17 ++- src/stubs.ts | 32 +++++ src/types.ts | 2 +- src/utils.ts | 46 ++++++- src/utils/find.ts | 13 +- .../stubComponentsTransformer.ts | 60 +++------ .../stubDirectivesTransformer.ts | 49 +++++++ src/vnodeTransformers/util.ts | 14 +- tests/findComponent.spec.ts | 20 +++ tests/mountingOptions/global.stubs.spec.ts | 121 +++++++++++++++++- 11 files changed, 385 insertions(+), 65 deletions(-) create mode 100644 src/stubs.ts create mode 100644 src/vnodeTransformers/stubDirectivesTransformer.ts diff --git a/docs/guide/advanced/stubs-shallow-mount.md b/docs/guide/advanced/stubs-shallow-mount.md index b9cdf4c1b..2fddb9895 100644 --- a/docs/guide/advanced/stubs-shallow-mount.md +++ b/docs/guide/advanced/stubs-shallow-mount.md @@ -1,6 +1,6 @@ # Stubs and Shallow Mount -Vue Test Utils provides some advanced features for _stubbing_ components. A _stub_ is where you replace an existing implementation of a custom component with a dummy component that doesn't do anything at all, which can simplify an otherwise complex test. Let's see an example. +Vue Test Utils provides some advanced features for _stubbing_ components and directives. A _stub_ is where you replace an existing implementation of a custom component or directive with a dummy one that doesn't do anything at all, which can simplify an otherwise complex test. Let's see an example. ## Stubbing a single child component @@ -238,6 +238,78 @@ test('stubs async component with resolving', async () => { }) ``` +## Stubbing a directive + +Sometimes directives do quite complex things, like perform a lot of DOM manipulation which might result in errors in your tests (due to JSDOM not resembling entire DOM behavior). A common example is tooltip directives from various libraries, which usually rely heavily on measuring DOM nodes position/sizes. + +In this example, we have another `` that renders a message with tooltip + +```js +// tooltip directive declared somewhere, named `Tooltip` + +const App = { + directives: { + Tooltip + }, + template: '

Welcome to Vue.js 3

' +} +``` + +We do not want the `Tooltip` directive code to be executed in this test, we just want to assert the message is rendered. In this case, we could use the `stubs`, which appears in the `global` mounting option passing `vTooltip`. + +```js +test('stubs component with custom template', () => { + const wrapper = mount(App, { + global: { + stubs: { + vTooltip: true + } + } + }) + + console.log(wrapper.html()) + //

Welcome to Vue.js 3

+ + expect(wrapper.html()).toContain('Welcome to Vue.js 3') +}) +``` + +::: tip +Usage of `vCustomDirective` naming scheme to differentiate between components and directives is inspired by [same approach](https://vuejs.org/api/sfc-script-setup.html#using-custom-directives) used in `