Skip to content

Commit fb15015

Browse files
authored
fix: reference chai types in every d.ts chunk (#11618)
1 parent a967d8f commit fb15015

8 files changed

Lines changed: 286 additions & 1 deletion

File tree

‎packages/vitest/rollup.config.js‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,16 @@ export default ({ watch }) =>
165165
}
166166
},
167167
},
168+
{
169+
// rollup-plugin-dts drops reference directives of .ts sources,
170+
// so every chunk that uses the global `Chai` namespace loads @types/chai here
171+
name: 'vitest-chai-type-reference',
172+
renderChunk(code) {
173+
if (/\bChai\./.test(code)) {
174+
return `/// <reference types="chai" />\n${code}`
175+
}
176+
},
177+
},
168178
],
169179
},
170180
])

‎pnpm-lock.yaml‎

Lines changed: 220 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"name": "@vitest/test-integration-dts-chai-types",
3+
"type": "module",
4+
"private": true,
5+
"scripts": {
6+
"test": "pnpm test:ts5 && pnpm test:ts7",
7+
"test:ts5": "node node_modules/typescript/bin/tsc -b --force tsconfig.json tsconfig.runtime.json",
8+
"test:ts7": "node node_modules/typescript-7/bin/tsc -b --force tsconfig.json tsconfig.runtime.json"
9+
},
10+
"devDependencies": {
11+
"typescript": "catalog:",
12+
"typescript-7": "npm:typescript@^7.0.2",
13+
"vitest": "workspace:*"
14+
}
15+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import type { Environment } from 'vitest/runtime'
2+
3+
export default <Environment>{
4+
name: 'custom',
5+
viteEnvironment: 'ssr',
6+
setup() {
7+
return {
8+
teardown() {},
9+
}
10+
},
11+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { assert, expect, test } from 'vitest'
2+
3+
test('chai api', async () => {
4+
expect('a').not.toBe('b')
5+
expect(1).to.equal(1)
6+
expect([1, 2]).to.not.include(3)
7+
expect({ a: 1 }).to.have.property('a').that.is.a('number')
8+
expect.soft(1).not.toBe(2)
9+
await expect(Promise.resolve(1)).resolves.not.toBe(2)
10+
assert.strictEqual(1, 1)
11+
})
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"extends": ["../_shared/tsconfig.patch.json"],
3+
"compilerOptions": {
4+
"target": "ESNext",
5+
"module": "ESNext",
6+
"moduleResolution": "Bundler",
7+
"types": [],
8+
"strict": true,
9+
"noEmit": true,
10+
"skipLibCheck": false
11+
},
12+
"include": ["src/expect.ts"]
13+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"extends": "./tsconfig.json",
3+
"include": ["src/environment.ts"]
4+
}

‎test/e2e/dts/exact-optional-property-no-node/tsconfig.json‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
"declarationMap": true,
1212
"sourceMap": true,
1313
"verbatimModuleSyntax": true,
14-
"skipLibCheck": false
14+
"skipLibCheck": false,
15+
"noEmit": true
1516
}
1617
}

0 commit comments

Comments
 (0)