vitest 0.0.20 → 0.0.24

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.gh.md ADDED
@@ -0,0 +1,178 @@
1
+ # vitest
2
+
3
+ [![NPM version](https://img.shields.io/npm/v/vitest?color=a1b858&label=)](https://www.npmjs.com/package/vitest)
4
+
5
+ A blazing fast unit test framework powered by Vite.
6
+
7
+ > **This project is currently in closed beta exclusively for Sponsors.**
8
+ > Become a Sponsor of [@patak-js](https://github.com/sponsors/patak-js) or [@antfu](https://github.com/sponsors/antfu) to access the source code and issues tracker.
9
+
10
+ ## Features
11
+
12
+ - [Vite](https://vitejs.dev/)'s config, transformers, resolvers, and plugins.
13
+ - [Jest Snapshot](https://jestjs.io/docs/snapshot-testing)
14
+ - [Chai](https://www.chaijs.com/) for assertions
15
+ - [Sinon](https://sinonjs.org/) for mocking
16
+ - [JSDOM](https://github.com/jsdom/jsdom) for DOM mocking
17
+ - Async suite / test, top level await
18
+ - ESM friendly
19
+ - Out-of-box TypeScript support
20
+ - Suite and Test filtering (skip, only, todo)
21
+
22
+ ```ts
23
+ import { it, describe, expect, assert } from 'vitest'
24
+
25
+ describe('suite name', () => {
26
+ it('foo', () => {
27
+ expect(1 + 1).toEqual(2)
28
+ expect(true).to.be.true
29
+ })
30
+
31
+ it('bar', () => {
32
+ assert.equal(Math.sqrt(4), 2)
33
+ })
34
+
35
+ it('snapshot', () => {
36
+ expect({ foo: 'bar' }).toMatchSnapshot()
37
+ })
38
+ })
39
+ ```
40
+
41
+ ```bash
42
+ $ npx vitest
43
+ ```
44
+
45
+ ## Configuration
46
+
47
+ `vitest` will read your root `vite.config.ts` when it present to match with the plugins and setup as your Vite app. If you want to it to have a different configuration for testing, you could either:
48
+
49
+ - Create `vitest.config.ts`, which will have the higher priority
50
+ - Pass `--config` option to CLI, e.g. `vitest --config ./path/to/vitest.config.ts`
51
+ - Use `process.env.VITEST` to conditionally apply differnet configuration in `vite.config.ts`
52
+
53
+ To configure `vitest` itself, add `test` property in your Vite config
54
+
55
+ ```ts
56
+ // vite.config.ts
57
+ import { defineConfig } from 'vite'
58
+
59
+ export default defineConfig({
60
+ test: {
61
+ // ...
62
+ }
63
+ })
64
+ ```
65
+
66
+ ## Global APIs
67
+
68
+ By default, `vitest` does not provide global APIs for explicitness. If you prefer to use the APIs globally like Jest, you can pass the `--global` option to CLI or add `global: true` in the config.
69
+
70
+ ```ts
71
+ // vite.config.ts
72
+ import { defineConfig } from 'vite'
73
+
74
+ export default defineConfig({
75
+ test: {
76
+ global: true
77
+ }
78
+ })
79
+ ```
80
+
81
+ To get TypeScript working with the global APIs, add `vitest/global` to the `types` filed in your `tsconfig.json`
82
+
83
+ ```json
84
+ // tsconfig.json
85
+ {
86
+ "compilerOptions": {
87
+ "types": [
88
+ "vitest/global"
89
+ ]
90
+ }
91
+ }
92
+ ```
93
+
94
+ ## Filtering
95
+
96
+ ### Skipping suites and tasks
97
+
98
+ Use `.skip` to avoid running certain suites or tests
99
+
100
+ ```ts
101
+ describe.skip('skipped suite', () => {
102
+ it('task', () => {
103
+ // Suite skipped, no error
104
+ assert.equal(Math.sqrt(4), 3)
105
+ })
106
+ })
107
+
108
+ describe('suite', () => {
109
+ it.skip('skipped task', () => {
110
+ // Task skipped, no error
111
+ assert.equal(Math.sqrt(4), 3)
112
+ })
113
+ })
114
+ ```
115
+
116
+ ### Selecting suites and tests to run
117
+
118
+ Use `.only` to only run certain suites or tests
119
+
120
+ ```ts
121
+ // Only this suite (and others marked with only) are run
122
+ describe.only('suite', () => {
123
+ it('task', () => {
124
+ assert.equal(Math.sqrt(4), 3)
125
+ })
126
+ })
127
+
128
+ describe('another suite', () => {
129
+ it('skipped task', () => {
130
+ // Task skipped, as tests are running in Only mode
131
+ assert.equal(Math.sqrt(4), 3)
132
+ })
133
+
134
+ it.only('task', () => {
135
+ // Only this task (and others marked with only) are run
136
+ assert.equal(Math.sqrt(4), 2)
137
+ })
138
+ })
139
+ ```
140
+
141
+ ### Unimplemented suites and tests
142
+
143
+ Use `.todo` to stub suites and tests that should be implemented
144
+
145
+ ```ts
146
+ // An entry will be shown in the report for this suite
147
+ describe.todo('unimplemented suite')
148
+
149
+ // An entry will be shown in the report for this task
150
+ describe('suite', () => {
151
+ it.todo('unimplemented task')
152
+ })
153
+ ```
154
+
155
+ ## TODO
156
+
157
+ - [x] Reporter & Better output
158
+ - [x] Task filter
159
+ - [x] Mock
160
+ - [x] Global Mode & Types
161
+ - [ ] Parallel Executing
162
+ - [x] CLI Help
163
+ - [x] JSDom
164
+ - [x] Watch
165
+ - [ ] Source Map
166
+ - [ ] Coverage
167
+
168
+ ## Sponsors
169
+
170
+ <p align="center">
171
+ <a href="https://cdn.jsdelivr.net/gh/antfu/static/sponsors.svg">
172
+ <img src='https://cdn.jsdelivr.net/gh/antfu/static/sponsors.svg'/>
173
+ </a>
174
+ </p>
175
+
176
+ ## License
177
+
178
+ [MIT](./LICENSE) License © 2021 [Anthony Fu](https://github.com/antfu)
package/README.md CHANGED
@@ -2,174 +2,7 @@
2
2
 
3
3
  [![NPM version](https://img.shields.io/npm/v/vitest?color=a1b858&label=)](https://www.npmjs.com/package/vitest)
4
4
 
5
- A blazing fast test runner powered by Vite.
5
+ A blazing fast unit test framework powered by Vite.
6
6
 
7
- ## Features
8
-
9
- - [Vite](https://vitejs.dev/)'s config, transformers, resolvers, and plugins.
10
- - [Jest Snapshot](https://jestjs.io/docs/snapshot-testing)
11
- - [Chai](https://www.chaijs.com/) for assertions
12
- - [Sinon](https://sinonjs.org/) for mocking
13
- - [JSDOM](https://github.com/jsdom/jsdom) for DOM mocking
14
- - Async suite / test, top level await
15
- - ESM friendly
16
- - Out-of-box TypeScript support
17
- - Suite and Test filtering (skip, only, todo)
18
-
19
- ```ts
20
- import { it, describe, expect, assert } from 'vitest'
21
-
22
- describe('suite name', () => {
23
- it('foo', () => {
24
- expect(1 + 1).toEqual(2)
25
- expect(true).to.be.true
26
- })
27
-
28
- it('bar', () => {
29
- assert.equal(Math.sqrt(4), 2)
30
- })
31
-
32
- it('snapshot', () => {
33
- expect({ foo: 'bar' }).toMatchSnapshot()
34
- })
35
- })
36
- ```
37
-
38
- ```bash
39
- $ npx vitest
40
- ```
41
-
42
- ## Configuration
43
-
44
- `vitest` will read your root `vite.config.ts` when it present to match with the plugins and setup as your Vite app. If you want to it to have a different configuration for testing, you could either:
45
-
46
- - Create `vitest.config.ts`, which will have the higher priority
47
- - Pass `--config` option to CLI, e.g. `vitest --config ./path/to/vitest.config.ts`
48
- - Use `process.env.VITEST` to conditionally apply differnet configuration in `vite.config.ts`
49
-
50
- To configure `vitest` itself, add `test` property in your Vite config
51
-
52
- ```ts
53
- // vite.config.ts
54
- import { defineConfig } from 'vite'
55
-
56
- export default defineConfig({
57
- test: {
58
- // ...
59
- }
60
- })
61
- ```
62
-
63
- ## Global APIs
64
-
65
- By default, `vitest` does not provide global APIs for explicitness. If you prefer to use the APIs globally like Jest, you can pass the `--global` option to CLI or add `global: true` in the config.
66
-
67
- ```ts
68
- // vite.config.ts
69
- import { defineConfig } from 'vite'
70
-
71
- export default defineConfig({
72
- test: {
73
- global: true
74
- }
75
- })
76
- ```
77
-
78
- To get TypeScript working with the global APIs, add `vitest/global` to the `types` filed in your `tsconfig.json`
79
-
80
- ```json
81
- // tsconfig.json
82
- {
83
- "compilerOptions": {
84
- "types": [
85
- "vitest/global"
86
- ]
87
- }
88
- }
89
- ```
90
-
91
- ## Filtering
92
-
93
- ### Skipping suites and tasks
94
-
95
- Use `.skip` to avoid running certain suites or tests
96
-
97
- ```ts
98
- describe.skip('skipped suite', () => {
99
- it('task', () => {
100
- // Suite skipped, no error
101
- assert.equal(Math.sqrt(4), 3)
102
- })
103
- })
104
-
105
- describe('suite', () => {
106
- it.skip('skipped task', () => {
107
- // Task skipped, no error
108
- assert.equal(Math.sqrt(4), 3)
109
- })
110
- })
111
- ```
112
-
113
- ### Selecting suites and tests to run
114
-
115
- Use `.only` to only run certain suites or tests
116
-
117
- ```ts
118
- // Only this suite (and others marked with only) are run
119
- describe.only('suite', () => {
120
- it('task', () => {
121
- assert.equal(Math.sqrt(4), 3)
122
- })
123
- })
124
-
125
- describe('another suite', () => {
126
- it('skipped task', () => {
127
- // Task skipped, as tests are running in Only mode
128
- assert.equal(Math.sqrt(4), 3)
129
- })
130
-
131
- it.only('task', () => {
132
- // Only this task (and others marked with only) are run
133
- assert.equal(Math.sqrt(4), 2)
134
- })
135
- })
136
- ```
137
-
138
- ### Unimplemented suites and tests
139
-
140
- Use `.todo` to stub suites and tests that should be implemented
141
-
142
- ```ts
143
- // An entry will be shown in the report for this suite
144
- describe.todo('unimplemented suite')
145
-
146
- // An entry will be shown in the report for this task
147
- describe('suite', () => {
148
- it.todo('unimplemented task')
149
- })
150
- ```
151
-
152
- ## TODO
153
-
154
- - [x] Reporter & Better output
155
- - [x] Task filter
156
- - [x] Mock
157
- - [x] Global Mode & Types
158
- - [ ] Parallel Executing
159
- - [ ] CLI Help (Use yargs)
160
- - [x] JSDom
161
- - [ ] Watch
162
- - [ ] Source Map
163
- - [ ] Coverage
164
-
165
- ## Sponsors
166
-
167
- <p align="center">
168
- <a href="https://cdn.jsdelivr.net/gh/antfu/static/sponsors.svg">
169
- <img src='https://cdn.jsdelivr.net/gh/antfu/static/sponsors.svg'/>
170
- </a>
171
- </p>
172
-
173
- ## License
174
-
175
- [MIT](./LICENSE) License © 2021 [Anthony Fu](https://github.com/antfu)
7
+ > **This project is currently in closed beta exclusively for Sponsors.**
8
+ > Become a Sponsor of [@patak-js](https://github.com/sponsors/patak-js) or [@antfu](https://github.com/sponsors/antfu) to access the source code and issues tracker.
package/README.npm.md ADDED
@@ -0,0 +1,8 @@
1
+ # vitest
2
+
3
+ [![NPM version](https://img.shields.io/npm/v/vitest?color=a1b858&label=)](https://www.npmjs.com/package/vitest)
4
+
5
+ A blazing fast unit test framework powered by Vite.
6
+
7
+ > **This project is currently in closed beta exclusively for Sponsors.**
8
+ > Become a Sponsor of [@patak-js](https://github.com/sponsors/patak-js) or [@antfu](https://github.com/sponsors/antfu) to access the source code and issues tracker.
package/bin/vitest.mjs CHANGED
@@ -1,4 +1,4 @@
1
1
  #!/usr/bin/env node
2
2
  'use strict'
3
3
 
4
- import '../dist/entry.js'
4
+ import '../dist/node/cli.js'
package/dist/index.d.ts CHANGED
@@ -1,8 +1,16 @@
1
+ import { UserOptions } from './types';
1
2
  export * from './types';
2
3
  export * from './suite';
3
- export * from './config';
4
4
  export * from './integrations/chai';
5
5
  export * from './integrations/sinon';
6
+ declare module 'vite' {
7
+ interface UserConfig {
8
+ /**
9
+ * Options for Vitest
10
+ */
11
+ test?: UserOptions;
12
+ }
13
+ }
6
14
  declare global {
7
15
  namespace Chai {
8
16
  interface Assertion {
package/dist/index.js CHANGED
@@ -1,6 +1,4 @@
1
- /* eslint-disable @typescript-eslint/no-namespace */
2
1
  export * from './types';
3
2
  export * from './suite';
4
- export * from './config';
5
3
  export * from './integrations/chai';
6
4
  export * from './integrations/sinon';
@@ -1,2 +1,2 @@
1
- import { Config } from 'vitest';
2
- export declare function setupChai(config: Config): Promise<void>;
1
+ import { ResolvedConfig } from 'vitest';
2
+ export declare function setupChai(config: ResolvedConfig): Promise<void>;
@@ -5,8 +5,5 @@ import { SnapshotPlugin } from './snapshot';
5
5
  export async function setupChai(config) {
6
6
  chai.use(SinonChai);
7
7
  chai.use(JestChaiExpect());
8
- chai.use(await SnapshotPlugin({
9
- rootDir: config.rootDir || process.cwd(),
10
- update: config.updateSnapshot,
11
- }));
8
+ chai.use(await SnapshotPlugin(config));
12
9
  }
@@ -1,7 +1,7 @@
1
1
  import { ChaiPlugin } from '../types';
2
2
  import { SnapshotManager } from './manager';
3
3
  export interface SnapshotOptions {
4
- rootDir: string;
4
+ root: string;
5
5
  update?: boolean;
6
6
  }
7
7
  export declare function getSnapshotManager(): SnapshotManager;
@@ -6,7 +6,7 @@ export function getSnapshotManager() {
6
6
  return _manager;
7
7
  }
8
8
  export async function SnapshotPlugin(options) {
9
- const { rootDir } = options;
9
+ const { root: rootDir } = options;
10
10
  _manager = new SnapshotManager({
11
11
  rootDir,
12
12
  update: options.update,
File without changes
@@ -1,5 +1,5 @@
1
- import { globalApis } from './constants';
2
- import * as index from './index';
1
+ import { globalApis } from '../constants';
2
+ import * as index from '../index';
3
3
  export function registerApiGlobally() {
4
4
  globalApis.forEach((api) => {
5
5
  // @ts-expect-error
@@ -1,130 +1,163 @@
1
1
  // SEE https://github.com/jsdom/jsdom/blob/master/lib/jsdom/living/interfaces.js
2
2
  const LIVING_KEYS = [
3
3
  'DOMException',
4
+ 'URL',
5
+ 'URLSearchParams',
6
+ 'EventTarget',
4
7
  'NamedNodeMap',
5
- 'Attr',
6
8
  'Node',
9
+ 'Attr',
7
10
  'Element',
8
11
  'DocumentFragment',
9
- 'HTMLDocument',
12
+ 'DOMImplementation',
10
13
  'Document',
14
+ 'XMLDocument',
11
15
  'CharacterData',
16
+ 'Text',
17
+ 'CDATASection',
18
+ 'ProcessingInstruction',
12
19
  'Comment',
13
20
  'DocumentType',
14
- 'DOMImplementation',
15
- 'ProcessingInstruction',
16
- 'Image',
17
- 'Text',
18
- 'Event',
19
- 'CustomEvent',
20
- 'MessageEvent',
21
- 'ErrorEvent',
22
- 'HashChangeEvent',
23
- 'PopStateEvent',
24
- 'UIEvent',
25
- 'MouseEvent',
26
- 'KeyboardEvent',
27
- 'TouchEvent',
28
- 'ProgressEvent',
29
- 'EventTarget',
30
- 'Location',
31
- 'History',
21
+ 'NodeList',
22
+ 'HTMLCollection',
23
+ 'HTMLOptionsCollection',
24
+ 'DOMStringMap',
25
+ 'DOMTokenList',
26
+ 'StyleSheetList',
32
27
  'HTMLElement',
33
- 'HTMLAnchorElement',
34
- 'HTMLAppletElement',
35
- 'HTMLAreaElement',
36
- 'HTMLAudioElement',
28
+ 'HTMLHeadElement',
29
+ 'HTMLTitleElement',
37
30
  'HTMLBaseElement',
31
+ 'HTMLLinkElement',
32
+ 'HTMLMetaElement',
33
+ 'HTMLStyleElement',
38
34
  'HTMLBodyElement',
35
+ 'HTMLHeadingElement',
36
+ 'HTMLParagraphElement',
37
+ 'HTMLHRElement',
38
+ 'HTMLPreElement',
39
+ 'HTMLUListElement',
40
+ 'HTMLOListElement',
41
+ 'HTMLLIElement',
42
+ 'HTMLMenuElement',
43
+ 'HTMLDListElement',
44
+ 'HTMLDivElement',
45
+ 'HTMLAnchorElement',
46
+ 'HTMLAreaElement',
39
47
  'HTMLBRElement',
40
48
  'HTMLButtonElement',
41
49
  'HTMLCanvasElement',
42
50
  'HTMLDataElement',
43
51
  'HTMLDataListElement',
52
+ 'HTMLDetailsElement',
44
53
  'HTMLDialogElement',
45
54
  'HTMLDirectoryElement',
46
- 'HTMLDivElement',
47
- 'HTMLDListElement',
48
- 'HTMLEmbedElement',
49
55
  'HTMLFieldSetElement',
50
56
  'HTMLFontElement',
51
57
  'HTMLFormElement',
52
- 'HTMLFrameElement',
53
- 'HTMLFrameSetElement',
54
- 'HTMLHeadingElement',
55
- 'HTMLHeadElement',
56
- 'HTMLHRElement',
57
58
  'HTMLHtmlElement',
58
- 'HTMLIFrameElement',
59
59
  'HTMLImageElement',
60
60
  'HTMLInputElement',
61
61
  'HTMLLabelElement',
62
62
  'HTMLLegendElement',
63
- 'HTMLLIElement',
64
- 'HTMLLinkElement',
65
63
  'HTMLMapElement',
64
+ 'HTMLMarqueeElement',
66
65
  'HTMLMediaElement',
67
- 'HTMLMenuElement',
68
- 'HTMLMetaElement',
69
66
  'HTMLMeterElement',
70
67
  'HTMLModElement',
71
- 'HTMLObjectElement',
72
- 'HTMLOListElement',
73
68
  'HTMLOptGroupElement',
74
69
  'HTMLOptionElement',
75
70
  'HTMLOutputElement',
76
- 'HTMLParagraphElement',
77
- 'HTMLParamElement',
78
- 'HTMLPreElement',
71
+ 'HTMLPictureElement',
79
72
  'HTMLProgressElement',
80
73
  'HTMLQuoteElement',
81
74
  'HTMLScriptElement',
82
75
  'HTMLSelectElement',
76
+ 'HTMLSlotElement',
83
77
  'HTMLSourceElement',
84
78
  'HTMLSpanElement',
85
- 'HTMLStyleElement',
86
79
  'HTMLTableCaptionElement',
87
80
  'HTMLTableCellElement',
88
81
  'HTMLTableColElement',
89
- 'HTMLTableDataCellElement',
90
82
  'HTMLTableElement',
91
- 'HTMLTableHeaderCellElement',
92
83
  'HTMLTimeElement',
93
- 'HTMLTitleElement',
94
84
  'HTMLTableRowElement',
95
85
  'HTMLTableSectionElement',
96
86
  'HTMLTemplateElement',
97
87
  'HTMLTextAreaElement',
98
- 'HTMLTrackElement',
99
- 'HTMLUListElement',
100
88
  'HTMLUnknownElement',
89
+ 'HTMLFrameElement',
90
+ 'HTMLFrameSetElement',
91
+ 'HTMLIFrameElement',
92
+ 'HTMLEmbedElement',
93
+ 'HTMLObjectElement',
94
+ 'HTMLParamElement',
101
95
  'HTMLVideoElement',
102
- 'StyleSheet',
103
- 'MediaList',
104
- 'CSSStyleSheet',
105
- 'CSSRule',
106
- 'CSSStyleRule',
107
- 'CSSMediaRule',
108
- 'CSSImportRule',
109
- 'CSSStyleDeclaration',
110
- 'StyleSheetList',
111
- 'XPathException',
112
- 'XPathExpression',
113
- 'XPathResult',
114
- 'XPathEvaluator',
115
- 'HTMLCollection',
116
- 'NodeFilter',
117
- 'NodeIterator',
118
- 'NodeList',
96
+ 'HTMLAudioElement',
97
+ 'HTMLTrackElement',
98
+ 'SVGElement',
99
+ 'SVGGraphicsElement',
100
+ 'SVGSVGElement',
101
+ 'SVGTitleElement',
102
+ 'SVGAnimatedString',
103
+ 'SVGNumber',
104
+ 'SVGStringList',
105
+ 'Event',
106
+ 'CloseEvent',
107
+ 'CustomEvent',
108
+ 'MessageEvent',
109
+ 'ErrorEvent',
110
+ 'HashChangeEvent',
111
+ 'PopStateEvent',
112
+ 'StorageEvent',
113
+ 'ProgressEvent',
114
+ 'PageTransitionEvent',
115
+ 'UIEvent',
116
+ 'FocusEvent',
117
+ 'InputEvent',
118
+ 'MouseEvent',
119
+ 'KeyboardEvent',
120
+ 'TouchEvent',
121
+ 'CompositionEvent',
122
+ 'WheelEvent',
123
+ 'BarProp',
124
+ 'External',
125
+ 'Location',
126
+ 'History',
127
+ 'Screen',
128
+ 'Performance',
129
+ 'Navigator',
130
+ 'PluginArray',
131
+ 'MimeTypeArray',
132
+ 'Plugin',
133
+ 'MimeType',
134
+ 'FileReader',
119
135
  'Blob',
120
136
  'File',
121
137
  'FileList',
138
+ 'ValidityState',
139
+ 'DOMParser',
140
+ 'XMLSerializer',
122
141
  'FormData',
123
- 'XMLHttpRequest',
124
142
  'XMLHttpRequestEventTarget',
125
143
  'XMLHttpRequestUpload',
126
- 'DOMTokenList',
127
- 'URL',
144
+ 'XMLHttpRequest',
145
+ 'WebSocket',
146
+ 'NodeFilter',
147
+ 'NodeIterator',
148
+ 'TreeWalker',
149
+ 'AbstractRange',
150
+ 'Range',
151
+ 'StaticRange',
152
+ 'Selection',
153
+ 'Storage',
154
+ 'CustomElementRegistry',
155
+ 'ShadowRoot',
156
+ 'MutationObserver',
157
+ 'MutationRecord',
158
+ 'Headers',
159
+ 'AbortController',
160
+ 'AbortSignal',
128
161
  ];
129
162
  const OTHER_KEYS = [
130
163
  'addEventListener',
@@ -0,0 +1,10 @@
1
+ import type { UserOptions } from '../types';
2
+ declare global {
3
+ namespace NodeJS {
4
+ interface Process {
5
+ __vitest__: {
6
+ options: Required<UserOptions>;
7
+ };
8
+ }
9
+ }
10
+ }