Skip to content

Commit c738a40

Browse files
committed
feat!: add vitest v5 support
BREAKING CHANGE: support for Vitest <2, Node <222 has been dropped
1 parent 403f89f commit c738a40

10 files changed

Lines changed: 61 additions & 93 deletions

File tree

.github/workflows/ci.yaml

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,15 @@ jobs:
1515
strategy:
1616
fail-fast: false
1717
matrix:
18-
node-version: ['18', '20', '22', '24']
18+
node-version: ['22', '24']
1919
vitest-version: ['latest']
2020
include:
2121
- node-version: '24'
2222
vitest-version: '2'
2323
- node-version: '24'
2424
vitest-version: '3'
25+
- node-version: '24'
26+
vitest-version: 'beta'
2527

2628
steps:
2729
- name: Checkout source
@@ -32,9 +34,16 @@ jobs:
3234
with:
3335
node-version: ${{ matrix.node-version }}
3436

35-
- name: Override vitest version
37+
- name: Override Vitest version
3638
if: matrix.vitest-version != 'latest'
37-
run: pnpm add --no-lockfile -D vitest@${{ matrix.vitest-version }} @vitest/expect@${{ matrix.vitest-version }} @vitest/coverage-istanbul@${{ matrix.vitest-version }}
39+
env:
40+
version: ${{ matrix.vitest-version }}
41+
run: |
42+
pnpm add --no-lockfile -D \
43+
vitest@${version} \
44+
@vitest/expect@${version} \
45+
@vitest/pretty-format@${version} \
46+
@vitest/coverage-istanbul@${version}
3847
3948
- name: Run tests
4049
run: pnpm coverage

package.json

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,6 @@
4141
"test": "vitest"
4242
},
4343
"prettier": "@mcous/prettier-config",
44-
"dependencies": {
45-
"pretty-format": "^30.3.0"
46-
},
4744
"devDependencies": {
4845
"@mcous/eslint-config": "^0.9.0",
4946
"@mcous/prettier-config": "^0.4.0",
@@ -59,16 +56,20 @@
5956
"vitest": "^4.1.5"
6057
},
6158
"peerDependencies": {
62-
"@vitest/expect": ">=0.31.0 <5",
63-
"vitest": ">=0.31.0 <5"
59+
"@vitest/expect": "*",
60+
"@vitest/pretty-format": "*",
61+
"vitest": ">=2.0.2 <6"
6462
},
6563
"peerDependenciesMeta": {
6664
"@vitest/expect": {
6765
"optional": true
66+
},
67+
"@vitest/pretty-format": {
68+
"optional": true
6869
}
6970
},
7071
"engines": {
71-
"node": ">=18"
72+
"node": ">=22"
7273
},
7374
"packageManager": "pnpm@10.33.1+sha512.05ba3c1d5d1c18f68df06470d74055e62d41fc110a0c660db1b2dfb2785327f04cf0f68345d4609bc52089e7fa0343c31593b2f9594e2c5d5da426230acc9820",
7475
"publishConfig": {

pnpm-lock.yaml

Lines changed: 22 additions & 37 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/debug.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import {
22
format as prettyFormat,
33
plugins as prettyFormatPlugins,
4-
} from 'pretty-format'
4+
} from '@vitest/pretty-format'
55

66
import { type Behavior, BehaviorType } from './behaviors.ts'
77
import { getBehaviorStack } from './stubs.ts'

src/fallback-implementation.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import type { AnyFunction, MockInstance } from './types.ts'
1+
import type { AnyFunction, AnyMockInstance } from './types.ts'
22

33
/** Get the fallback implementation of a mock if no matching stub is found. */
44
export const getFallbackImplementation = (
5-
mock: MockInstance,
5+
mock: AnyMockInstance,
66
): AnyFunction | undefined => {
77
return (
88
(mock.getMockImplementation() as AnyFunction | undefined) ??
@@ -25,7 +25,7 @@ interface TinyspyInternals {
2525
* which is stored on a Symbol key in the mock object.
2626
*/
2727
const getTinyspyInternals = (
28-
mock: MockInstance,
28+
mock: AnyMockInstance,
2929
): TinyspyInternals | undefined => {
3030
const maybeTinyspy = mock as unknown as Record<PropertyKey, unknown>
3131

src/stubs.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import type {
1010
AsFunction,
1111
Mock,
1212
MockInstance,
13-
NormalizeMockable,
1413
ParametersOf,
1514
} from './types.ts'
1615

@@ -75,13 +74,13 @@ export const configureMock = <TFunc extends AnyMockable>(
7574

7675
export const validateMock = <TFunc extends AnyMockable>(
7776
maybeMock: TFunc | MockInstance<TFunc>,
78-
): MockInstance<NormalizeMockable<TFunc>> => {
77+
): MockInstance<TFunc> => {
7978
if (
8079
typeof maybeMock === 'function' &&
8180
'mockImplementation' in maybeMock &&
8281
typeof maybeMock.mockImplementation === 'function'
8382
) {
84-
return maybeMock as unknown as MockInstance<NormalizeMockable<TFunc>>
83+
return maybeMock as unknown as MockInstance<TFunc>
8584
}
8685

8786
throw new NotAMockFunctionError(maybeMock)
@@ -102,6 +101,6 @@ export const getBehaviorStack = <TFunc extends AnyMockable>(
102101

103102
export const asMock = <TFunc extends AnyMockable>(
104103
mock: MockInstance<TFunc>,
105-
): Mock<NormalizeMockable<TFunc>> => {
106-
return mock as unknown as Mock<NormalizeMockable<TFunc>>
104+
): Mock<TFunc> => {
105+
return mock as unknown as Mock<TFunc>
107106
}

0 commit comments

Comments
 (0)