Skip to content

Commit cc98c61

Browse files
authored
perf: remove chai as a direct dependency, keep it in @vitest/expect (#8461)
1 parent 903815d commit cc98c61

File tree

10 files changed

+34
-148
lines changed

10 files changed

+34
-148
lines changed

packages/browser/src/node/plugin.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -275,9 +275,9 @@ export default (parentServer: ParentBrowserProject, base = '/'): Plugin[] => {
275275
const include = [
276276
'vitest > expect-type',
277277
'vitest > @vitest/snapshot > magic-string',
278-
'vitest > chai',
279-
'vitest > chai > loupe',
280278
'vitest > @vitest/runner > strip-literal',
279+
'vitest > @vitest/expect > chai',
280+
'vitest > @vitest/expect > chai > loupe',
281281
'vitest > @vitest/utils > loupe',
282282
'@vitest/browser > @testing-library/user-event',
283283
'@vitest/browser > @testing-library/dom',

packages/expect/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@
4040
"tinyrainbow": "catalog:"
4141
},
4242
"devDependencies": {
43-
"@vitest/runner": "workspace:*",
44-
"rollup-plugin-copy": "^3.5.0"
43+
"@vitest/runner": "workspace:*"
4544
}
4645
}

packages/expect/src/index.ts

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,25 @@
1-
export * from './constants'
1+
export {
2+
ASYMMETRIC_MATCHERS_OBJECT,
3+
GLOBAL_EXPECT,
4+
JEST_MATCHERS_OBJECT,
5+
MATCHERS_OBJECT,
6+
} from './constants'
27
export { customMatchers } from './custom-matchers'
3-
export * from './jest-asymmetric-matchers'
8+
export type { AsymmetricMatcherInterface } from './jest-asymmetric-matchers'
9+
export {
10+
Any,
11+
Anything,
12+
ArrayContaining,
13+
AsymmetricMatcher,
14+
JestAsymmetricMatchers,
15+
ObjectContaining,
16+
StringContaining,
17+
StringMatching,
18+
} from './jest-asymmetric-matchers'
419
export { JestChaiExpect } from './jest-expect'
520
export { JestExtend } from './jest-extend'
621
export { addCustomEqualityTesters } from './jest-matcher-utils'
722
export * from './jest-utils'
823
export { getState, setState } from './state'
924
export * from './types'
25+
export * as chai from 'chai'

packages/vitest/package.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,15 +156,13 @@
156156
}
157157
},
158158
"dependencies": {
159-
"@types/chai": "catalog:",
160159
"@vitest/expect": "workspace:*",
161160
"@vitest/mocker": "workspace:*",
162161
"@vitest/pretty-format": "workspace:^",
163162
"@vitest/runner": "workspace:*",
164163
"@vitest/snapshot": "workspace:*",
165164
"@vitest/spy": "workspace:*",
166165
"@vitest/utils": "workspace:*",
167-
"chai": "catalog:",
168166
"debug": "catalog:",
169167
"es-module-lexer": "^1.7.0",
170168
"expect-type": "^1.2.2",

packages/vitest/src/integrations/chai/config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import * as chai from 'chai'
1+
import { chai } from '@vitest/expect'
22

33
export function setupChaiConfig(config: ChaiConfig): void {
44
Object.assign(chai.config, config)

packages/vitest/src/integrations/chai/index.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@ import type { TaskPopulated, Test } from '@vitest/runner'
33
import {
44
addCustomEqualityTesters,
55
ASYMMETRIC_MATCHERS_OBJECT,
6+
chai,
67
customMatchers,
78
getState,
89
GLOBAL_EXPECT,
910
setState,
1011
} from '@vitest/expect'
1112
import { getCurrentTest } from '@vitest/runner'
1213
import { getTestName } from '@vitest/runner/utils'
13-
import * as chai from 'chai'
1414
import { getCurrentEnvironment, getWorkerState } from '../../runtime/utils'
1515
import { createExpectPoll } from './poll'
1616
import './setup'
@@ -121,5 +121,6 @@ Object.defineProperty(globalThis, GLOBAL_EXPECT, {
121121
configurable: true,
122122
})
123123

124-
export { assert, should } from 'chai'
124+
export const assert: Chai.Assert = chai.assert
125+
export const should: () => Chai.Should = chai.should
125126
export { chai, globalExpect as expect }

packages/vitest/src/integrations/chai/poll.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { Assertion, ExpectStatic } from '@vitest/expect'
22
import type { Test } from '@vitest/runner'
3+
import { chai } from '@vitest/expect'
34
import { getSafeTimers } from '@vitest/utils'
4-
import * as chai from 'chai'
55
import { getWorkerState } from '../../runtime/utils'
66

77
// these matchers are not supported because they don't make sense with poll

packages/vitest/src/integrations/chai/setup.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import {
2+
chai,
23
JestAsymmetricMatchers,
34
JestChaiExpect,
45
JestExtend,
56
} from '@vitest/expect'
6-
import * as chai from 'chai'
77
import Subset from 'chai-subset'
88
import { SnapshotPlugin } from '../snapshot/chai'
99

0 commit comments

Comments
 (0)