فهرست منبع

wip: basic compat test

Evan You 5 سال پیش
والد
کامیت
3d810eb422

+ 1 - 0
jest.config.js

@@ -35,6 +35,7 @@ module.exports = {
   watchPathIgnorePatterns: ['/node_modules/', '/dist/', '/.git/'],
   moduleFileExtensions: ['ts', 'tsx', 'js', 'json'],
   moduleNameMapper: {
+    '@vue/compat': '<rootDir>/packages/vue-compat/src',
     '^@vue/(.*?)$': '<rootDir>/packages/$1/src',
     vue: '<rootDir>/packages/vue/src'
   },

+ 16 - 0
packages/runtime-core/src/compat/__tests__/compatGlobal.spec.ts

@@ -0,0 +1,16 @@
+import Vue from '@vue/compat'
+
+test('should work', async () => {
+  const el = document.createElement('div')
+  el.innerHTML = `{{ msg }}`
+  new Vue({
+    el,
+    data() {
+      return {
+        msg: 'hello'
+      }
+    }
+  })
+  expect('global app bootstrapping API has changed').toHaveBeenWarned()
+  expect(el.innerHTML).toBe('hello')
+})

+ 1 - 1
packages/runtime-core/src/compat/customDirective.ts

@@ -1,4 +1,4 @@
-import { isArray } from '@vue/shared/src'
+import { isArray } from '@vue/shared'
 import { ObjectDirective, DirectiveHook } from '../directives'
 import { DeprecationTypes, warnDeprecation } from './deprecations'
 

+ 1 - 1
packages/runtime-core/src/compat/deprecations.ts

@@ -122,7 +122,7 @@ const deprecations: Record<DeprecationTypes, DeprecationData> = {
 
   [DeprecationTypes.INSTANCE_MOUNT]: {
     message:
-      `The global app boostrapping API has changed: vm.$mount() and the "el" ` +
+      `The global app bootstrapping API has changed: vm.$mount() and the "el" ` +
       `option have been removed. Use createApp(RootComponent).mount() instead.`,
     link: `https://v3.vuejs.org/guide/migration/global-api.html#mounting-app-instance`
   },

+ 2 - 2
packages/runtime-core/src/compat/global.ts

@@ -246,7 +246,7 @@ export function installCompatMount(
     if (hasNoRender) {
       instance.render = emptyRender
     }
-    setupComponent(instance, __NODE_JS__)
+    setupComponent(instance)
     vnode.component = instance
 
     // $mount & $destroy
@@ -312,7 +312,7 @@ export function installCompatMount(
         }
         instance.render = null
         ;(component as ComponentOptions).template = container.innerHTML
-        finishComponentSetup(instance, __NODE_JS__, true /* skip options */)
+        finishComponentSetup(instance, false, true /* skip options */)
       }
 
       // clear content before mounting

+ 1 - 0
tsconfig.json

@@ -18,6 +18,7 @@
     "types": ["jest", "puppeteer", "node"],
     "rootDir": ".",
     "paths": {
+      "@vue/compat": ["packages/vue-compat/src"],
       "@vue/*": ["packages/*/src"],
       "vue": ["packages/vue/src"]
     }