Skip to content

Commit b3127a8

Browse files
ianzoneyoyo837
andauthored
test(@tarojs/shared): jest to vitest (#18148)
Co-authored-by: Amumu <[email protected]>
1 parent 0a14895 commit b3127a8

File tree

6 files changed

+31
-42
lines changed

6 files changed

+31
-42
lines changed

packages/shared/jest.config.js

Lines changed: 0 additions & 20 deletions
This file was deleted.

packages/shared/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
"build": "pnpm run rollup --environment NODE_ENV:production",
2525
"dev": "pnpm run rollup --environment NODE_ENV:development -w",
2626
"rollup": "rollup --config rollup.config.ts --configPlugin typescript",
27-
"test": "jest"
27+
"test": "vitest run"
2828
},
2929
"bugs": {
3030
"url": "https://github.com/NervJS/taro/issues"

packages/shared/__tests__/hooks.spec.ts renamed to packages/shared/tests/hooks.spec.ts

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { beforeAll, describe, expect, test, vi } from 'vitest'
2+
13
import { HOOK_TYPE, TaroHook, TaroHooks } from '../src/runtime-hooks'
24
import { mergeReconciler } from '../src/utils'
35

@@ -13,7 +15,7 @@ describe('taro hooks', () => {
1315
})
1416
})
1517

16-
it('single', () => {
18+
test('single', () => {
1719
hook.tap('hookA', () => {
1820
return 'first'
1921
})
@@ -24,7 +26,7 @@ describe('taro hooks', () => {
2426
expect(res).toBe('second')
2527
})
2628

27-
it('single with default', () => {
29+
test('single with default', () => {
2830
let res = hook.call('hookAWithDefault', 'Ben')
2931
expect(res).toBe('name: Ben')
3032
hook.tap('hookAWithDefault', (name) => {
@@ -34,20 +36,20 @@ describe('taro hooks', () => {
3436
expect(res).toBe('JoJo')
3537
})
3638

37-
it('multi', () => {
38-
const fnA = jest.fn()
39-
const fnB = jest.fn()
39+
test('multi', () => {
40+
const fnA = vi.fn()
41+
const fnB = vi.fn()
4042
hook.tap('hookB', fnA)
4143
hook.tap('hookB', fnB)
4244
hook.call('hookB')
4345
expect(fnA).toBeCalled()
4446
expect(fnB).toBeCalled()
4547
})
4648

47-
it('multi default', () => {
48-
const fnA = jest.fn()
49-
const fnB = jest.fn()
50-
const fnC = jest.fn()
49+
test('multi default', () => {
50+
const fnA = vi.fn()
51+
const fnB = vi.fn()
52+
const fnC = vi.fn()
5153
const hook = new TaroHooks({
5254
hookBWithDefault: TaroHook(HOOK_TYPE.MULTI, fnA)
5355
})
@@ -59,7 +61,7 @@ describe('taro hooks', () => {
5961
expect(fnC).toBeCalled()
6062
})
6163

62-
it('waterfall', () => {
64+
test('waterfall', () => {
6365
hook.tap('hookC', (obj) => {
6466
obj.num += 1
6567
return obj
@@ -76,7 +78,7 @@ describe('taro hooks', () => {
7678
expect(res).toEqual({ num: 16 })
7779
})
7880

79-
it('plugin', () => {
81+
test('plugin', () => {
8082
// shared
8183
const hooks = new TaroHooks({
8284
hookA: TaroHook(HOOK_TYPE.SINGLE, () => 'default'),
@@ -85,7 +87,7 @@ describe('taro hooks', () => {
8587
})
8688

8789
// pluginA
88-
const fnA = jest.fn()
90+
const fnA = vi.fn()
8991
const reconcilerA = {
9092
hookA: () => 'pluginA',
9193
hookB: fnA,
@@ -94,7 +96,7 @@ describe('taro hooks', () => {
9496
mergeReconciler(reconcilerA, hooks)
9597

9698
// pluginB
97-
const fnB = jest.fn()
99+
const fnB = vi.fn()
98100
const reconcilerB = {
99101
hookA: () => 'pluginB',
100102
hookB: fnB,

packages/shared/__tests__/shared.spec.ts renamed to packages/shared/tests/shared.spec.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1+
import { describe, expect, test } from 'vitest'
2+
13
import { indent } from '../src/utils'
24

35
describe('shared utils', () => {
4-
it('#indent', async () => {
6+
test('#indent', async () => {
57
const inner =
68
`<text>
79
hello, world

packages/shared/tsconfig.test.json

Lines changed: 0 additions & 7 deletions
This file was deleted.

packages/shared/vitest.config.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { defineConfig } from 'vitest/config'
2+
3+
// https://cn.vitest.dev/guide/
4+
export default defineConfig({
5+
test: {
6+
include: ['tests/**/*.spec.ts?(x)'],
7+
coverage: {
8+
provider: 'istanbul',
9+
include: ['src/**/*.ts'],
10+
}
11+
}
12+
})

0 commit comments

Comments
 (0)