wip(vitest-migration): runtime-dom tests passing + use environmentMatchGlobs

This commit is contained in:
Evan You 2023-01-26 21:35:50 +08:00
parent a6be280fc3
commit 4ee0dad0fe
14 changed files with 11 additions and 43 deletions

View File

@ -367,11 +367,8 @@ describe('defineCustomElement', () => {
})
test('emit from within async component wrapper', async () => {
const E = defineCustomElement(
defineAsyncComponent(
() => new Promise<typeof CompDef>(res => res(CompDef as any))
)
)
const p = new Promise<typeof CompDef>(res => res(CompDef as any))
const E = defineCustomElement(defineAsyncComponent(() => p))
customElements.define('my-async-el-emits', E)
container.innerHTML = `<my-async-el-emits></my-async-el-emits>`
const e = container.childNodes[0] as VueElement
@ -379,6 +376,8 @@ describe('defineCustomElement', () => {
e.addEventListener('my-click', spy)
// this feels brittle but seems necessary to reach the node in the DOM.
await customElements.whenDefined('my-async-el-emits')
await nextTick()
await nextTick()
e.shadowRoot!.childNodes[0].dispatchEvent(new CustomEvent('click'))
expect(spy).toHaveBeenCalled()
expect(spy.mock.calls[0][0]).toMatchObject({
@ -398,6 +397,8 @@ describe('defineCustomElement', () => {
const spy = vi.fn()
e.addEventListener('my-click', spy)
await customElements.whenDefined('my-async-el-props-emits')
await nextTick()
await nextTick()
e.shadowRoot!.childNodes[0].dispatchEvent(new CustomEvent('click'))
expect(spy).toHaveBeenCalled()
expect(spy.mock.calls[0][0]).toMatchObject({

View File

@ -85,15 +85,14 @@ describe(`runtime-dom: events patching`, () => {
const el = document.createElement('div')
// string should be set as attribute
const fn = ((window as any).__globalSpy = vi.fn())
patchProp(el, 'onclick', null, '__globalSpy(1)')
const fn = ((el as any).spy = vi.fn())
patchProp(el, 'onclick', null, 'this.spy(1)')
el.dispatchEvent(new Event('click'))
await timeout()
delete (window as any).__globalSpy
expect(fn).toHaveBeenCalledWith(1)
const fn2 = vi.fn()
patchProp(el, 'onclick', '__globalSpy(1)', fn2)
patchProp(el, 'onclick', 'this.spy(1)', fn2)
const event = new Event('click')
el.dispatchEvent(event)
await timeout()

View File

@ -1,6 +1,3 @@
/**
* @vitest-environment jsdom
*/
import { vi } from 'vitest'
import Vue from '@vue/compat'
import { nextTick } from '@vue/runtime-core'

View File

@ -1,6 +1,3 @@
/**
* @vitest-environment jsdom
*/
import Vue from '@vue/compat'
import {
DeprecationTypes,

View File

@ -1,6 +1,3 @@
/**
* @vitest-environment jsdom
*/
import Vue from '@vue/compat'
import {
DeprecationTypes,

View File

@ -1,6 +1,3 @@
/**
* @vitest-environment jsdom
*/
import Vue from '@vue/compat'
import { ComponentOptions } from '../../runtime-core/src/component'
import { nextTick } from '../../runtime-core/src/scheduler'

View File

@ -1,6 +1,3 @@
/**
* @vitest-environment jsdom
*/
import Vue from '@vue/compat'
import { CompilerDeprecationTypes } from '../../compiler-core/src'
import {

View File

@ -1,6 +1,3 @@
/**
* @vitest-environment jsdom
*/
import { vi } from 'vitest'
import Vue from '@vue/compat'
import { effect, isReactive } from '@vue/reactivity'

View File

@ -1,6 +1,3 @@
/**
* @vitest-environment jsdom
*/
import { vi } from 'vitest'
import Vue from '@vue/compat'
import {

View File

@ -1,6 +1,3 @@
/**
* @vitest-environment jsdom
*/
import { vi, Mock } from 'vitest'
import Vue from '@vue/compat'
import { Slots } from '../../runtime-core/src/componentSlots'

View File

@ -1,6 +1,3 @@
/**
* @vitest-environment jsdom
*/
import { vi } from 'vitest'
import Vue from '@vue/compat'
import { nextTick } from '../../runtime-core/src/scheduler'

View File

@ -1,6 +1,3 @@
/**
* @vitest-environment jsdom
*/
import { vi } from 'vitest'
import Vue from '@vue/compat'
import { nextTick } from '../../runtime-core/src/scheduler'

View File

@ -1,6 +1,3 @@
/**
* @vitest-environment jsdom
*/
import { ShapeFlags } from '@vue/shared'
import Vue from '@vue/compat'
import { createComponentInstance } from '../../runtime-core/src/component'

View File

@ -42,6 +42,7 @@ export default defineConfig({
},
test: {
globals: true,
setupFiles: 'scripts/setupVitest.ts'
setupFiles: 'scripts/setupVitest.ts',
environmentMatchGlobs: [['packages/{vue-compat,runtime-dom}/**', 'jsdom']]
}
})