-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat!: split vitest into separate packages (#2575)
- Loading branch information
1 parent
e641a11
commit c8e6fb6
Showing
44 changed files
with
1,065 additions
and
509 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# @vitest/expect | ||
|
||
Jest's expect matchers as a Chai plugin. | ||
|
||
## Usage | ||
|
||
```js | ||
import * as chai from 'chai' | ||
import { JestAsymmetricMatchers, JestChaiExpect, JestExtend } from '@vitest/expect' | ||
|
||
// allows using expect.extend instead of chai.use to extend plugins | ||
chai.use(JestExtend) | ||
// adds all jest matchers to expect | ||
chai.use(JestChaiExpect) | ||
// adds asymmetric matchers like stringContaining, objectContaining | ||
chai.use(JestAsymmetricMatchers) | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
{ | ||
"name": "@vitest/expect", | ||
"type": "module", | ||
"version": "0.26.2", | ||
"description": "Jest's expect matchers as a Chai plugin", | ||
"license": "MIT", | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/vitest-dev/vitest.git", | ||
"directory": "packages/expect" | ||
}, | ||
"sideEffects": false, | ||
"exports": { | ||
".": { | ||
"types": "./dist/index.d.ts", | ||
"import": "./dist/index.js" | ||
}, | ||
"./*": "./*" | ||
}, | ||
"main": "./dist/index.js", | ||
"module": "./dist/index.js", | ||
"types": "./dist/index.d.ts", | ||
"files": [ | ||
"dist" | ||
], | ||
"scripts": { | ||
"build": "rimraf dist && rollup -c", | ||
"dev": "rollup -c --watch", | ||
"prepublishOnly": "pnpm build" | ||
}, | ||
"dependencies": { | ||
"@vitest/spy": "workspace:*", | ||
"@vitest/utils": "workspace:*", | ||
"chai": "^4.3.7", | ||
"picocolors": "^1.0.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import { builtinModules } from 'module' | ||
import esbuild from 'rollup-plugin-esbuild' | ||
import dts from 'rollup-plugin-dts' | ||
import { defineConfig } from 'rollup' | ||
import pkg from './package.json' | ||
|
||
const external = [ | ||
...builtinModules, | ||
...Object.keys(pkg.dependencies || {}), | ||
...Object.keys(pkg.peerDependencies || {}), | ||
] | ||
|
||
const plugins = [ | ||
esbuild({ | ||
target: 'node14', | ||
}), | ||
] | ||
|
||
export default defineConfig([ | ||
{ | ||
input: 'src/index.ts', | ||
output: { | ||
dir: 'dist', | ||
format: 'esm', | ||
entryFileNames: '[name].js', | ||
chunkFileNames: 'chunk-[name].js', | ||
}, | ||
external, | ||
plugins, | ||
onwarn, | ||
}, | ||
{ | ||
input: 'src/index.ts', | ||
output: { | ||
dir: 'dist', | ||
entryFileNames: '[name].d.ts', | ||
format: 'esm', | ||
}, | ||
external, | ||
plugins: [ | ||
dts({ respectExternal: true }), | ||
], | ||
onwarn, | ||
}, | ||
]) | ||
|
||
function onwarn(message) { | ||
if (['EMPTY_BUNDLE', 'CIRCULAR_DEPENDENCY'].includes(message.code)) | ||
return | ||
console.error(message) | ||
} |
2 changes: 1 addition & 1 deletion
2
...vitest/src/integrations/chai/constants.ts → packages/expect/src/constants.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
export const GLOBAL_EXPECT = Symbol.for('expect-global') | ||
export const MATCHERS_OBJECT = Symbol.for('matchers-object') | ||
export const JEST_MATCHERS_OBJECT = Symbol.for('$$jest-matchers-object') | ||
export const GLOBAL_EXPECT = Symbol.for('expect-global') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
export * from './jest-asymmetric-matchers' | ||
export * from './jest-utils' | ||
export * from './constants' | ||
export * from './types' | ||
export { getState, setState } from './state' | ||
export { JestChaiExpect } from './jest-expect' | ||
export { JestExtend } from './jest-extend' |
4 changes: 2 additions & 2 deletions
4
...grations/chai/jest-asymmetric-matchers.ts → ...es/expect/src/jest-asymmetric-matchers.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import type { MatcherState } from './types' | ||
import { GLOBAL_EXPECT, JEST_MATCHERS_OBJECT, MATCHERS_OBJECT } from './constants' | ||
|
||
if (!Object.prototype.hasOwnProperty.call(globalThis, MATCHERS_OBJECT)) { | ||
const globalState = new WeakMap<Vi.ExpectStatic, MatcherState>() | ||
const matchers = Object.create(null) | ||
Object.defineProperty(globalThis, MATCHERS_OBJECT, { | ||
get: () => globalState, | ||
}) | ||
Object.defineProperty(globalThis, JEST_MATCHERS_OBJECT, { | ||
configurable: true, | ||
get: () => ({ | ||
state: globalState.get((globalThis as any)[GLOBAL_EXPECT]), | ||
matchers, | ||
}), | ||
}) | ||
} | ||
|
||
export const getState = <State extends MatcherState = MatcherState>(expect: Vi.ExpectStatic): State => | ||
(globalThis as any)[MATCHERS_OBJECT].get(expect) | ||
|
||
export const setState = <State extends MatcherState = MatcherState>( | ||
state: Partial<State>, | ||
expect: Vi.ExpectStatic, | ||
): void => { | ||
const map = (globalThis as any)[MATCHERS_OBJECT] | ||
const current = map.get(expect) || {} | ||
Object.assign(current, state) | ||
map.set(expect, current) | ||
} |
Oops, something went wrong.