Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 11 additions & 9 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,8 @@ jobs:
strategy:
fail-fast: false
matrix:
node-version: ['18', '20', '22', '24']
vitest-version: ['latest']
include:
- node-version: '24'
vitest-version: '2'
- node-version: '24'
vitest-version: '3'
node-version: ['22', '24']
vitest-version: ['2', '3', 'latest', 'beta']

steps:
- name: Checkout source
Expand All @@ -32,9 +27,16 @@ jobs:
with:
node-version: ${{ matrix.node-version }}

- name: Override vitest version
- name: Override Vitest version
if: matrix.vitest-version != 'latest'
run: pnpm add --no-lockfile -D vitest@${{ matrix.vitest-version }} @vitest/expect@${{ matrix.vitest-version }} @vitest/coverage-istanbul@${{ matrix.vitest-version }}
env:
version: ${{ matrix.vitest-version }}
run: |
pnpm add --no-lockfile -D \
vitest@${version} \
@vitest/expect@${version} \
@vitest/pretty-format@${version} \
@vitest/coverage-istanbul@${version}

- name: Run tests
run: pnpm coverage
Expand Down
11 changes: 6 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,6 @@
"test": "vitest"
},
"prettier": "@mcous/prettier-config",
"dependencies": {
"pretty-format": "^30.3.0"
},
"devDependencies": {
"@mcous/eslint-config": "^0.9.0",
"@mcous/prettier-config": "^0.4.0",
Expand All @@ -59,12 +56,16 @@
"vitest": "^4.1.5"
},
"peerDependencies": {
"@vitest/expect": ">=0.31.0 <5",
"vitest": ">=0.31.0 <5"
"@vitest/expect": "*",
"@vitest/pretty-format": "*",
"vitest": ">=2.0.2 <6"
},
"peerDependenciesMeta": {
"@vitest/expect": {
"optional": true
},
"@vitest/pretty-format": {
"optional": true
}
},
"engines": {
Expand Down
59 changes: 22 additions & 37 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/debug.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {
format as prettyFormat,
plugins as prettyFormatPlugins,
} from 'pretty-format'
} from '@vitest/pretty-format'

import { type Behavior, BehaviorType } from './behaviors.ts'
import { getBehaviorStack } from './stubs.ts'
Expand Down
6 changes: 3 additions & 3 deletions src/fallback-implementation.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import type { AnyFunction, MockInstance } from './types.ts'
import type { AnyFunction, AnyMockInstance } from './types.ts'

/** Get the fallback implementation of a mock if no matching stub is found. */
export const getFallbackImplementation = (
mock: MockInstance,
mock: AnyMockInstance,
): AnyFunction | undefined => {
return (
(mock.getMockImplementation() as AnyFunction | undefined) ??
Expand All @@ -25,7 +25,7 @@ interface TinyspyInternals {
* which is stored on a Symbol key in the mock object.
*/
const getTinyspyInternals = (
mock: MockInstance,
mock: AnyMockInstance,
): TinyspyInternals | undefined => {
const maybeTinyspy = mock as unknown as Record<PropertyKey, unknown>

Expand Down
9 changes: 4 additions & 5 deletions src/stubs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import type {
AsFunction,
Mock,
MockInstance,
NormalizeMockable,
ParametersOf,
} from './types.ts'

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

export const validateMock = <TFunc extends AnyMockable>(
maybeMock: TFunc | MockInstance<TFunc>,
): MockInstance<NormalizeMockable<TFunc>> => {
): MockInstance<TFunc> => {
if (
typeof maybeMock === 'function' &&
'mockImplementation' in maybeMock &&
typeof maybeMock.mockImplementation === 'function'
) {
return maybeMock as unknown as MockInstance<NormalizeMockable<TFunc>>
return maybeMock as unknown as MockInstance<TFunc>
}

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

export const asMock = <TFunc extends AnyMockable>(
mock: MockInstance<TFunc>,
): Mock<NormalizeMockable<TFunc>> => {
return mock as unknown as Mock<NormalizeMockable<TFunc>>
): Mock<TFunc> => {
return mock as unknown as Mock<TFunc>
}
Loading
Loading