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)
|
app.mount(root)
|
||||||
expect(serializeInner(root)).toBe('hello')
|
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,
|
validateComponentName,
|
||||||
Component
|
Component
|
||||||
} from './component'
|
} from './component'
|
||||||
import { ComponentOptions } from './componentOptions'
|
import { ComponentOptions, RuntimeCompilerOptions } from './componentOptions'
|
||||||
import { ComponentPublicInstance } from './componentPublicInstance'
|
import { ComponentPublicInstance } from './componentPublicInstance'
|
||||||
import { Directive, validateDirectiveName } from './directives'
|
import { Directive, validateDirectiveName } from './directives'
|
||||||
import { RootRenderFunction } from './renderer'
|
import { RootRenderFunction } from './renderer'
|
||||||
@ -87,14 +87,9 @@ export interface AppConfig {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Options to pass to @vue/compiler-dom.
|
* Options to pass to @vue/compiler-dom.
|
||||||
* *Only supported in runtime compiler build.*
|
* Only supported in runtime compiler build.
|
||||||
*/
|
*/
|
||||||
compilerOptions: {
|
compilerOptions: RuntimeCompilerOptions
|
||||||
isCustomElement: (tag: string) => boolean
|
|
||||||
whitespace?: 'preserve' | 'condense'
|
|
||||||
comments?: boolean
|
|
||||||
delimiters?: [string, string]
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface AppContext {
|
export interface AppContext {
|
||||||
|
@ -7,6 +7,7 @@ import {
|
|||||||
} from '../compatConfig'
|
} from '../compatConfig'
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
|
toggleDeprecationWarning(false)
|
||||||
Vue.configureCompat({ MODE: 2 })
|
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,
|
NOOP,
|
||||||
EMPTY_OBJ,
|
EMPTY_OBJ,
|
||||||
isArray,
|
isArray,
|
||||||
isObject
|
isObject,
|
||||||
|
isString
|
||||||
} from '@vue/shared'
|
} from '@vue/shared'
|
||||||
import { warn } from '../warning'
|
import { warn } from '../warning'
|
||||||
import { cloneVNode, createVNode } from '../vnode'
|
import { cloneVNode, createVNode } from '../vnode'
|
||||||
@ -152,8 +153,21 @@ export function createCompatVue(
|
|||||||
) {
|
) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
const val = singletonApp.config[key as keyof AppConfig]
|
||||||
// @ts-ignore
|
// @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
|
isCopyingConfig = false
|
||||||
|
|
||||||
|
@ -1,12 +1,7 @@
|
|||||||
import { extend, isArray, isString } from '@vue/shared'
|
import { extend, isArray } from '@vue/shared'
|
||||||
import { AppConfig } from '../apiCreateApp'
|
import { AppConfig } from '../apiCreateApp'
|
||||||
import { isRuntimeOnly } from '../component'
|
|
||||||
import { mergeDataOption } from './data'
|
import { mergeDataOption } from './data'
|
||||||
import {
|
import { DeprecationTypes, warnDeprecation } from './compatConfig'
|
||||||
DeprecationTypes,
|
|
||||||
warnDeprecation,
|
|
||||||
isCompatEnabled
|
|
||||||
} from './compatConfig'
|
|
||||||
import { isCopyingConfig } from './global'
|
import { isCopyingConfig } from './global'
|
||||||
|
|
||||||
// legacy config warnings
|
// legacy config warnings
|
||||||
@ -59,20 +54,6 @@ export function installLegacyConfigProperties(config: AppConfig) {
|
|||||||
warnDeprecation(legacyConfigOptions[key], null)
|
warnDeprecation(legacyConfigOptions[key], null)
|
||||||
}
|
}
|
||||||
val = newVal
|
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…
x
Reference in New Issue
Block a user