Skip to content

Commit 403f89f

Browse files
authored
ci: include Vitest versions in matrix (#42)
1 parent 7fea35c commit 403f89f

4 files changed

Lines changed: 34 additions & 24 deletions

File tree

.github/workflows/ci.yaml

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,19 @@ on:
99

1010
jobs:
1111
test:
12-
name: Test / Node.js ${{ matrix.node-version }} / ${{ matrix.os }}
13-
runs-on: ${{ matrix.os }}
12+
name: Test / Node.js ${{ matrix.node-version }} / Vitest ${{ matrix.vitest-version }}
13+
runs-on: ubuntu-latest
1414

1515
strategy:
1616
fail-fast: false
1717
matrix:
18-
os: [ubuntu-latest, macos-latest, windows-latest]
19-
node-version: ['18', '20', '22']
18+
node-version: ['18', '20', '22', '24']
19+
vitest-version: ['latest']
20+
include:
21+
- node-version: '24'
22+
vitest-version: '2'
23+
- node-version: '24'
24+
vitest-version: '3'
2025

2126
steps:
2227
- name: Checkout source
@@ -27,6 +32,10 @@ jobs:
2732
with:
2833
node-version: ${{ matrix.node-version }}
2934

35+
- name: Override vitest version
36+
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 }}
38+
3039
- name: Run tests
3140
run: pnpm coverage
3241

test/debug.test.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { describe, expect, it, vi } from 'vitest'
33
import * as subject from '../src/vitest-when.ts'
44

55
const DEBUG_OPTIONS = { log: false }
6+
const VI_FN_NAME_MATCHER = /(?:vi\.fn\(\)|spy)/u
67

78
describe('vitest-when debug', () => {
89
it('debugs a non-stubbed spy', () => {
@@ -11,7 +12,7 @@ describe('vitest-when debug', () => {
1112
const result = subject.debug(spy, DEBUG_OPTIONS)
1213

1314
expect(result).toEqual({
14-
name: 'vi.fn()',
15+
name: expect.stringMatching(VI_FN_NAME_MATCHER),
1516
stubbings: [],
1617
unmatchedCalls: [],
1718
description: expect.stringContaining(
@@ -28,7 +29,7 @@ describe('vitest-when debug', () => {
2829
const result = subject.debug(spy, DEBUG_OPTIONS)
2930

3031
expect(result).toEqual({
31-
name: 'vi.fn()',
32+
name: expect.stringMatching(VI_FN_NAME_MATCHER),
3233
stubbings: [
3334
{
3435
args: ['hello', 'world'],
@@ -52,7 +53,7 @@ describe('vitest-when debug', () => {
5253
const result = subject.debug(spy, DEBUG_OPTIONS)
5354

5455
expect(result).toMatchObject({
55-
name: 'vi.fn()',
56+
name: expect.stringMatching(VI_FN_NAME_MATCHER),
5657
stubbings: [
5758
{
5859
args: [expect.any(String)],
@@ -75,7 +76,7 @@ describe('vitest-when debug', () => {
7576
const result = subject.debug(spy, DEBUG_OPTIONS)
7677

7778
expect(result).toMatchObject({
78-
name: 'vi.fn()',
79+
name: expect.stringMatching(VI_FN_NAME_MATCHER),
7980
stubbings: [
8081
{
8182
args: [expect.any(String)],

test/typing.test-d.ts

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,8 @@ describe('vitest-when type signatures', () => {
139139
.calledWith(1)
140140
.thenReturn({ simpleMethod: () => '' })
141141

142-
expectTypeOf(result).toEqualTypeOf<
143-
MockedClass<new (input: number) => SimpleClass>
142+
expectTypeOf(result).branded.toEqualTypeOf<
143+
MockedClass<typeof SimpleClass>
144144
>()
145145
})
146146

@@ -202,9 +202,7 @@ describe('vitest-when type signatures', () => {
202202
.calledWith(42)
203203
.thenReturn({ simpleMethod: () => '' })
204204

205-
expectTypeOf(result).branded.toEqualTypeOf<
206-
MockedClass<new (input: number) => SimpleClass>
207-
>()
205+
expectTypeOf(result).toEqualTypeOf<MockedClass<typeof SimpleClass>>()
208206

209207
// @ts-expect-error: args wrong type
210208
subject.when(TestClass).calledWith('42')
@@ -218,9 +216,7 @@ describe('vitest-when type signatures', () => {
218216
this.simpleMethod = () => `${input}`
219217
})
220218

221-
expectTypeOf(result).branded.toEqualTypeOf<
222-
MockedClass<new (input: number) => SimpleClass>
223-
>()
219+
expectTypeOf(result).toEqualTypeOf<MockedClass<typeof SimpleClass>>()
224220

225221
// @ts-expect-error: args wrong type
226222
subject.when(TestClass).calledWith('42')

test/vitest-when.test.ts

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { describe, expect, it, vi } from 'vitest'
2+
import vitestPkg from 'vitest/package.json' with { type: 'json' }
23

34
import * as subject from '../src/vitest-when.ts'
45
import { SimpleClass } from './fixtures.ts'
@@ -19,6 +20,7 @@ expect.extend({
1920
})
2021

2122
const noop = () => undefined
23+
const vitestMajorVersion = Number(vitestPkg.version.split('.')[0])
2224

2325
describe('vitest-when', () => {
2426
it('should raise an error if passed a non-spy', () => {
@@ -60,16 +62,18 @@ describe('vitest-when', () => {
6062
expect(spy()).toEqual(100)
6163
})
6264

63-
it('should fall back to original implementation after reset', () => {
64-
const spy = vi.fn((n) => 2 * n)
65+
it.skipIf(vitestMajorVersion < 3)(
66+
'should fall back to original implementation after reset',
67+
() => {
68+
const spy = vi.fn((n) => 2 * n)
6569

66-
vi.resetAllMocks()
67-
expect(spy(2)).toEqual(4)
70+
vi.resetAllMocks()
6871

69-
subject.when(spy).calledWith(1).thenReturn(4)
70-
expect(spy(1)).toEqual(4)
71-
expect(spy(2)).toEqual(4)
72-
})
72+
subject.when(spy).calledWith(1).thenReturn(4)
73+
expect(spy(1)).toEqual(4)
74+
expect(spy(2)).toEqual(4)
75+
},
76+
)
7377

7478
it('should return a number of times', () => {
7579
const spy = subject

0 commit comments

Comments
 (0)