From 502546946bf7528a12f223ad9dc0090545c2b2df Mon Sep 17 00:00:00 2001 From: cuixiaorui Date: Mon, 13 Jul 2020 19:22:33 +0800 Subject: [PATCH 1/2] chore: remove ShapeFlags --- src/utils/vueShared.ts | 14 -------------- src/vue-wrapper.ts | 2 +- 2 files changed, 1 insertion(+), 15 deletions(-) diff --git a/src/utils/vueShared.ts b/src/utils/vueShared.ts index 25d7ac8cf..2214494b5 100644 --- a/src/utils/vueShared.ts +++ b/src/utils/vueShared.ts @@ -19,17 +19,3 @@ const hyphenateRE = /\B([A-Z])/g export const hyphenate = cacheStringFunction((str: string): string => { return str.replace(hyphenateRE, '-$1').toLowerCase() }) - -export const enum ShapeFlags { - ELEMENT = 1, - FUNCTIONAL_COMPONENT = 1 << 1, - STATEFUL_COMPONENT = 1 << 2, - TEXT_CHILDREN = 1 << 3, - ARRAY_CHILDREN = 1 << 4, - SLOTS_CHILDREN = 1 << 5, - TELEPORT = 1 << 6, - SUSPENSE = 1 << 7, - COMPONENT_SHOULD_KEEP_ALIVE = 1 << 8, - COMPONENT_KEPT_ALIVE = 1 << 9, - COMPONENT = ShapeFlags.STATEFUL_COMPONENT | ShapeFlags.FUNCTIONAL_COMPONENT -} diff --git a/src/vue-wrapper.ts b/src/vue-wrapper.ts index 9aa6fa715..305d5d552 100644 --- a/src/vue-wrapper.ts +++ b/src/vue-wrapper.ts @@ -1,5 +1,5 @@ import { ComponentPublicInstance, nextTick, App } from 'vue' -import { ShapeFlags } from './utils/vueShared' +import { ShapeFlags } from '@vue/shared' import { config } from './config' import { DOMWrapper } from './dom-wrapper' From fd3d26cb842ee48f639e9091def719822599d8b2 Mon Sep 17 00:00:00 2001 From: Lachlan Miller Date: Wed, 15 Jul 2020 20:37:41 +1000 Subject: [PATCH 2/2] feat: add flush promises --- package.json | 1 - src/index.ts | 11 ++++++++++- src/utils/flushPromises.ts | 7 +++++++ tests/features/async-components.spec.ts | 3 +-- tests/features/suspense.spec.ts | 4 +--- yarn.lock | 5 ----- 6 files changed, 19 insertions(+), 12 deletions(-) create mode 100644 src/utils/flushPromises.ts diff --git a/package.json b/package.json index e1b2b9c59..ed40d7c23 100644 --- a/package.json +++ b/package.json @@ -27,7 +27,6 @@ "babel-jest": "^25.2.3", "babel-preset-jest": "^25.2.1", "dom-event-types": "^1.0.0", - "flush-promises": "^1.0.2", "husky": "^4.2.3", "jest": "^25.1.0", "jsdom": "^16.2.2", diff --git a/src/index.ts b/src/index.ts index 85b75d0f1..40ba00379 100644 --- a/src/index.ts +++ b/src/index.ts @@ -3,5 +3,14 @@ import { RouterLinkStub } from './components/RouterLinkStub' import { VueWrapper } from './vue-wrapper' import { DOMWrapper } from './dom-wrapper' import { config } from './config' +import { flushPromises } from './utils/flushPromises' -export { mount, shallowMount, RouterLinkStub, VueWrapper, DOMWrapper, config } +export { + mount, + shallowMount, + RouterLinkStub, + VueWrapper, + DOMWrapper, + config, + flushPromises +} diff --git a/src/utils/flushPromises.ts b/src/utils/flushPromises.ts new file mode 100644 index 000000000..05315fa52 --- /dev/null +++ b/src/utils/flushPromises.ts @@ -0,0 +1,7 @@ +const scheduler = typeof setImmediate === 'function' ? setImmediate : setTimeout + +export function flushPromises() { + return new Promise((resolve) => { + scheduler(resolve, 0) + }) +} diff --git a/tests/features/async-components.spec.ts b/tests/features/async-components.spec.ts index e829668a5..bc26ed57c 100644 --- a/tests/features/async-components.spec.ts +++ b/tests/features/async-components.spec.ts @@ -1,7 +1,6 @@ import { defineAsyncComponent, defineComponent, h, AppConfig } from 'vue' -import flushPromises from 'flush-promises' -import { mount } from '../../src' +import { mount, flushPromises } from '../../src' const config: AppConfig = { devtools: false, diff --git a/tests/features/suspense.spec.ts b/tests/features/suspense.spec.ts index d4f6f354e..1338fbce4 100644 --- a/tests/features/suspense.spec.ts +++ b/tests/features/suspense.spec.ts @@ -1,7 +1,5 @@ -import flushPromises from 'flush-promises' - import SuspenseComponent from '../components/Suspense.vue' -import { mount } from '../../src' +import { mount, flushPromises } from '../../src' let mockShouldError = false jest.mock('../utils', () => ({ diff --git a/yarn.lock b/yarn.lock index 3d5e24308..245846c8d 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2572,11 +2572,6 @@ find-versions@^3.2.0: dependencies: semver-regex "^2.0.0" -flush-promises@^1.0.2: - version "1.0.2" - resolved "https://registry.yarnpkg.com/flush-promises/-/flush-promises-1.0.2.tgz#4948fd58f15281fed79cbafc86293d5bb09b2ced" - integrity sha512-G0sYfLQERwKz4+4iOZYQEZVpOt9zQrlItIxQAAYAWpfby3gbHrx0osCHz5RLl/XoXevXk0xoN4hDFky/VV9TrA== - for-in@^1.0.2: version "1.0.2" resolved "https://registry.yarnpkg.com/for-in/-/for-in-1.0.2.tgz#81068d295a8142ec0ac726c6e2200c30fb6d5e80"