Skip to content

Commit 6fdb2ba

Browse files
authored
fix: guard disposable and optional body (#9912)
1 parent fda8986 commit 6fdb2ba

File tree

19 files changed

+112
-4
lines changed

19 files changed

+112
-4
lines changed

packages/runner/src/types/tasks.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1262,7 +1262,7 @@ export interface TestAttachment {
12621262
/** File system path to the attachment */
12631263
path?: string
12641264
/** Inline attachment content as a string or raw binary data */
1265-
body?: string | Uint8Array
1265+
body?: string | Uint8Array | undefined
12661266
}
12671267

12681268
export interface Location {

packages/spy/optional-types.d.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/* eslint-disable ts/ban-ts-comment */
2+
3+
export interface Disposable {
4+
// @ts-ignore -- Symbol.dispose might not be in user types
5+
[Symbol.dispose]: () => void
6+
}

packages/spy/package.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,17 @@
2727
"types": "./dist/index.d.ts",
2828
"default": "./dist/index.js"
2929
},
30+
"./optional-types.js": {
31+
"types": "./optional-types.d.ts"
32+
},
3033
"./*": "./*"
3134
},
3235
"main": "./dist/index.js",
3336
"module": "./dist/index.js",
3437
"types": "./dist/index.d.ts",
3538
"files": [
36-
"dist"
39+
"dist",
40+
"optional-types.d.ts"
3741
],
3842
"scripts": {
3943
"build": "premove dist && rollup -c",

packages/spy/rollup.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ const external = [
1010
...builtinModules,
1111
...Object.keys(pkg.dependencies || {}),
1212
...Object.keys(pkg.peerDependencies || {}),
13+
'@vitest/spy/optional-types.js',
1314
]
1415

1516
const dtsUtils = createDtsUtils()

packages/spy/src/types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import type { Disposable } from '@vitest/spy/optional-types.js'
2+
13
export interface MockResultReturn<T> {
24
type: 'return'
35
/**
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/* eslint-disable ts/ban-ts-comment */
2+
3+
export interface Disposable {
4+
// @ts-ignore -- Symbol.dispose might not be in user types
5+
[Symbol.dispose]: () => void
6+
}

packages/vitest/package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@
4848
"./optional-types.js": {
4949
"types": "./optional-types.d.ts"
5050
},
51+
"./optional-runtime-types.js": {
52+
"types": "./optional-runtime-types.d.ts"
53+
},
5154
"./src/*": "./src/*",
5255
"./globals": {
5356
"types": "./globals.d.ts"

packages/vitest/rollup.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ const external = [
7575
'node:console',
7676
'node:events',
7777
'inspector',
78+
'vitest/optional-runtime-types.js',
7879
'vitest/optional-types.js',
7980
'vitest/browser',
8081
'vite/module-runner',

packages/vitest/src/integrations/vi.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import type {
66
MaybePartiallyMockedDeep,
77
MockInstance,
88
} from '@vitest/spy'
9+
import type { Disposable } from 'vitest/optional-runtime-types.js'
910
import type { RuntimeOptions, SerializedConfig } from '../runtime/config'
1011
import type { VitestMocker } from '../runtime/moduleRunner/moduleMocker'
1112
import type { MockFactoryWithHelper, MockOptions } from '../types/mocker'

pnpm-lock.yaml

Lines changed: 19 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)