wip: tests for global config compat
This commit is contained in:
parent
ce0bbe053a
commit
c27f01bc74
@ -481,4 +481,7 @@ describe('api: createApp', () => {
|
||||
app.mount(root)
|
||||
expect(serializeInner(root)).toBe('hello')
|
||||
})
|
||||
|
||||
// config.compilerOptions is tested in packages/vue since it is only
|
||||
// supported in the full build.
|
||||
})
|
||||
|
@ -4,7 +4,7 @@ import {
|
||||
validateComponentName,
|
||||
Component
|
||||
} from './component'
|
||||
import { ComponentOptions } from './componentOptions'
|
||||
import { ComponentOptions, RuntimeCompilerOptions } from './componentOptions'
|
||||
import { ComponentPublicInstance } from './componentPublicInstance'
|
||||
import { Directive, validateDirectiveName } from './directives'
|
||||
import { RootRenderFunction } from './renderer'
|
||||
@ -87,14 +87,9 @@ export interface AppConfig {
|
||||
|
||||
/**
|
||||
* Options to pass to @vue/compiler-dom.
|
||||
* *Only supported in runtime compiler build.*
|
||||
* Only supported in runtime compiler build.
|
||||
*/
|
||||
compilerOptions: {
|
||||
isCustomElement: (tag: string) => boolean
|
||||
whitespace?: 'preserve' | 'condense'
|
||||
comments?: boolean
|
||||
delimiters?: [string, string]
|
||||
}
|
||||
compilerOptions: RuntimeCompilerOptions
|
||||
}
|
||||
|
||||
export interface AppContext {
|
||||
|
@ -7,6 +7,7 @@ import {
|
||||
} from '../compatConfig'
|
||||
|
||||
beforeEach(() => {
|
||||
toggleDeprecationWarning(false)
|
||||
Vue.configureCompat({ MODE: 2 })
|
||||
})
|
||||
|
||||
|
@ -0,0 +1,77 @@
|
||||
import Vue from '@vue/compat'
|
||||
import { toggleDeprecationWarning } from '../compatConfig'
|
||||
|
||||
beforeEach(() => {
|
||||
toggleDeprecationWarning(false)
|
||||
Vue.configureCompat({ MODE: 2 })
|
||||
})
|
||||
|
||||
afterEach(() => {
|
||||
Vue.configureCompat({ MODE: 3 })
|
||||
toggleDeprecationWarning(false)
|
||||
})
|
||||
|
||||
function triggerEvent(
|
||||
target: Element,
|
||||
event: string,
|
||||
process?: (e: any) => any
|
||||
) {
|
||||
const e = document.createEvent('HTMLEvents')
|
||||
e.initEvent(event, true, true)
|
||||
if (process) process(e)
|
||||
target.dispatchEvent(e)
|
||||
return e
|
||||
}
|
||||
|
||||
// only testing config options that affect runtime behavior.
|
||||
|
||||
test('GLOBAL_KEY_CODES', () => {
|
||||
Vue.config.keyCodes = {
|
||||
foo: 86,
|
||||
bar: [38, 87]
|
||||
}
|
||||
|
||||
const onFoo = jest.fn()
|
||||
const onBar = jest.fn()
|
||||
|
||||
const el = document.createElement('div')
|
||||
new Vue({
|
||||
el,
|
||||
template: `<input type="text" @keyup.foo="onFoo" @keyup.bar="onBar">`,
|
||||
methods: {
|
||||
onFoo,
|
||||
onBar
|
||||
}
|
||||
})
|
||||
|
||||
triggerEvent(el.children[0], 'keyup', e => {
|
||||
e.key = '_'
|
||||
e.keyCode = 86
|
||||
})
|
||||
expect(onFoo).toHaveBeenCalledTimes(1)
|
||||
expect(onBar).toHaveBeenCalledTimes(0)
|
||||
|
||||
triggerEvent(el.children[0], 'keyup', e => {
|
||||
e.key = '_'
|
||||
e.keyCode = 38
|
||||
})
|
||||
expect(onFoo).toHaveBeenCalledTimes(1)
|
||||
expect(onBar).toHaveBeenCalledTimes(1)
|
||||
|
||||
triggerEvent(el.children[0], 'keyup', e => {
|
||||
e.key = '_'
|
||||
e.keyCode = 87
|
||||
})
|
||||
expect(onFoo).toHaveBeenCalledTimes(1)
|
||||
expect(onBar).toHaveBeenCalledTimes(2)
|
||||
})
|
||||
|
||||
test('GLOBAL_IGNORED_ELEMENTS', () => {
|
||||
Vue.config.ignoredElements = [/^v-/, 'foo']
|
||||
const el = document.createElement('div')
|
||||
new Vue({
|
||||
el,
|
||||
template: `<v-foo/><foo/>`
|
||||
})
|
||||
expect(el.innerHTML).toBe(`<v-foo></v-foo><foo></foo>`)
|
||||
})
|
@ -12,7 +12,8 @@ import {
|
||||
NOOP,
|
||||
EMPTY_OBJ,
|
||||
isArray,
|
||||
isObject
|
||||
isObject,
|
||||
isString
|
||||
} from '@vue/shared'
|
||||
import { warn } from '../warning'
|
||||
import { cloneVNode, createVNode } from '../vnode'
|
||||
@ -152,8 +153,21 @@ export function createCompatVue(
|
||||
) {
|
||||
continue
|
||||
}
|
||||
const val = singletonApp.config[key as keyof AppConfig]
|
||||
// @ts-ignore
|
||||
app.config[key] = singletonApp.config[key]
|
||||
app.config[key] = val
|
||||
|
||||
// compat for runtime ignoredElements -> isCustomElement
|
||||
if (
|
||||
key === 'ignoredElements' &&
|
||||
isCompatEnabled(DeprecationTypes.CONFIG_IGNORED_ELEMENTS, null) &&
|
||||
!isRuntimeOnly() &&
|
||||
isArray(val)
|
||||
) {
|
||||
app.config.compilerOptions.isCustomElement = tag => {
|
||||
return val.some(v => (isString(v) ? v === tag : v.test(tag)))
|
||||
}
|
||||
}
|
||||
}
|
||||
isCopyingConfig = false
|
||||
|
||||
|
@ -1,12 +1,7 @@
|
||||
import { extend, isArray, isString } from '@vue/shared'
|
||||
import { extend, isArray } from '@vue/shared'
|
||||
import { AppConfig } from '../apiCreateApp'
|
||||
import { isRuntimeOnly } from '../component'
|
||||
import { mergeDataOption } from './data'
|
||||
import {
|
||||
DeprecationTypes,
|
||||
warnDeprecation,
|
||||
isCompatEnabled
|
||||
} from './compatConfig'
|
||||
import { DeprecationTypes, warnDeprecation } from './compatConfig'
|
||||
import { isCopyingConfig } from './global'
|
||||
|
||||
// legacy config warnings
|
||||
@ -59,20 +54,6 @@ export function installLegacyConfigProperties(config: AppConfig) {
|
||||
warnDeprecation(legacyConfigOptions[key], null)
|
||||
}
|
||||
val = newVal
|
||||
|
||||
// compat for runtime ignoredElements -> isCustomElement
|
||||
if (
|
||||
key === 'ignoredElements' &&
|
||||
isCompatEnabled(DeprecationTypes.CONFIG_IGNORED_ELEMENTS, null) &&
|
||||
!isRuntimeOnly() &&
|
||||
isArray(newVal)
|
||||
) {
|
||||
config.isCustomElement = tag => {
|
||||
return newVal.some(
|
||||
val => (isString(val) ? val === tag : val.test(tag))
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user