-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add chai config #3066
feat: add chai config #3066
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -1386,3 +1386,45 @@ Path to custom tsconfig, relative to the project root. | |||||||||
- **Default**: `300` | ||||||||||
|
||||||||||
The number of milliseconds after which a test is considered slow and reported as such in the results. | ||||||||||
|
||||||||||
### chaiConfig | ||||||||||
|
||||||||||
- **Type:** `{ includeStack?, showDiff?, truncateThreshold?, useProxy?, proxyExcludedKeys? }` | ||||||||||
- **Default:** `{ includeStack: false, showDiff: true, truncateThreshold: 40, useProxy: true, proxyExcludedKeys: ['then', 'catch', 'inspect', 'toJSON'] }` | ||||||||||
|
||||||||||
Equivalent to [chai config](https://github.com/chaijs/chai/blob/4.x.x/lib/chai/config.js). You can override it in your `vitest.config.ts` file. | ||||||||||
|
||||||||||
#### chaiConfig.includeStack | ||||||||||
|
||||||||||
- **Type:** `boolean` | ||||||||||
- **Default:** `false` | ||||||||||
|
||||||||||
Influences whether stack trace is included in Assertion error message. Default of false suppresses stack trace in the error message. | ||||||||||
|
||||||||||
#### chaiConfig.showDiff | ||||||||||
|
||||||||||
- **Type:** `boolean` | ||||||||||
- **Default:** `true` | ||||||||||
|
||||||||||
influences whether or not the `showDiff` flag should be included in the thrown AssertionErrors. `false` will always be `false`; `true` will be true when the assertion has requested a diff be shown. | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
|
||||||||||
#### chaiConfig.truncateThreshold | ||||||||||
|
||||||||||
- **Type:** `number` | ||||||||||
- **Default:** `40` | ||||||||||
|
||||||||||
Sets length threshold for actual and expected values in assertion errors. If this threshold is exceeded, for example for large data structures, the value is replaced with something like `[ Array(3) ]` or `{ Object (prop1, prop2) }`. Set it to `0` if you want to disable truncating altogether. | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
|
||||||||||
#### chaiConfig.useProxy | ||||||||||
|
||||||||||
- **Type:** `boolean` | ||||||||||
- **Default:** `true` | ||||||||||
|
||||||||||
Defines if chai will use a Proxy to throw an error when a non-existent property is read, which protects users from typos when using property-based assertions. | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This can be removed, because Vitest requires Proxy to exist, so the config is irrelevant. |
||||||||||
|
||||||||||
#### chaiConfig.proxyExcludedKeys | ||||||||||
sheremet-va marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||
|
||||||||||
- **Type:** `string[]` | ||||||||||
- **Default:** `['then', 'catch', 'inspect', 'toJSON']` | ||||||||||
|
||||||||||
Defines which properties should be ignored instead of throwing an error if they do not exist on the assertion. This is only applied if the environment Chai is running in supports proxies and if the `useProxy` configuration setting is enabled. By default, `then` and `inspect` will not throw an error if they do not exist on the assertion object because the `.inspect` property is read by `util.inspect` (for example, when using `console.log` on the assertion object) and `.then` is necessary for promise type-checking. |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -78,3 +78,7 @@ Object.defineProperty(globalThis, GLOBAL_EXPECT, { | |||||
|
||||||
export { assert, should } from 'chai' | ||||||
export { chai, globalExpect as expect } | ||||||
export const setupConfig = (config: chaiConfig) => { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
Object.assign(chai.config, config) | ||||||
} | ||||||
export type chaiConfig = Partial<typeof chai.config> | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -4,6 +4,7 @@ import type { FakeTimerInstallOpts } from '@sinonjs/fake-timers' | |||||
import type { SequenceHooks, SequenceSetupFiles } from '@vitest/runner' | ||||||
import type { BuiltinReporters } from '../node/reporters' | ||||||
import type { TestSequencerConstructor } from '../node/sequencers/types' | ||||||
import type { chaiConfig } from '../integrations/chai' | ||||||
import type { CoverageOptions, ResolvedCoverageOptions } from './coverage' | ||||||
import type { JSDOMOptions } from './jsdom-options' | ||||||
import type { Reporter } from './reporter' | ||||||
|
@@ -583,6 +584,12 @@ export interface InlineConfig { | |||||
* Requires `singleThread: true` OR `threads: false`. | ||||||
*/ | ||||||
inspectBrk?: boolean | ||||||
|
||||||
/** | ||||||
* chai config | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
* https://github.com/chaijs/chai/blob/4.x.x/lib/chai/config.js | ||||||
*/ | ||||||
chaiConfig?: chaiConfig | ||||||
} | ||||||
|
||||||
export interface TypecheckConfig { | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is implied.