vitest 0.0.36 → 0.0.40
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 +32 -3
- package/dist/chunk-LUQHGOPU.js +1 -0
- package/dist/chunk-W4BWZKS2.js +1 -0
- package/dist/chunk-Z2OPSSDM.js +1 -0
- package/dist/global-OOVANJ2U.js +1 -0
- package/dist/index.d.ts +65 -24
- package/dist/index.js +1 -1
- package/dist/node/cli.d.ts +11 -2
- package/dist/node/cli.js +5 -6
- package/dist/node/entry.js +16 -17
- package/dist/{types-d3253f2d.d.ts → types-15d74511.d.ts} +41 -41
- package/package.json +4 -6
- package/dist/chunk-4OVO6RD6.js +0 -1
- package/dist/chunk-CUG6SVUZ.js +0 -1
- package/dist/global-CKRMAXWF.js +0 -1
package/README.gh.md
CHANGED
|
@@ -17,7 +17,7 @@ A blazing fast unit test framework powered by Vite.
|
|
|
17
17
|
|
|
18
18
|
> ⚠️ **DISCLAIMER**: Vitest is still in development and not stable yet. It's not recommended to use it in production.
|
|
19
19
|
|
|
20
|
-
> Vitest requires Vite v2.7
|
|
20
|
+
> Vitest requires Vite v2.7 and Node v16
|
|
21
21
|
|
|
22
22
|
[**Join the Discord!**](https://discord.com/invite/2zYZNngd7y)
|
|
23
23
|
|
|
@@ -174,7 +174,7 @@ For convenience, we also provide a shorthand for passing `--coverage` option to
|
|
|
174
174
|
$ vitest --coverage
|
|
175
175
|
```
|
|
176
176
|
|
|
177
|
-
For more configuration
|
|
177
|
+
For more configuration available, please refer to [c8](https://github.com/bcoe/c8)'s documentation.
|
|
178
178
|
|
|
179
179
|
## Filtering
|
|
180
180
|
|
|
@@ -271,8 +271,36 @@ describe('suite', () => {
|
|
|
271
271
|
})
|
|
272
272
|
```
|
|
273
273
|
|
|
274
|
-
|
|
274
|
+
If you use `.concurrent` in a suite, every tasks in it will be run in parallel
|
|
275
|
+
```ts
|
|
276
|
+
// The two tasks marked with concurrent will be run in parallel
|
|
277
|
+
describe.concurrent('suite', () => {
|
|
278
|
+
it('concurrent task 1', () => {
|
|
279
|
+
assert.equal(Math.sqrt(4), 3)
|
|
280
|
+
})
|
|
281
|
+
it('concurrent task 2', () => {
|
|
282
|
+
assert.equal(Math.sqrt(4), 3)
|
|
283
|
+
})
|
|
284
|
+
// No effect, same as not using .concurrent
|
|
285
|
+
it.concurrent('concurrent task 3', () => {
|
|
286
|
+
assert.equal(Math.sqrt(4), 3)
|
|
287
|
+
})
|
|
288
|
+
})
|
|
289
|
+
```
|
|
290
|
+
|
|
291
|
+
You can also use `.skip`, `.only`, and `.todo` with concurrent suite and tasks. All the following combinations are valid:
|
|
275
292
|
```js
|
|
293
|
+
describe.concurrent(...)
|
|
294
|
+
|
|
295
|
+
describe.skip.concurrent(...)
|
|
296
|
+
describe.concurrent.skip(...)
|
|
297
|
+
|
|
298
|
+
describe.only.concurrent(...)
|
|
299
|
+
describe.concurrent.only(...)
|
|
300
|
+
|
|
301
|
+
describe.todo.concurrent(...)
|
|
302
|
+
describe.concurrent.todo(...)
|
|
303
|
+
|
|
276
304
|
it.concurrent(...)
|
|
277
305
|
|
|
278
306
|
it.skip.concurrent(...)
|
|
@@ -285,6 +313,7 @@ it.todo.concurrent(...)
|
|
|
285
313
|
it.concurrent.todo(...)
|
|
286
314
|
```
|
|
287
315
|
|
|
316
|
+
|
|
288
317
|
## Sponsors
|
|
289
318
|
|
|
290
319
|
<p align="center">
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{e as r,f as a,g as s,h as l,i as c,j as d,k as p,l as u,m as f,n as g,o as x}from"./chunk-Z2OPSSDM.js";import{d as i,f as e}from"./chunk-XPSQDVUG.js";var R={};i(R,{afterAll:()=>u,afterEach:()=>g,assert:()=>v,beforeAll:()=>p,beforeEach:()=>f,chai:()=>m,clearContext:()=>x,createSuiteHooks:()=>s,defaultSuite:()=>a,describe:()=>c,expect:()=>S,it:()=>d,mock:()=>T,should:()=>C,sinon:()=>t,spy:()=>k,stub:()=>y,suite:()=>r,test:()=>l});e();e();e();import m from"chai";import{assert as v,should as C,expect as S}from"chai";e();import t from"sinon";var{mock:T,spy:k,stub:y}=t;t.fn=t.spy;export{m as a,v as b,C as c,S as d,t as e,T as f,k as g,y as h,R as i};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{f as t}from"./chunk-XPSQDVUG.js";t();import{resolve as s}from"path";import{fileURLToPath as e}from"url";var i=s(e(import.meta.url),"../../dist"),a=["**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}"],p=["**/node_modules/**","**/dist/**"],d=["suite","test","describe","it","chai","expect","assert","sinon","spy","mock","stub","beforeAll","afterAll","beforeEach","afterEach"];export{i as a,a as b,p as c,d};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{f as k}from"./chunk-XPSQDVUG.js";k();k();var a={children:[],currentSuite:null};k();var x=new WeakMap,C=new WeakMap;function H(o,e){x.set(o,e)}function q(o){return x.get(o)}function M(o,e){C.set(o,e)}function b(o){return C.get(o)}var A=Q(),y=A("");function c(){return a.currentSuite||y}function G(){return{beforeAll:[],afterAll:[],beforeEach:[],afterEach:[]}}function f(o,e=()=>{},r,l){var T;let u=[],n=[],t;S();let i=W((p,d,s,R)=>{let F={type:"task",name:p,mode:s,computeMode:R??l??"serial",suite:{}};H(F,d),u.push(F)}),g={type:"collector",name:o,mode:r,test:i,children:u,collect:v,clear:w,on:E};function E(p,...d){b(t)[p].push(...d)}function S(){t={type:"suite",computeMode:"serial",name:o,mode:r,children:[]},M(t,G())}function w(){u.length=0,n.length=0,S()}async function v(p){if(n.length=0,e){let s=a.currentSuite;a.currentSuite=g,await e(i),a.currentSuite=s}let d=await Promise.all([...n,...u].map(s=>s.type==="collector"?s.collect(p):s));return t.file=p,t.children=d,d.forEach(s=>{s.type==="task"&&(s.suite=t,p&&(s.file=p))}),t}return(T=a.currentSuite)==null||T.children.push(g),g}function W(o){function e(t,i){o(t,i,"run")}e.concurrent=r,e.skip=l,e.only=u,e.todo=n;function r(t,i){o(t,i,"run","concurrent")}r.skip=(t,i)=>o(t,i,"skip","concurrent"),r.only=(t,i)=>o(t,i,"only","concurrent"),r.todo=n;function l(t,i){o(t,i,"skip")}l.concurrent=r.skip;function u(t,i){o(t,i,"only")}u.concurrent=r.only;function n(t){o(t,()=>{},"todo")}return n.concurrent=n,e}var P=function(){function o(n,t){return c().test(n,t)}function e(n,t){return c().test.concurrent(n,t)}e.skip=(n,t)=>c().test.concurrent.skip(n,t),e.only=(n,t)=>c().test.concurrent.only(n,t),e.todo=n=>c().test.concurrent.todo(n);function r(n,t){return c().test.skip(n,t)}r.concurrent=(n,t)=>c().test.skip.concurrent(n,t);function l(n,t){return c().test.only(n,t)}l.concurrent=(n,t)=>c().test.only.concurrent(n,t);function u(n){return c().test.todo(n)}return u.concurrent=n=>c().test.todo.concurrent(n),o.concurrent=e,o.skip=r,o.only=l,o.todo=u,o}();function Q(){function o(n,t){return f(n,t,"run")}function e(n,t){return f(n,t,"run","concurrent")}e.skip=(n,t)=>f(n,t,"skip","concurrent"),e.only=(n,t)=>f(n,t,"only","concurrent"),e.todo=n=>f(n,void 0,"todo");function r(n,t){return f(n,t,"skip")}r.concurrent=e.skip;function l(n,t){return f(n,t,"only")}l.concurrent=e.only;function u(n){return f(n,void 0,"todo")}return u.concurrent=e.todo,o.concurrent=e,o.skip=r,o.only=l,o.todo=u,o}var I=A,J=P,K=o=>c().on("beforeAll",o),L=o=>c().on("afterAll",o),N=o=>c().on("beforeEach",o),O=o=>c().on("afterEach",o);function U(){a.children.length=0,y.clear(),a.currentSuite=y}export{a,q as b,M as c,b as d,A as e,y as f,G as g,P as h,I as i,J as j,K as k,L as l,N as m,O as n,U as o};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{i as r}from"./chunk-LUQHGOPU.js";import"./chunk-Z2OPSSDM.js";import{d as l}from"./chunk-W4BWZKS2.js";import{f as i}from"./chunk-XPSQDVUG.js";i();function a(){l.forEach(o=>{globalThis[o]=r[o]})}export{a as registerApiGlobally};
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as pretty_format from 'pretty-format';
|
|
2
|
-
import {
|
|
3
|
-
export { C as
|
|
2
|
+
import { T as TestFactory, S as SuiteCollector, a as TestFunction, b as SuiteHooks, U as UserOptions } from './types-15d74511';
|
|
3
|
+
export { C as ComputeMode, F as File, G as GlobalContext, H as HookListener, l as Reporter, R as ResolvedConfig, c as RunMode, k as RunnerContext, j as Suite, S as SuiteCollector, b as SuiteHooks, e as SuiteState, f as Task, h as TaskOrSuite, g as TaskResult, d as TaskState, i as TestCollector, T as TestFactory, a as TestFunction, U as UserOptions } from './types-15d74511';
|
|
4
4
|
export { assert, default as chai, expect, should } from 'chai';
|
|
5
5
|
import sinon from 'sinon';
|
|
6
6
|
export { default as sinon } from 'sinon';
|
|
@@ -8,60 +8,101 @@ import '@antfu/utils';
|
|
|
8
8
|
import 'jest-snapshot';
|
|
9
9
|
import 'jest-snapshot/build/State';
|
|
10
10
|
|
|
11
|
+
declare const suite: {
|
|
12
|
+
(suiteName: string, factory?: TestFactory | undefined): SuiteCollector;
|
|
13
|
+
concurrent: {
|
|
14
|
+
(suiteName: string, factory?: TestFactory | undefined): SuiteCollector;
|
|
15
|
+
skip(suiteName: string, factory?: TestFactory | undefined): SuiteCollector;
|
|
16
|
+
only(suiteName: string, factory?: TestFactory | undefined): SuiteCollector;
|
|
17
|
+
todo(suiteName: string): SuiteCollector;
|
|
18
|
+
};
|
|
19
|
+
skip: {
|
|
20
|
+
(suiteName: string, factory?: TestFactory | undefined): SuiteCollector;
|
|
21
|
+
concurrent: (suiteName: string, factory?: TestFactory | undefined) => SuiteCollector;
|
|
22
|
+
};
|
|
23
|
+
only: {
|
|
24
|
+
(suiteName: string, factory?: TestFactory | undefined): SuiteCollector;
|
|
25
|
+
concurrent: (suiteName: string, factory?: TestFactory | undefined) => SuiteCollector;
|
|
26
|
+
};
|
|
27
|
+
todo: {
|
|
28
|
+
(suiteName: string): SuiteCollector;
|
|
29
|
+
concurrent: (suiteName: string) => SuiteCollector;
|
|
30
|
+
};
|
|
31
|
+
};
|
|
11
32
|
declare const defaultSuite: SuiteCollector;
|
|
33
|
+
declare function createSuiteHooks(): {
|
|
34
|
+
beforeAll: never[];
|
|
35
|
+
afterAll: never[];
|
|
36
|
+
beforeEach: never[];
|
|
37
|
+
afterEach: never[];
|
|
38
|
+
};
|
|
12
39
|
declare const test: {
|
|
13
40
|
(name: string, fn: TestFunction): void;
|
|
14
41
|
concurrent: {
|
|
15
|
-
(name: string, fn: TestFunction
|
|
16
|
-
skip(name: string, fn: TestFunction
|
|
17
|
-
only(name: string, fn: TestFunction
|
|
42
|
+
(name: string, fn: TestFunction): void;
|
|
43
|
+
skip(name: string, fn: TestFunction): void;
|
|
44
|
+
only(name: string, fn: TestFunction): void;
|
|
18
45
|
todo(name: string): void;
|
|
19
46
|
};
|
|
20
47
|
skip: {
|
|
21
48
|
(name: string, fn: TestFunction): void;
|
|
22
|
-
concurrent(name: string, fn: TestFunction
|
|
49
|
+
concurrent(name: string, fn: TestFunction): void;
|
|
23
50
|
};
|
|
24
51
|
only: {
|
|
25
52
|
(name: string, fn: TestFunction): void;
|
|
26
|
-
concurrent(name: string, fn: TestFunction
|
|
53
|
+
concurrent(name: string, fn: TestFunction): void;
|
|
27
54
|
};
|
|
28
55
|
todo: {
|
|
29
56
|
(name: string): void;
|
|
30
57
|
concurrent(name: string): void;
|
|
31
58
|
};
|
|
32
59
|
};
|
|
33
|
-
declare
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
60
|
+
declare const describe: {
|
|
61
|
+
(suiteName: string, factory?: TestFactory | undefined): SuiteCollector;
|
|
62
|
+
concurrent: {
|
|
63
|
+
(suiteName: string, factory?: TestFactory | undefined): SuiteCollector;
|
|
64
|
+
skip(suiteName: string, factory?: TestFactory | undefined): SuiteCollector;
|
|
65
|
+
only(suiteName: string, factory?: TestFactory | undefined): SuiteCollector;
|
|
66
|
+
todo(suiteName: string): SuiteCollector;
|
|
67
|
+
};
|
|
68
|
+
skip: {
|
|
69
|
+
(suiteName: string, factory?: TestFactory | undefined): SuiteCollector;
|
|
70
|
+
concurrent: (suiteName: string, factory?: TestFactory | undefined) => SuiteCollector;
|
|
71
|
+
};
|
|
72
|
+
only: {
|
|
73
|
+
(suiteName: string, factory?: TestFactory | undefined): SuiteCollector;
|
|
74
|
+
concurrent: (suiteName: string, factory?: TestFactory | undefined) => SuiteCollector;
|
|
75
|
+
};
|
|
76
|
+
todo: {
|
|
77
|
+
(suiteName: string): SuiteCollector;
|
|
78
|
+
concurrent: (suiteName: string) => SuiteCollector;
|
|
79
|
+
};
|
|
80
|
+
};
|
|
40
81
|
declare const it: {
|
|
41
82
|
(name: string, fn: TestFunction): void;
|
|
42
83
|
concurrent: {
|
|
43
|
-
(name: string, fn: TestFunction
|
|
44
|
-
skip(name: string, fn: TestFunction
|
|
45
|
-
only(name: string, fn: TestFunction
|
|
84
|
+
(name: string, fn: TestFunction): void;
|
|
85
|
+
skip(name: string, fn: TestFunction): void;
|
|
86
|
+
only(name: string, fn: TestFunction): void;
|
|
46
87
|
todo(name: string): void;
|
|
47
88
|
};
|
|
48
89
|
skip: {
|
|
49
90
|
(name: string, fn: TestFunction): void;
|
|
50
|
-
concurrent(name: string, fn: TestFunction
|
|
91
|
+
concurrent(name: string, fn: TestFunction): void;
|
|
51
92
|
};
|
|
52
93
|
only: {
|
|
53
94
|
(name: string, fn: TestFunction): void;
|
|
54
|
-
concurrent(name: string, fn: TestFunction
|
|
95
|
+
concurrent(name: string, fn: TestFunction): void;
|
|
55
96
|
};
|
|
56
97
|
todo: {
|
|
57
98
|
(name: string): void;
|
|
58
99
|
concurrent(name: string): void;
|
|
59
100
|
};
|
|
60
101
|
};
|
|
61
|
-
declare const beforeAll: (fn:
|
|
62
|
-
declare const afterAll: (fn:
|
|
63
|
-
declare const beforeEach: (fn:
|
|
64
|
-
declare const afterEach: (fn:
|
|
102
|
+
declare const beforeAll: (fn: SuiteHooks['beforeAll'][0]) => void;
|
|
103
|
+
declare const afterAll: (fn: SuiteHooks['afterAll'][0]) => void;
|
|
104
|
+
declare const beforeEach: (fn: SuiteHooks['beforeEach'][0]) => void;
|
|
105
|
+
declare const afterEach: (fn: SuiteHooks['afterEach'][0]) => void;
|
|
65
106
|
declare function clearContext(): void;
|
|
66
107
|
|
|
67
108
|
declare const mock: sinon.SinonMockStatic;
|
|
@@ -105,4 +146,4 @@ declare global {
|
|
|
105
146
|
}
|
|
106
147
|
}
|
|
107
148
|
|
|
108
|
-
export { afterAll, afterEach, beforeAll, beforeEach, clearContext, defaultSuite, describe, it, mock, spy, stub, suite, test };
|
|
149
|
+
export { afterAll, afterEach, beforeAll, beforeEach, clearContext, createSuiteHooks, defaultSuite, describe, it, mock, spy, stub, suite, test };
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as
|
|
1
|
+
import{a as l,b as m,c as n,d as o,e as p,f as q,g as r,h as s}from"./chunk-LUQHGOPU.js";import{e as a,f as b,g as c,h as d,i as e,j as f,k as g,l as h,m as i,n as j,o as k}from"./chunk-Z2OPSSDM.js";import"./chunk-XPSQDVUG.js";export{h as afterAll,j as afterEach,m as assert,g as beforeAll,i as beforeEach,l as chai,k as clearContext,c as createSuiteHooks,b as defaultSuite,e as describe,o as expect,f as it,q as mock,n as should,p as sinon,r as spy,s as stub,a as suite,d as test};
|
package/dist/node/cli.d.ts
CHANGED
|
@@ -1,13 +1,22 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { TransformResult, ViteDevServer } from 'vite';
|
|
2
|
+
import { R as ResolvedConfig } from '../types-15d74511';
|
|
2
3
|
import '@antfu/utils';
|
|
3
4
|
import 'jest-snapshot';
|
|
4
5
|
import 'jest-snapshot/build/State';
|
|
5
6
|
|
|
7
|
+
interface ModuleCache {
|
|
8
|
+
promise?: Promise<any>;
|
|
9
|
+
exports?: any;
|
|
10
|
+
transformResult?: TransformResult;
|
|
11
|
+
}
|
|
12
|
+
|
|
6
13
|
declare global {
|
|
7
14
|
namespace NodeJS {
|
|
8
15
|
interface Process {
|
|
9
16
|
__vitest__: {
|
|
10
|
-
|
|
17
|
+
config: ResolvedConfig;
|
|
18
|
+
server: ViteDevServer;
|
|
19
|
+
moduleCache: Map<string, ModuleCache>;
|
|
11
20
|
};
|
|
12
21
|
}
|
|
13
22
|
}
|
package/dist/node/cli.js
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{a as V}from"../chunk-W4BWZKS2.js";import{a as x,b as O,f as p}from"../chunk-XPSQDVUG.js";p();import{resolve as Y}from"path";import Z from"sade";import v from"picocolors";var M="0.0.40";p();p();import{builtinModules as z,createRequire as L}from"module";import{fileURLToPath as N,pathToFileURL as $}from"url";import{dirname as E,resolve as q}from"path";import B from"vm";var H=process.platform==="win32",D={"/@vite/client":{injectQuery:e=>e,createHotContext(){return{accept:()=>{},prune:()=>{}}},updateStyle(){}}};async function T({moduleCache:e,root:r,files:t,fetch:f,inline:n,external:c}){let g=[];for(let s of t)g.push(await R(`/@fs/${j(q(s))}`,[]));return g;async function y(s,i,o){o=[...o,s];let a=async l=>{if(o.includes(l)){if(!e.get(l))throw new Error(`Circular dependency detected
|
|
2
2
|
Stack:
|
|
3
|
-
${[...
|
|
4
|
-
`)}
|
|
5
|
-
|
|
6
|
-
Vitest is currently in closed beta exclusively for Sponsors`)));console.log(v.magenta(`Become a Sponsor of ${v.underline("https://github.com/sponsors/patak-js")} or ${v.underline("https://github.com/sponsors/antfu")}
|
|
3
|
+
${[...o,l].reverse().map(U=>`- ${U}`).join(`
|
|
4
|
+
`)}`);return e.get(l).exports}return R(l,o)};if(s in D)return D[s];let m=await f(s);if(!m)throw new Error(`failed to load ${s}`);let d=$(i).href,u={};h(s,{transformResult:m,exports:u});let C=N(d),S={require:L(d),__filename:C,__dirname:E(C),__vite_ssr_import__:a,__vite_ssr_dynamic_import__:a,__vite_ssr_exports__:u,__vite_ssr_exportAll__:l=>A(u,l),__vite_ssr_import_meta__:{url:d}};return await B.runInThisContext(`async (${Object.keys(S).join(",")}) => { ${m.code} }`,{filename:i,lineOffset:0})(...Object.values(S)),u}function h(s,i){e.has(s)?Object.assign(e.get(s),i):e.set(s,i)}function _(s){for(let i of n)if(typeof i=="string"){if(s.includes(`/node_modules/${i}/`))return!1}else if(i.test(s))return!1;for(let i of c)if(typeof i=="string"){if(s.includes(`/node_modules/${i}/`))return!0}else if(i.test(s))return!0;return s.includes("/node_modules/")}async function R(s,i){var d,u;let o=J(s);if(z.includes(o))return import(o);let a=Q(o,r);if(_(a))return a.match(/^\w:\//)?import(`/${a}`):import(a);if((d=e.get(a))==null?void 0:d.promise)return(u=e.get(a))==null?void 0:u.promise;let m=y(o,a,i);return h(a,{promise:m}),await m}function A(s,i){for(let o in i)if(o!=="default")try{Object.defineProperty(s,o,{enumerable:!0,configurable:!0,get(){return i[o]}})}catch{}}}function J(e){return e&&e.startsWith("/@id/__x00__")&&(e=`\0${e.slice("/@id/__x00__".length)}`),e&&e.startsWith("/@id/")&&(e=e.slice("/@id/".length)),e.startsWith("__vite-browser-external:")&&(e=e.slice("__vite-browser-external:".length)),e}function Q(e,r){let t=j(e).startsWith("/@fs/")?e.slice(4):e.startsWith(E(r))?e:e.startsWith("/")?j(q(r,e.slice(1))):e;return t.startsWith("//")&&(t=t.slice(1)),H&&t.startsWith("/")?$(t.slice(1)).href:t}function j(e){return e.replace(/\\/g,"/")}p();async function F(e,r){if(r.match(/\.(?:[cm]?[jt]sx?|json)$/))return await e.transformRequest(r,{ssr:!0});{let t=await e.transformRequest(r);return t?await e.ssrTransform(t.code,t.map,r):void 0}}async function W(e,r,t,f){let n={root:e.config.root,files:f,fetch:c=>F(e,c),inline:r.depsInline,external:r.depsExternal,moduleCache:t};try{await T(n)}catch(c){throw process.exitCode=1,c}finally{r.watch||await e.close()}}p();import{resolve as I}from"path";import{findUp as G}from"find-up";import{createServer as K}from"vite";var X=["vitest.config.ts","vitest.config.js","vitest.config.mjs","vite.config.ts","vite.config.js","vite.config.mjs"];async function P(e={}){var g,y,h,_;let{filters:r}=e,t=I(e.root||process.cwd());process.chdir(t);let f=e.config?I(t,e.config):await G(X,{cwd:t}),n=x({},e);n.config=f,n.root=t,n.filters=r?Array.isArray(r)?r:[r]:void 0;let c=await K({root:t,logLevel:"error",clearScreen:!1,configFile:n.config,optimizeDeps:{exclude:["vitest"]}});return await c.pluginContainer.buildStart({}),Object.assign(n,c.config.test),n.depsInline=["vitest/dist","vitest/src","vue","@vue","diff",...((y=(g=c.config.test)==null?void 0:g.deps)==null?void 0:y.inline)||[]],n.depsExternal=((_=(h=c.config.test)==null?void 0:h.deps)==null?void 0:_.external)||[],{server:c,config:n}}Z("vitest [filter]",!0).version(M).describe("A blazing fast unit test framework powered by Vite.").option("-r, --root","root path",process.cwd()).option("-c, --config","path to config file").option("-w, --watch","watch mode",!1).option("-u, --update","update snapshot",!1).option("--global","inject apis globally",!1).option("--dom","mock browser api using jsdom or happy-dom","").action(async(e,r)=>{process.env.VITEST="true",console.log(v.yellow(v.bold(`
|
|
5
|
+
Vitest is currently in closed beta exclusively for Sponsors`))),console.log(v.magenta(`Become a Sponsor of ${v.underline("https://github.com/sponsors/patak-js")} or ${v.underline("https://github.com/sponsors/antfu")}
|
|
7
6
|
to access the source code and issues tracker \u{1F496}
|
|
8
|
-
`));
|
|
7
|
+
`));let{config:t,server:f}=await P(O(x({},r),{filters:e})),n=new Map;process.__vitest__={server:f,config:t,moduleCache:n},await W(f,t,n,[Y(V,"./node/entry.js")])}).parse(process.argv);
|
package/dist/node/entry.js
CHANGED
|
@@ -1,19 +1,18 @@
|
|
|
1
|
-
import{a as
|
|
2
|
-
`)}function
|
|
3
|
-
`).map(o=>{let
|
|
1
|
+
import{a as z,b as G,c as J,d as V,f as Y,g as Q,o as X}from"../chunk-Z2OPSSDM.js";import{b as Z,c as ee}from"../chunk-W4BWZKS2.js";import{c as Oe,e as Ae,f as c}from"../chunk-XPSQDVUG.js";var se=Oe((ft,oe)=>{c();"use strict";oe.exports=t=>{let e=/^\\\\\?\\/.test(t),n=/[^\u0000-\u0080]+/.test(t);return e||n?t:t.replace(/\\/g,"/")}});c();c();c();import ue from"jest-snapshot";c();import De from"chai";import He from"jest-snapshot";c();import Ee from"@jest/test-result";var{makeEmptyAggregatedTestResult:Pe}=Ee,L=t=>{let e=Pe().snapshot;return e.didUpdate=t.updateSnapshot==="all",e},te=t=>{let e={added:0,fileDeleted:!1,matched:0,unchecked:0,uncheckedKeys:[],unmatched:0,updated:0},n=t.getUncheckedCount(),o=t.getUncheckedKeys();n&&t.removeUncheckedKeys();let i=t.save();return e.fileDeleted=i.deleted,e.added=t.added,e.matched=t.matched,e.unmatched=t.unmatched,e.updated=t.updated,e.unchecked=i.deleted?0:n,e.uncheckedKeys=Array.from(o),e},ne=(t,e,n)=>{e.added&&t.filesAdded++,e.fileDeleted&&t.filesRemoved++,e.unmatched&&t.filesUnmatched++,e.updated&&t.filesUpdated++,t.added+=e.added,t.matched+=e.matched,t.unchecked+=e.unchecked,e.uncheckedKeys&&e.uncheckedKeys.length>0&&t.uncheckedKeysByFile.push({filePath:n,keys:e.uncheckedKeys}),t.unmatched+=e.unmatched,t.updated+=e.updated,t.total+=e.added+e.matched+e.unmatched+e.updated};c();var ie=Ae(se());import R,{isAbsolute as Fe}from"path";import{pluralize as y}from"jest-util";import w from"picocolors";var _=(t,e)=>{Fe(e)&&(e=R.relative(t,e));let n=R.dirname(e),o=R.basename(e);return(0,ie.default)(w.dim(n+R.sep)+w.bold(o))},$=" \u203A ",re=" \u21B3 ",B=" \u2022 ",je=t=>w.bold(w.red(t)),ae=t=>w.bold(w.yellow(t)),Le=t=>w.bold(w.green(t)),D=w.dim,le=t=>w.bold(w.green(t)),_e=w.bold,Be=t=>w.bold(w.green(t)),H="re-run mocha with `--update` to update them",ce=(t,e)=>{let n=[];if(n.push(_e("Snapshot Summary")),e.added&&n.push(`${Le(`${$+y("snapshot",e.added)} written `)}from ${y("test suite",e.filesAdded)}.`),e.unmatched&&n.push(`${je(`${$}${y("snapshot",e.unmatched)} failed`)} from ${y("test suite",e.filesUnmatched)}. ${D(`Inspect your code changes or ${H} to update them.`)}`),e.updated&&n.push(`${Be(`${$+y("snapshot",e.updated)} updated `)}from ${y("test suite",e.filesUpdated)}.`),e.filesRemoved&&(e.didUpdate?n.push(`${le(`${$}${y("snapshot file",e.filesRemoved)} removed `)}from ${y("test suite",e.filesRemoved)}.`):n.push(`${ae(`${$}${y("snapshot file",e.filesRemoved)} obsolete `)}from ${y("test suite",e.filesRemoved)}. ${D(`To remove ${e.filesRemoved===1?"it":"them all"}, ${H}.`)}`)),e.filesRemovedList&&e.filesRemovedList.length){let[o,...i]=e.filesRemovedList;n.push(` ${re} ${B}${_(t,o)}`),i.forEach(s=>{n.push(` ${B}${_(t,s)}`)})}return e.unchecked&&(e.didUpdate?n.push(`${le(`${$}${y("snapshot",e.unchecked)} removed `)}from ${y("test suite",e.uncheckedKeysByFile.length)}.`):n.push(`${ae(`${$}${y("snapshot",e.unchecked)} obsolete `)}from ${y("test suite",e.uncheckedKeysByFile.length)}. ${D(`To remove ${e.unchecked===1?"it":"them all"}, ${H}.`)}`),e.uncheckedKeysByFile.forEach(o=>{n.push(` ${re}${_(t,o.filePath)}`),o.keys.forEach(i=>{n.push(` ${B}${i}`)})})),n};var{expect:Ne}=De,{SnapshotState:We}=He,N=class{snapshotState=null;snapshotSummary;snapshotOptions;ctx=null;testFile="";snapshotResolver;rootDir;constructor({rootDir:e,update:n,snapshotResolver:o=null}){this.rootDir=e,this.snapshotResolver=o;let i=process.env,s=!!i.CI,r=n||i.UPDATE_SNAPSHOT;this.snapshotOptions={updateSnapshot:s&&!r?"none":r?"all":"new"},this.snapshotSummary=L(this.snapshotOptions)}onFileChanged(){!this.ctx||(this.snapshotState!==null&&this.saveSnap(),this.testFile=this.ctx.file,this.snapshotState=new We(this.snapshotResolver.resolveSnapshotPath(this.testFile),this.snapshotOptions))}setTask(e){var n;this.setContext({file:((n=e.file)==null?void 0:n.filepath)||e.name,title:e.name,fullTitle:[e.suite.name,e.name].filter(Boolean).join(" > ")})}setContext(e){!e.title||!e.file||(this.ctx=e,this.testFile!==e.file&&this.onFileChanged())}assert(e,n){if(!this.snapshotState||!this.ctx)return;let{actual:o,expected:i,key:s,pass:r}=this.snapshotState.match({testName:this.ctx.fullTitle||this.ctx.title||this.ctx.file,received:e,isInline:!1});r||Ne(o.trim()).equals(i?i.trim():"",n||`Snapshot name: \`${s}\``)}clear(){this.snapshotSummary=L(this.snapshotOptions)}saveSnap(){if(!this.testFile||!this.snapshotState)return;let e=te(this.snapshotState);ne(this.snapshotSummary,e,this.testFile),this.testFile="",this.snapshotState=null}report(){let e=ce(this.rootDir,this.snapshotSummary);if(e.length>1)return e}};var{addSerializer:Ue}=ue,O;function A(){return O}async function de(t){let{root:e}=t;return O=new N({rootDir:e,update:t.update}),O.snapshotResolver=await ue.buildSnapshotResolver({transform:[],rootDir:e}),function(n,o){for(let i of["matchSnapshot","toMatchSnapshot"])o.addMethod(n.Assertion.prototype,i,function(s){let r=o.flag(this,"object");O.assert(r,s)});n.expect.addSnapshotSerializer=Ue}}c();import{slash as Ke}from"@antfu/utils";c();import{basename as Ie}from"path";c();import{toArray as E}from"@antfu/utils";function he(t){let e=[],n=[];for(let o of t.children)e.length===0||o.computeMode===e[0].computeMode?e.push(o):(n.push(e),e=[o]);return e.length>0&&n.push(e),n}function W(t){t.some(e=>e.mode==="only")&&t.forEach(e=>{e.mode==="run"?e.mode="skip":e.mode==="only"&&(e.mode="run")})}function b(t){return E(t).flatMap(e=>e.children.flatMap(n=>n.type==="task"?[n]:b(n)))}function U(t){return E(t).flatMap(e=>e.type==="suite"?[e,...U(e.children)]:[])}function M(t){return E(t).some(e=>e.children.some(n=>n.type==="task"||M(n)))}function fe(t){return E(t).some(e=>e.children.some(n=>{var o;return((o=n.result)==null?void 0:o.state)==="fail"}))}async function P(t){let e={};for(let i of t){let s={name:Ie(i),type:"suite",mode:"run",computeMode:"serial",filepath:i,children:[]};J(s,Q()),X();try{await import(i);for(let r of[Y,...z.children])if(r.type==="task")s.children.push(r);else{let u=await r.collect(s);(u.name||u.children.length)&&s.children.push(u)}}catch(r){s.result={start:performance.now(),state:"fail",error:r},process.exitCode=1}e[i]=s}let o=Object.values(e).reduce((i,s)=>i.concat(s.children),[]);return W(o),o.forEach(i=>{i.type==="suite"&&(i.mode==="skip"?i.children.forEach(s=>s.mode==="run"&&(s.mode="skip")):W(i.children))}),e}async function pe(t){var l;let{reporter:e,snapshotManager:n,filesMap:o}=t;await((l=e.onWatcherStart)==null?void 0:l.call(e,t));let i,s=new Set,r=new Set,{server:u,moduleCache:a}=process.__vitest__;u.watcher.on("change",async f=>{f=Ke(f),me(f,t,s,r),r.forEach(g=>a.delete(g)),r.clear(),s.size!==0&&(clearTimeout(i),i=setTimeout(async()=>{var T,h,S,x;if(s.size===0)return;n.clear();let g=Array.from(s);s.clear(),await((T=e.onWatcherRerun)==null?void 0:T.call(e,g,f,t)),g.forEach(Re=>a.delete(Re));let C=await P(g);Object.assign(o,C);let v=Object.values(o);(h=e.onCollected)==null||h.call(e,v,t),await I(v,t),n.saveSnap(),await((S=e.onFinished)==null?void 0:S.call(e,t,Object.values(C))),await((x=e.onWatcherStart)==null?void 0:x.call(e,t))},100))}),await new Promise(()=>{})}function me(t,e,n=new Set,o=new Set){if(o.has(t)||n.has(t))return n;if(o.add(t),t in e.filesMap)return n.add(t),n;let i=process.__vitest__.server.moduleGraph.getModuleById(t);return i&&i.importers.forEach(s=>{s.id&&me(s.id,e,n,o)}),n}c();import qe from"fast-glob";async function ge(t){var n;let e=await qe(t.includes||Z,{absolute:!0,cwd:t.root,ignore:t.excludes||ee});return((n=t.filters)==null?void 0:n.length)&&(e=e.filter(o=>t.filters.some(i=>o.includes(i)))),e}c();c();import{performance as we}from"perf_hooks";import{relative as rt}from"path";import d from"picocolors";import ke from"listr";c();import{promises as ze,existsSync as Ge}from"fs";import k from"picocolors";import{createPatch as it}from"diff";import{notNullish as Je}from"@antfu/utils";import{SourceMapConsumer as Ve}from"source-map";async function K(t){var r;if(!(t instanceof Error)){console.error(t);return}let{moduleCache:e}=process.__vitest__,n=t,o=!1,s=tt(n.stack||"").find(u=>e.has(u.file));if(s){let u=(r=e.get(s.file))==null?void 0:r.transformResult,a=await Ye(u==null?void 0:u.map,s);if(a&&Ge(s.file)){let l=await ze.readFile(s.file,"utf-8");console.error(`${k.red(`${k.bold(n.name)}: ${n.message}`)}`),console.log(k.gray(`${s.file}:${a.line}:${a.column}`)),console.log(k.yellow(Xe(l,a))),o=!0}}o||console.error(n),n.showDiff&&console.error(k.gray(nt(ye(n.actual),ye(n.expected))))}function Ye(t,{line:e,column:n}){return new Promise(o=>{if(!t)return o(null);Ve.with(t,null,i=>{let s=i.originalPositionFor({line:e,column:n});s.line!=null&&s.column!=null?o(s):o(null)})})}var Se=/\r?\n/;function Qe(t,e){if(typeof e=="number")return e;let n=t.split(Se),{line:o,column:i}=e,s=0;for(let r=0;r<o-1;r++)s+=n[r].length+1;return s+i}function Xe(t,e=0,n,o=2){e=Qe(t,e),n=n||e;let i=t.split(Se),s=0,r=[];for(let u=0;u<i.length;u++)if(s+=i[u].length+1,s>=e){for(let a=u-o;a<=u+o||n>s;a++){if(a<0||a>=i.length)continue;let l=a+1;r.push(`${k.gray(`${l}${" ".repeat(Math.max(3-String(l).length,0))}|`)} ${i[a]}`);let f=i[a].length;if(a===u){let g=e-(s-f)+1,C=Math.max(1,n>s?f-g:n-e);r.push(`${k.gray(" |")} ${" ".repeat(g)}${"^".repeat(C)}`)}else if(a>u){if(n>s){let g=Math.max(Math.min(n-s,f),1);r.push(`${k.gray(" |")} ${"^".repeat(g)}`)}s+=f+1}}break}return r.join(`
|
|
2
|
+
`)}function ye(t){return String(t)}var Ze=/at (.*) \((.+):(\d+):(\d+)\)$/,et=/at ()(.+):(\d+):(\d+)$/;function tt(t){return t.split(`
|
|
3
|
+
`).map(o=>{let i=o.trim(),s=i.match(Ze)||i.match(et);if(!s)return null;let r=s[2];return r.startsWith("file://")&&(r=r.slice(7)),{method:s[1],file:s[2],line:parseInt(s[3]),column:parseInt(s[4])}}).filter(Je)}function nt(t,e){let n=2048;return t.length>n&&(t=`${t.substring(0,n)} ... Lines skipped`),e.length>n&&(e=`${e.substring(0,n)} ... Lines skipped`),ot(t,e)}function ot(t,e){let n=" ";function o(r){return r[0]==="+"?n+k.green(`${r[0]} ${r.slice(1)}`):r[0]==="-"?n+k.red(`${r[0]} ${r.slice(1)}`):r.match(/@@/)?"--":r.match(/\\ No newline/)?null:n+r}let s=it("string",t,e).split(`
|
|
4
4
|
`).splice(5);return`
|
|
5
|
-
${n}${
|
|
6
|
-
${n}${
|
|
5
|
+
${n}${k.red("- actual")}
|
|
6
|
+
${n}${k.green("+ expected")}
|
|
7
7
|
|
|
8
|
-
${s.map(o).filter(
|
|
9
|
-
`)}`}function
|
|
10
|
-
`))}onCollected(e){this.start=
|
|
11
|
-
`));let
|
|
12
|
-
Failed to
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
${
|
|
17
|
-
${
|
|
18
|
-
|
|
19
|
-
`))}onSnapshotUpdate(){}};async function R(t,e,n){await Promise.all(t.hooks[e].map(o=>o(...n)))}async function re(t,e){var o,r,s;let{reporter:n}=e;if((o=B())==null||o.setTask(t),await((r=n.onTaskBegin)==null?void 0:r.call(n,t,e)),t.mode==="run"){try{await R(t.suite,"beforeEach",[t,t.suite]),await t.fn(),t.state="pass"}catch(i){t.state="fail",t.error=i,process.exitCode=1}try{await R(t.suite,"afterEach",[t,t.suite])}catch(i){t.state="fail",t.error=i,process.exitCode=1}}await((s=n.onTaskEnd)==null?void 0:s.call(n,t,e))}async function ae(t){let e={};for(let r of t){let s={filepath:r,suites:[],collected:!1};I();try{await import(r);let i=[W,...O.suites];for(let a of i)O.currentSuite=a,s.suites.push(await a.collect(s));s.collected=!0}catch(i){s.error=i,s.collected=!1,process.exitCode=1}e[r]=s}let o=Object.values(e).reduce((r,s)=>r.concat(s.suites),[]);return le(o),o.forEach(r=>{r.mode==="skip"?r.tasks.forEach(s=>s.mode==="run"&&(s.mode="skip")):le(r.tasks),r.tasks.forEach(s=>s.mode==="skip"&&(s.state="skip"))}),e}function le(t){t.some(e=>e.mode==="only")&&t.forEach(e=>{e.mode==="run"?e.mode="skip":e.mode==="only"&&(e.mode="run")})}async function ce(t,e){var o,r;let{reporter:n}=e;if(await((o=n.onSuiteBegin)==null?void 0:o.call(n,t,e)),t.mode==="skip")t.status="skip";else if(t.mode==="todo")t.status="todo";else try{await R(t,"beforeAll",[t]);for(let s of Je(t.tasks))if(s[0].concurrent)await Promise.all(s.map(i=>re(i,e)));else for(let i of s)await re(i,e);await R(t,"afterAll",[t])}catch(s){t.error=s,t.status="fail",process.exitCode=1}await((r=n.onSuiteEnd)==null?void 0:r.call(n,t,e))}function Je(t){let e=[],n=[];for(let o of t)e.length===0||!!o.concurrent==!!e[0].concurrent?e.push(o):(n.push(e),e=[o]);return e.length>0&&n.push(e),n}async function Ve(t,e){var r,s;let{reporter:n}=e;if(t.suites.filter(i=>i.mode==="run").length!==0){if(await((r=n.onFileBegin)==null?void 0:r.call(n,t,e)),e.config.parallel)await Promise.all(t.suites.map(i=>ce(i,e)));else for(let i of t.suites)await ce(i,e);await((s=n.onFileEnd)==null?void 0:s.call(n,t,e))}}async function de(t,e){var o;let{reporter:n}=e;await((o=n.onCollected)==null?void 0:o.call(n,Object.values(t),e));for(let r of Object.values(t))await Ve(r,e)}async function he(t){var i,a,d;t.reporter=t.reporter||new L;let{reporter:e}=t;t.watch&&(process.__vite_node__.watch=!0),await ne(t);let n=await ze(t.includes||U,{absolute:!0,cwd:t.root,ignore:t.excludes||H});if(((i=t.filters)==null?void 0:i.length)&&(n=n.filter(f=>t.filters.some(u=>f.includes(u)))),!n.length){console.error("No test files found"),process.exitCode=1;return}t.global&&(await import("../global-CKRMAXWF.js")).registerApiGlobally(),t.dom==="happy-dom"?(await import("../happy-dom-RNJZR3YC.js")).setupHappyDOM(globalThis):t.dom&&(await import("../jsdom-6QAZGE6T.js")).setupJSDOM(globalThis),await((a=e.onStart)==null?void 0:a.call(e,t));let o=await ae(n),r=B(),s={filesMap:o,get files(){return Object.values(this.filesMap)},get suites(){return Object.values(this.filesMap).reduce((f,u)=>f.concat(u.suites),[])},get tasks(){return this.suites.reduce((f,u)=>f.concat(u.tasks),[])},config:t,reporter:e,snapshotManager:r};await de(o,s),r.saveSnap(),await((d=e.onFinished)==null?void 0:d.call(e,s)),t.watch&&await Ye(s)}async function Ye(t){var f;let{reporter:e,snapshotManager:n,filesMap:o}=t;await((f=e.onWatcherStart)==null?void 0:f.call(e,t));let r,s=new Set,i=new Set,{server:a,moduleCache:d}=process.__vite_node__;a.watcher.on("change",async u=>{u=Ge(u),ue(u,t,s,i),i.forEach(g=>d.delete(g)),i.clear(),s.size!==0&&(clearTimeout(r),r=setTimeout(async()=>{var v,l,N;if(s.size===0)return;n.clear();let g=Array.from(s);s.clear(),await((v=e.onWatcherRerun)==null?void 0:v.call(e,g,u,t)),g.forEach(fe=>d.delete(fe));let w=await ae(g);Object.assign(o,w),await de(w,t),n.saveSnap(),await((l=e.onFinished)==null?void 0:l.call(e,t,Object.values(w))),await((N=e.onWatcherStart)==null?void 0:N.call(e,t))},100))}),await new Promise(()=>{})}function ue(t,e,n=new Set,o=new Set){if(o.has(t)||n.has(t))return n;if(o.add(t),t in e.filesMap)return n.add(t),n;let r=process.__vite_node__.server.moduleGraph.getModuleById(t);return r&&r.importers.forEach(s=>{s.id&&ue(s.id,e,n,o)}),n}if(!process.__vite_node__||!process.__vitest__)throw new Error("Vitest can only run in vite-node environment, please use the CLI to start the process");var Qe=process.__vite_node__.server.config.test||{},Xe=process.__vitest__.options||{},Ze=x(x({},Xe),Qe);await he(Ze);var et=setTimeout(()=>{process.exit()},500);et.unref();
|
|
8
|
+
${s.map(o).filter(st).join(`
|
|
9
|
+
`)}`}function st(t){return typeof t!="undefined"&&t!==null}var q=class{start=0;end=0;listr=null;listrPromise=null;taskMap=new Map;cwd=process.cwd();relative(e){return rt(this.cwd,e)}onStart(e){this.cwd=e.root,console.log(d.green(`Running tests under ${d.gray(this.cwd)}
|
|
10
|
+
`))}onCollected(e){this.start=we.now(),this.taskMap=new Map,e.reduce((a,l)=>a.concat(b(l)),[]).forEach(a=>{let l={};l.promise=new Promise((f,g)=>{l.resolve=f,l.reject=g}),this.taskMap.set(a,l)});let o={exitOnError:!1},i=a=>({title:a.name,skip:()=>a.mode==="skip"||a.mode==="todo",task:async()=>{var l;return await((l=this.taskMap.get(a))==null?void 0:l.promise)}});function s(a){return a.children.map(l=>l.type==="task"?i(l):u(l))}function r(a){var l;if((l=a.result)==null?void 0:l.error)throw a.result.error;if(!M(a))throw new Error("No tasks found");return new ke(s(a),o)}function u(a){return{title:a.name,skip:()=>a.mode!=="run",task:()=>r(a)}}this.listr=new ke(e.map(a=>({title:this.relative(a.filepath),task:()=>{var l,f;if((l=a.result)==null?void 0:l.error)throw(f=a.result)==null?void 0:f.error;return r(a)}})),o),this.listrPromise=this.listr.run().catch(()=>{})}onTaskEnd(e){var n,o,i,s;((n=e.result)==null?void 0:n.state)==="fail"?(i=this.taskMap.get(e))==null||i.reject((o=e.result)==null?void 0:o.error):(s=this.taskMap.get(e))==null||s.resolve()}async onFinished(e,n=e.files){var C,v,T;await this.listrPromise,this.end=we.now(),console.log();let o=e.snapshotManager.report();o&&console.log(o.join(`
|
|
11
|
+
`));let i=U(n),s=b(n),r=i.filter(h=>{var S;return(S=h.result)==null?void 0:S.error}),u=s.filter(h=>{var S,x;return((S=h.result)==null?void 0:S.state)==="pass"||((x=h.result)==null?void 0:x.state)==="fail"}),a=s.filter(h=>{var S;return((S=h.result)==null?void 0:S.state)==="pass"}),l=s.filter(h=>{var S;return((S=h.result)==null?void 0:S.state)==="fail"}),f=s.filter(h=>h.mode==="skip"),g=s.filter(h=>h.mode==="todo");if(r.length){console.error(d.bold(d.red(`
|
|
12
|
+
Failed to run ${r.length} suites:`)));for(let h of r)console.error(d.red(`
|
|
13
|
+
- ${(C=h.file)==null?void 0:C.filepath} > ${h.name}`)),await K((v=h.result)==null?void 0:v.error),console.log()}if(l.length){console.error(d.bold(d.red(`
|
|
14
|
+
Failed Tests (${l.length})`)));for(let h of l)console.error(`${d.red(`
|
|
15
|
+
${d.inverse(" FAIL ")}`)} ${[h.suite.name,h.name].filter(Boolean).join(" > ")}`),await K((T=h.result)==null?void 0:T.error),console.log()}console.log(d.bold(d.green(`Passed ${a.length} / ${u.length}`))),l.length&&console.log(d.bold(d.red(`Failed ${l.length} / ${u.length}`))),f.length&&console.log(d.yellow(`Skipped ${f.length}`)),g.length&&console.log(d.dim(`Todo ${g.length}`)),console.log(`Time ${(this.end-this.start).toFixed(2)}ms`)}async onWatcherStart(e){await this.listrPromise;let n=e.tasks.filter(o=>{var i;return((i=o.result)==null?void 0:i.state)==="fail"});n.length?console.log(`
|
|
16
|
+
${d.bold(d.inverse(d.red(" FAIL ")))}${d.red(` ${n.length} tests failed. Watching for file changes...`)}`):console.log(`
|
|
17
|
+
${d.bold(d.inverse(d.green(" PASS ")))}${d.green(" Watching for file changes...")}`)}async onWatcherRerun(e,n){await this.listrPromise,console.clear(),console.log(d.blue("Re-running tests...")+d.dim(` [ ${this.relative(n)} ]
|
|
18
|
+
`))}};c();c();import F from"chai";import at from"sinon-chai";import lt from"chai-subset";c();function Ce(){return(t,e)=>{let n=t.Assertion.prototype;e.addMethod(n,"toEqual",function(o){return this.eql(o)}),e.addMethod(n,"toStrictEqual",function(o){return this.equal(o)}),e.addMethod(n,"toBe",function(o){return this.equal(o)}),e.addMethod(n,"toMatchObject",function(o){return this.containSubset(o)}),e.addMethod(n,"toMatch",function(o){return typeof o=="string"?this.include(o):this.match(o)}),e.addMethod(n,"toContain",function(o){return this.contain(o)}),e.addMethod(n,"toBeTruthy",function(){let o=e.flag(this,"object");this.assert(Boolean(o),"expected #{this} to be truthy","expected #{this} to not be truthy",o)}),e.addMethod(n,"toBeFalsy",function(){let o=e.flag(this,"object");this.assert(!o,"expected #{this} to be falsy","expected #{this} to not be falsy",o)}),e.addMethod(n,"toBeNaN",function(){return this.be.NaN}),e.addMethod(n,"toBeUndefined",function(){return this.be.undefined}),e.addMethod(n,"toBeNull",function(){return this.be.null}),e.addMethod(n,"toBeDefined",function(){return this.not.be.undefined}),e.addMethod(n,"toBeInstanceOf",function(o){return this.instanceOf(o)}),e.addMethod(n,"toHaveBeenCalledTimes",function(o){return this.callCount(o)}),e.addMethod(n,"toHaveBeenCalledOnce",function(){return this.callCount(1)}),e.addMethod(n,"toHaveBeenCalled",function(){return this.called}),e.addMethod(n,"toHaveBeenCalled",function(){return this.called}),e.addMethod(n,"toHaveBeenCalledWith",function(...o){return this.calledWith(...o)})}}async function $e(t){F.use(at),F.use(Ce()),F.use(lt),F.use(await de(t))}async function be(t){await $e(t),t.global&&(await import("../global-OOVANJ2U.js")).registerApiGlobally(),t.dom==="happy-dom"?(await import("../happy-dom-RNJZR3YC.js")).setupHappyDOM(globalThis):t.dom&&(await import("../jsdom-6QAZGE6T.js")).setupJSDOM(globalThis)}async function ve(t){return await be(t),{filesMap:{},get files(){return Object.values(this.filesMap)},get tasks(){return b(Object.values(this.filesMap))},config:t,reporter:t.reporter||new q,snapshotManager:A()}}async function j(t,e,n){await Promise.all(V(t)[e].map(o=>o(...n)))}async function ct(t,e){var o,i,s;if(t.mode!=="run")return;let{reporter:n}=e;(o=A())==null||o.setTask(t),await((i=n.onTaskBegin)==null?void 0:i.call(n,t,e)),t.result={start:performance.now(),state:"run"};try{await j(t.suite,"beforeEach",[t,t.suite]),await G(t)(),t.result.state="pass"}catch(r){t.result.state="fail",t.result.error=r,process.exitCode=1}try{await j(t.suite,"afterEach",[t,t.suite])}catch(r){t.result.state="fail",t.result.error=r,process.exitCode=1}t.result.end=performance.now(),await((s=n.onTaskEnd)==null?void 0:s.call(n,t,e))}async function Te(t,e){var o,i;let{reporter:n}=e;if(await((o=n.onSuiteBegin)==null?void 0:o.call(n,t,e)),t.result={start:performance.now(),state:"run"},t.mode==="skip")t.result.state="skip";else if(t.mode==="todo")t.result.state="todo";else try{await j(t,"beforeAll",[t]);for(let s of he(t)){let r=s[0].computeMode;if(r==="serial")for(let u of s)await xe(u,e);else r==="concurrent"&&await Promise.all(s.map(u=>xe(u,e)))}await j(t,"afterAll",[t])}catch(s){t.result.state="fail",t.result.error=s,process.exitCode=1}t.result.end=performance.now(),t.mode==="run"&&(M(t)?fe(t)&&(t.result.state="fail"):(t.result.state="fail",t.result.error=new Error(`No tests found in suite ${t.name}`),process.exitCode=1)),await((i=n.onSuiteEnd)==null?void 0:i.call(n,t,e))}async function xe(t,e){return t.type==="task"?ct(t,e):Te(t,e)}async function I(t,e){for(let n of t)await Te(n,e)}async function Me(t){var a,l,f;let e=await ge(t);if(!e.length){console.error("No test files found"),process.exitCode=1;return}let n=await ve(t),{filesMap:o,snapshotManager:i,reporter:s}=n;await((a=s.onStart)==null?void 0:a.call(s,t));let r=await P(e);Object.assign(o,r);let u=Object.values(o);await((l=s.onCollected)==null?void 0:l.call(s,u,n)),await I(u,n),i.saveSnap(),await((f=s.onFinished)==null?void 0:f.call(s,n)),t.watch&&await pe(n)}if(!process.__vitest__)throw new Error("Vitest can only run in vite-node environment, please use the CLI to start the process");await Me(process.__vitest__.config);var ut=setTimeout(()=>{process.exit()},500);ut.unref();
|
|
@@ -32,7 +32,7 @@ declare class SnapshotManager {
|
|
|
32
32
|
snapshotState: SnapshotStateType | null;
|
|
33
33
|
snapshotSummary: SnapshotSummary;
|
|
34
34
|
snapshotOptions: SnapshotStateOptions;
|
|
35
|
-
|
|
35
|
+
ctx: Context | null;
|
|
36
36
|
testFile: string;
|
|
37
37
|
snapshotResolver: SnapshotResolver | null;
|
|
38
38
|
rootDir: string;
|
|
@@ -81,12 +81,6 @@ interface UserOptions {
|
|
|
81
81
|
* @default false
|
|
82
82
|
*/
|
|
83
83
|
dom?: boolean | 'jsdom' | 'happy-dom';
|
|
84
|
-
/**
|
|
85
|
-
* Run tests files in parallel
|
|
86
|
-
*
|
|
87
|
-
* @default false
|
|
88
|
-
*/
|
|
89
|
-
parallel?: boolean;
|
|
90
84
|
/**
|
|
91
85
|
* Update snapshot files
|
|
92
86
|
*
|
|
@@ -107,40 +101,49 @@ interface UserOptions {
|
|
|
107
101
|
* Custom reporter for output
|
|
108
102
|
*/
|
|
109
103
|
reporter?: Reporter;
|
|
110
|
-
}
|
|
111
|
-
interface ResolvedConfig extends Required<UserOptions> {
|
|
112
104
|
filters?: string[];
|
|
105
|
+
config?: string | undefined;
|
|
106
|
+
}
|
|
107
|
+
interface ResolvedConfig extends Omit<Required<UserOptions>, 'config' | 'filters'> {
|
|
113
108
|
config?: string;
|
|
109
|
+
filters?: string[];
|
|
110
|
+
depsInline: (string | RegExp)[];
|
|
111
|
+
depsExternal: (string | RegExp)[];
|
|
114
112
|
}
|
|
115
113
|
declare type RunMode = 'run' | 'skip' | 'only' | 'todo';
|
|
116
114
|
declare type TaskState = RunMode | 'pass' | 'fail';
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
}
|
|
115
|
+
declare type SuiteState = RunMode | 'pass' | 'fail';
|
|
116
|
+
declare type ComputeMode = 'serial' | 'concurrent';
|
|
120
117
|
interface Task {
|
|
118
|
+
type: 'task';
|
|
121
119
|
name: string;
|
|
122
120
|
mode: RunMode;
|
|
123
|
-
|
|
121
|
+
computeMode: ComputeMode;
|
|
124
122
|
suite: Suite;
|
|
125
|
-
fn: () => Awaitable<void>;
|
|
126
123
|
file?: File;
|
|
127
|
-
|
|
124
|
+
result?: TaskResult;
|
|
125
|
+
}
|
|
126
|
+
interface TaskResult {
|
|
127
|
+
state: TaskState;
|
|
128
|
+
start: number;
|
|
129
|
+
end?: number;
|
|
128
130
|
error?: unknown;
|
|
129
131
|
}
|
|
132
|
+
declare type TaskOrSuite = Task | Suite;
|
|
130
133
|
declare type TestFunction = () => Awaitable<void>;
|
|
131
134
|
interface ConcurrentCollector {
|
|
132
|
-
(name: string, fn: TestFunction
|
|
133
|
-
only: (name: string, fn: TestFunction
|
|
134
|
-
skip: (name: string, fn: TestFunction
|
|
135
|
+
(name: string, fn: TestFunction): void;
|
|
136
|
+
only: (name: string, fn: TestFunction) => void;
|
|
137
|
+
skip: (name: string, fn: TestFunction) => void;
|
|
135
138
|
todo: (name: string) => void;
|
|
136
139
|
}
|
|
137
140
|
interface OnlyCollector {
|
|
138
141
|
(name: string, fn: TestFunction): void;
|
|
139
|
-
concurrent: (name: string, fn: TestFunction
|
|
142
|
+
concurrent: (name: string, fn: TestFunction) => void;
|
|
140
143
|
}
|
|
141
144
|
interface SkipCollector {
|
|
142
145
|
(name: string, fn: TestFunction): void;
|
|
143
|
-
concurrent: (name: string, fn: TestFunction
|
|
146
|
+
concurrent: (name: string, fn: TestFunction) => void;
|
|
144
147
|
}
|
|
145
148
|
interface TodoCollector {
|
|
146
149
|
(name: string): void;
|
|
@@ -154,60 +157,57 @@ interface TestCollector {
|
|
|
154
157
|
todo: TodoCollector;
|
|
155
158
|
}
|
|
156
159
|
declare type HookListener<T extends any[]> = (...args: T) => Awaitable<void>;
|
|
160
|
+
interface SuiteHooks {
|
|
161
|
+
beforeAll: HookListener<[Suite]>[];
|
|
162
|
+
afterAll: HookListener<[Suite]>[];
|
|
163
|
+
beforeEach: HookListener<[Task, Suite]>[];
|
|
164
|
+
afterEach: HookListener<[Task, Suite]>[];
|
|
165
|
+
}
|
|
157
166
|
interface Suite {
|
|
167
|
+
type: 'suite';
|
|
158
168
|
name: string;
|
|
159
169
|
mode: RunMode;
|
|
160
|
-
|
|
170
|
+
computeMode: ComputeMode;
|
|
171
|
+
children: TaskOrSuite[];
|
|
161
172
|
file?: File;
|
|
162
|
-
|
|
163
|
-
status?: TaskState;
|
|
164
|
-
hooks: {
|
|
165
|
-
beforeAll: HookListener<[Suite]>[];
|
|
166
|
-
afterAll: HookListener<[Suite]>[];
|
|
167
|
-
beforeEach: HookListener<[Task, Suite]>[];
|
|
168
|
-
afterEach: HookListener<[Task, Suite]>[];
|
|
169
|
-
};
|
|
173
|
+
result?: TaskResult;
|
|
170
174
|
}
|
|
171
175
|
interface SuiteCollector {
|
|
172
176
|
readonly name: string;
|
|
173
177
|
readonly mode: RunMode;
|
|
178
|
+
type: 'collector';
|
|
174
179
|
test: TestCollector;
|
|
180
|
+
children: (Suite | Task | SuiteCollector)[];
|
|
175
181
|
collect: (file?: File) => Promise<Suite>;
|
|
176
182
|
clear: () => void;
|
|
177
|
-
on: <T extends keyof
|
|
183
|
+
on: <T extends keyof SuiteHooks>(name: T, ...fn: SuiteHooks[T]) => void;
|
|
178
184
|
}
|
|
179
185
|
declare type TestFactory = (test: (name: string, fn: TestFunction) => void) => Awaitable<void>;
|
|
180
|
-
interface File {
|
|
186
|
+
interface File extends Suite {
|
|
181
187
|
filepath: string;
|
|
182
|
-
suites: Suite[];
|
|
183
|
-
collected: boolean;
|
|
184
|
-
error?: unknown;
|
|
185
188
|
}
|
|
186
189
|
interface RunnerContext {
|
|
187
190
|
filesMap: Record<string, File>;
|
|
188
191
|
files: File[];
|
|
189
|
-
suites: Suite[];
|
|
190
192
|
tasks: Task[];
|
|
191
193
|
config: ResolvedConfig;
|
|
192
194
|
reporter: Reporter;
|
|
193
195
|
snapshotManager: SnapshotManager;
|
|
194
196
|
}
|
|
195
197
|
interface GlobalContext {
|
|
196
|
-
|
|
198
|
+
children: (SuiteCollector | Task)[];
|
|
197
199
|
currentSuite: SuiteCollector | null;
|
|
198
200
|
}
|
|
199
201
|
interface Reporter {
|
|
200
202
|
onStart?: (config: ResolvedConfig) => Awaitable<void>;
|
|
201
203
|
onCollected?: (files: File[], ctx: RunnerContext) => Awaitable<void>;
|
|
202
204
|
onFinished?: (ctx: RunnerContext, files?: File[]) => Awaitable<void>;
|
|
203
|
-
onSuiteBegin?: (suite: Suite, ctx: RunnerContext) => Awaitable<void>;
|
|
204
|
-
onSuiteEnd?: (suite: Suite, ctx: RunnerContext) => Awaitable<void>;
|
|
205
|
-
onFileBegin?: (file: File, ctx: RunnerContext) => Awaitable<void>;
|
|
206
|
-
onFileEnd?: (file: File, ctx: RunnerContext) => Awaitable<void>;
|
|
207
205
|
onTaskBegin?: (task: Task, ctx: RunnerContext) => Awaitable<void>;
|
|
208
206
|
onTaskEnd?: (task: Task, ctx: RunnerContext) => Awaitable<void>;
|
|
207
|
+
onSuiteBegin?: (suite: Suite, ctx: RunnerContext) => Awaitable<void>;
|
|
208
|
+
onSuiteEnd?: (suite: Suite, ctx: RunnerContext) => Awaitable<void>;
|
|
209
209
|
onWatcherStart?: (ctx: RunnerContext) => Awaitable<void>;
|
|
210
210
|
onWatcherRerun?: (files: string[], trigger: string, ctx: RunnerContext) => Awaitable<void>;
|
|
211
211
|
}
|
|
212
212
|
|
|
213
|
-
export {
|
|
213
|
+
export { ComputeMode as C, File as F, GlobalContext as G, HookListener as H, ResolvedConfig as R, SuiteCollector as S, TestFactory as T, UserOptions as U, TestFunction as a, SuiteHooks as b, RunMode as c, TaskState as d, SuiteState as e, Task as f, TaskResult as g, TaskOrSuite as h, TestCollector as i, Suite as j, RunnerContext as k, Reporter as l };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vitest",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.40",
|
|
4
4
|
"description": "A blazing fast unit test framework powered by Vite",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"vite",
|
|
@@ -48,11 +48,9 @@
|
|
|
48
48
|
"lint": "eslint \"{src,test}/**/*.ts\"",
|
|
49
49
|
"prepublishOnly": "nr build",
|
|
50
50
|
"release": "bumpp --commit --push --tag && esmo scripts/publish.ts",
|
|
51
|
-
"test": "
|
|
52
|
-
"test
|
|
53
|
-
"
|
|
54
|
-
"test:react": "node bin/vitest.mjs --dev -r test/react",
|
|
55
|
-
"coverage": "node bin/vitest.mjs --dev -r test/core --coverage"
|
|
51
|
+
"test:all": "pnpm -r --stream --filter !vitest run test --",
|
|
52
|
+
"test": "node bin/vitest.mjs -r test/core",
|
|
53
|
+
"coverage": "node bin/vitest.mjs -r test/core --coverage"
|
|
56
54
|
},
|
|
57
55
|
"dependencies": {
|
|
58
56
|
"@antfu/utils": "^0.3.0",
|
package/dist/chunk-4OVO6RD6.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{a as k,b as F,f as d}from"./chunk-XPSQDVUG.js";d();var O=["**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}"],R=["**/node_modules/**","**/dist/**"],G=["suite","test","describe","it","chai","expect","assert","sinon","spy","mock","stub","beforeAll","afterAll","beforeEach","afterEach"],C=5e3;d();d();var g={suites:[],currentSuite:null};var y=h("");function s(){return g.currentSuite||y}function x(t,r=()=>{},u){let c=[],i=[],e={name:t,mode:u,hooks:{beforeAll:[],afterAll:[],beforeEach:[],afterEach:[]}},n=j((f,p,a,T)=>{c.push({name:f,mode:a,concurrent:T,suite:{},state:a!=="run"&&a!=="only"?a:void 0,fn:p})}),o={name:t,mode:u,test:n,collect:A,clear:E,on:l};function l(f,...p){e.hooks[f].push(...p)}function E(){c.length=0,i.length=0}async function A(f){i.length=0,r&&await r(n);let p=[...i,...c],a=F(k({},e),{tasks:p,file:f});return p.forEach(T=>{T.suite=a,f&&(T.file=f)}),a}return g.currentSuite=o,g.suites.push(o),o}function b(t){return{timeout:t??C}}function j(t){function r(n,o){t(n,o,"run")}r.concurrent=u,r.skip=c,r.only=i,r.todo=e;function u(n,o,l){t(n,o,"run",b(l))}u.skip=(n,o,l)=>t(n,o,"skip",b(l)),u.only=(n,o,l)=>t(n,o,"only",b(l)),u.todo=e;function c(n,o){t(n,o,"skip")}c.concurrent=u.skip;function i(n,o){t(n,o,"only")}i.concurrent=u.only;function e(n){t(n,()=>{},"todo")}return e.concurrent=e,r}var M=function(){function t(e,n){return s().test(e,n)}function r(e,n,o){return s().test.concurrent(e,n,o)}r.skip=(e,n,o)=>s().test.concurrent.skip(e,n,o),r.only=(e,n,o)=>s().test.concurrent.only(e,n,o),r.todo=e=>s().test.concurrent.todo(e);function u(e,n){return s().test.skip(e,n)}u.concurrent=(e,n,o)=>s().test.skip.concurrent(e,n,o);function c(e,n){return s().test.only(e,n)}c.concurrent=(e,n,o)=>s().test.only.concurrent(e,n,o);function i(e){return s().test.todo(e)}return i.concurrent=e=>s().test.todo.concurrent(e),t.concurrent=r,t.skip=u,t.only=c,t.todo=i,t}();function h(t,r){return x(t,r,"run")}h.skip=(t,r)=>x(t,r,"skip");h.only=(t,r)=>x(t,r,"only");h.todo=t=>x(t,void 0,"todo");var H=h,I=M,P=t=>s().on("beforeAll",t),Q=t=>s().on("afterAll",t),_=t=>s().on("beforeEach",t),z=t=>s().on("afterEach",t);function D(){g.suites.length=0,y.clear(),g.currentSuite=y}export{g as a,O as b,R as c,G as d,y as e,M as f,h as g,H as h,I as i,P as j,Q as k,_ as l,z as m,D as n};
|
package/dist/chunk-CUG6SVUZ.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{e as r,f as a,g as s,h as l,i as c,j as d,k as u,l as p,m as f,n as m}from"./chunk-4OVO6RD6.js";import{d as i,f as e}from"./chunk-XPSQDVUG.js";var T={};i(T,{afterAll:()=>u,afterEach:()=>f,assert:()=>g,beforeAll:()=>d,beforeEach:()=>p,chai:()=>x,clearContext:()=>m,defaultSuite:()=>r,describe:()=>l,expect:()=>C,it:()=>c,mock:()=>b,should:()=>v,sinon:()=>t,spy:()=>k,stub:()=>S,suite:()=>s,test:()=>a});e();e();e();import x from"chai";import{assert as g,should as v,expect as C}from"chai";e();import t from"sinon";var{mock:b,spy:k,stub:S}=t;t.fn=t.spy;export{x as a,g as b,v as c,C as d,t as e,b as f,k as g,S as h,T as i};
|
package/dist/global-CKRMAXWF.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{i as l}from"./chunk-CUG6SVUZ.js";import{d as r}from"./chunk-4OVO6RD6.js";import{f as i}from"./chunk-XPSQDVUG.js";i();function a(){r.forEach(o=>{globalThis[o]=l[o]})}export{a as registerApiGlobally};
|