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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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