vitest 0.0.52 → 0.0.53
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 +16 -1
- package/dist/chunk-2PVIVCXM.js +1 -0
- package/dist/chunk-A73PYES7.js +1 -0
- package/dist/{chunk-PUYNF2CK.js → chunk-NQCSRT6G.js} +1 -1
- package/dist/{global-EIUXDMNN.js → global-P6HP35SI.js} +1 -1
- package/dist/index.d.ts +22 -22
- package/dist/index.js +1 -1
- package/dist/node/cli.d.ts +1 -1
- package/dist/node/cli.js +2 -2
- package/dist/node/worker.d.ts +1 -1
- package/dist/node/worker.js +1 -1
- package/dist/runtime/entry.d.ts +1 -1
- package/dist/runtime/entry.js +1 -1
- package/dist/{types-29c69ee0.d.ts → types-53cd5eeb.d.ts} +9 -8
- package/package.json +1 -1
- package/dist/chunk-76F2Y2GL.js +0 -1
- package/dist/chunk-EPZJPNZW.js +0 -1
package/README.gh.md
CHANGED
|
@@ -34,6 +34,7 @@ A blazing fast unit test framework powered by Vite.
|
|
|
34
34
|
- Async suite / test, top level await
|
|
35
35
|
- ESM friendly
|
|
36
36
|
- Out-of-box TypeScript / JSX support
|
|
37
|
+
- Test and Hooks timeouts
|
|
37
38
|
- Suite and Test filtering (skip, only, todo)
|
|
38
39
|
- Concurrent Tests
|
|
39
40
|
|
|
@@ -135,7 +136,7 @@ export default defineConfig({
|
|
|
135
136
|
plugins: [
|
|
136
137
|
AutoImport({
|
|
137
138
|
imports: ['vitest'],
|
|
138
|
-
dts: true //
|
|
139
|
+
dts: true // generate TypeScript declaration
|
|
139
140
|
})
|
|
140
141
|
]
|
|
141
142
|
})
|
|
@@ -219,6 +220,20 @@ basic.test.ts
|
|
|
219
220
|
basic-foo.test.ts
|
|
220
221
|
```
|
|
221
222
|
|
|
223
|
+
### Specifying a Timeout
|
|
224
|
+
|
|
225
|
+
You can optionally pass a timeout in milliseconds as third argument to tests. The default is 5 seconds.
|
|
226
|
+
|
|
227
|
+
```ts
|
|
228
|
+
test('name', async() => { ... }, 1000)
|
|
229
|
+
```
|
|
230
|
+
|
|
231
|
+
Hooks also can receive a timeout, with the same 5 seconds default.
|
|
232
|
+
|
|
233
|
+
```ts
|
|
234
|
+
beforeAll( async() => { ... }, 1000)
|
|
235
|
+
```
|
|
236
|
+
|
|
222
237
|
### Skipping suites and tests
|
|
223
238
|
|
|
224
239
|
Use `.skip` to avoid running certain suites or tests
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{init_esm_shims}from"./chunk-64PJVUUV.js";init_esm_shims();import{resolve}from"path";import{fileURLToPath}from"url";var distDir=resolve(fileURLToPath(import.meta.url),"../../dist"),defaultTestTimeout=5e3,defaultHookTimeout=5e3,defaultIncludes=["**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}"],defaultExcludes=["**/node_modules/**","**/dist/**"],globalApis=["suite","test","describe","it","chai","expect","assert","sinon","spy","mock","stub","beforeAll","afterAll","beforeEach","afterEach"];export{distDir,defaultTestTimeout,defaultHookTimeout,defaultIncludes,defaultExcludes,globalApis};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{defaultHookTimeout,defaultTestTimeout}from"./chunk-2PVIVCXM.js";import{init_esm_shims}from"./chunk-64PJVUUV.js";init_esm_shims();import{nanoid}from"nanoid";init_esm_shims();var context={tasks:[],currentSuite:null};init_esm_shims();var fnMap=new WeakMap,hooksMap=new WeakMap;function setFn(key,fn){fnMap.set(key,fn)}function getFn(key){return fnMap.get(key)}function setHooks(key,hooks){hooksMap.set(key,hooks)}function getHooks(key){return hooksMap.get(key)}var suite=createSuite(),defaultSuite=suite("");function getCurrentSuite(){return context.currentSuite||defaultSuite}function createSuiteHooks(){return{beforeAll:[],afterAll:[],beforeEach:[],afterEach:[]}}function createSuiteCollector(name,factory=()=>{},mode,suiteComputeMode){var _a;let tasks=[],factoryQueue=[],suite2;initSuite();let test2=createTestCollector((name2,fn,mode2,computeMode)=>{let test3={id:nanoid(),type:"test",name:name2,mode:mode2,computeMode:computeMode??suiteComputeMode??"serial",suite:{}};setFn(test3,fn),tasks.push(test3)}),collector={type:"collector",name,mode,test:test2,tasks,collect,clear,on:addHook};function addHook(name2,...fn){getHooks(suite2)[name2].push(...fn)}function initSuite(){suite2={id:nanoid(),type:"suite",computeMode:"serial",name,mode,tasks:[],suite:{}},setHooks(suite2,createSuiteHooks())}function clear(){tasks.length=0,factoryQueue.length=0,initSuite()}async function collect(file){if(factoryQueue.length=0,factory){let prev=context.currentSuite;context.currentSuite=collector,await factory(test2),context.currentSuite=prev}let allChildren=await Promise.all([...factoryQueue,...tasks].map(i=>i.type==="collector"?i.collect(file):i));return suite2.file=file,suite2.tasks=allChildren,allChildren.forEach(task=>{task.suite=suite2,file&&(task.file=file)}),suite2}return(_a=context.currentSuite)==null||_a.tasks.push(collector),collector}function createTestCollector(collectTest){function test2(name,fn,timeout){collectTest(name,withTimeout(fn,timeout),"run")}test2.concurrent=concurrent,test2.skip=skip,test2.only=only,test2.todo=todo;function concurrent(name,fn,timeout){collectTest(name,withTimeout(fn,timeout),"run","concurrent")}concurrent.skip=(name,fn,timeout)=>collectTest(name,withTimeout(fn,timeout),"skip","concurrent"),concurrent.only=(name,fn,timeout)=>collectTest(name,withTimeout(fn,timeout),"only","concurrent"),concurrent.todo=todo;function skip(name,fn,timeout){collectTest(name,withTimeout(fn,timeout),"skip")}skip.concurrent=concurrent.skip;function only(name,fn,timeout){collectTest(name,withTimeout(fn,timeout),"only")}only.concurrent=concurrent.only;function todo(name){collectTest(name,()=>{},"todo")}return todo.concurrent=todo,test2}var test=function(){function test2(name,fn,timeout){return getCurrentSuite().test(name,fn,timeout)}function concurrent(name,fn,timeout){return getCurrentSuite().test.concurrent(name,fn,timeout)}concurrent.skip=(name,fn,timeout)=>getCurrentSuite().test.concurrent.skip(name,fn,timeout),concurrent.only=(name,fn,timeout)=>getCurrentSuite().test.concurrent.only(name,fn,timeout),concurrent.todo=name=>getCurrentSuite().test.concurrent.todo(name);function skip(name,fn,timeout){return getCurrentSuite().test.skip(name,fn,timeout)}skip.concurrent=(name,fn,timeout)=>getCurrentSuite().test.skip.concurrent(name,fn,timeout);function only(name,fn,timeout){return getCurrentSuite().test.only(name,fn,timeout)}only.concurrent=(name,fn,timeout)=>getCurrentSuite().test.only.concurrent(name,fn,timeout);function todo(name){return getCurrentSuite().test.todo(name)}return todo.concurrent=name=>getCurrentSuite().test.todo.concurrent(name),test2.concurrent=concurrent,test2.skip=skip,test2.only=only,test2.todo=todo,test2}();function createSuite(){function suite2(suiteName,factory){return createSuiteCollector(suiteName,factory,"run")}function concurrent(suiteName,factory){return createSuiteCollector(suiteName,factory,"run","concurrent")}concurrent.skip=(suiteName,factory)=>createSuiteCollector(suiteName,factory,"skip","concurrent"),concurrent.only=(suiteName,factory)=>createSuiteCollector(suiteName,factory,"only","concurrent"),concurrent.todo=suiteName=>createSuiteCollector(suiteName,void 0,"todo");function skip(suiteName,factory){return createSuiteCollector(suiteName,factory,"skip")}skip.concurrent=concurrent.skip;function only(suiteName,factory){return createSuiteCollector(suiteName,factory,"only")}only.concurrent=concurrent.only;function todo(suiteName){return createSuiteCollector(suiteName,void 0,"todo")}return todo.concurrent=concurrent.todo,suite2.concurrent=concurrent,suite2.skip=skip,suite2.only=only,suite2.todo=todo,suite2}var describe=suite,it=test,beforeAll=(fn,timeout=defaultHookTimeout)=>getCurrentSuite().on("beforeAll",withTimeout(fn,timeout)),afterAll=(fn,timeout=defaultHookTimeout)=>getCurrentSuite().on("afterAll",withTimeout(fn,timeout)),beforeEach=(fn,timeout=defaultHookTimeout)=>getCurrentSuite().on("beforeEach",withTimeout(fn,timeout)),afterEach=(fn,timeout=defaultHookTimeout)=>getCurrentSuite().on("afterEach",withTimeout(fn,timeout));function clearContext(){context.tasks.length=0,defaultSuite.clear(),context.currentSuite=defaultSuite}function withTimeout(fn,timeout=defaultTestTimeout){return timeout<=0||timeout===1/0?fn:(...args)=>Promise.race([fn(...args),new Promise((resolve,reject)=>{let timer=setTimeout(()=>{clearTimeout(timer),reject(new Error(`Test timed out in ${timeout}ms.`))},timeout);timer.unref()})])}export{context,getFn,setHooks,getHooks,suite,defaultSuite,createSuiteHooks,test,describe,it,beforeAll,afterAll,beforeEach,afterEach,clearContext};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{afterAll,afterEach,beforeAll,beforeEach,clearContext,createSuiteHooks,defaultSuite,describe,it,suite,test}from"./chunk-
|
|
1
|
+
import{afterAll,afterEach,beforeAll,beforeEach,clearContext,createSuiteHooks,defaultSuite,describe,it,suite,test}from"./chunk-A73PYES7.js";import{__export,init_esm_shims}from"./chunk-64PJVUUV.js";var src_exports={};__export(src_exports,{afterAll:()=>afterAll,afterEach:()=>afterEach,assert:()=>assert,beforeAll:()=>beforeAll,beforeEach:()=>beforeEach,chai:()=>chai,clearContext:()=>clearContext,createSuiteHooks:()=>createSuiteHooks,defaultSuite:()=>defaultSuite,describe:()=>describe,expect:()=>expect,it:()=>it,mock:()=>mock,should:()=>should,sinon:()=>sinon,spy:()=>spy,stub:()=>stub,suite:()=>suite,test:()=>test});init_esm_shims();init_esm_shims();init_esm_shims();import chai from"chai";import{assert,should,expect}from"chai";init_esm_shims();import sinon from"sinon";var{mock,spy,stub}=sinon;sinon.fn=sinon.spy;export{chai,assert,should,expect,sinon,mock,spy,stub,src_exports};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{src_exports}from"./chunk-
|
|
1
|
+
import{src_exports}from"./chunk-NQCSRT6G.js";import"./chunk-A73PYES7.js";import{globalApis}from"./chunk-2PVIVCXM.js";import{init_esm_shims}from"./chunk-64PJVUUV.js";init_esm_shims();function registerApiGlobally(){globalApis.forEach(api=>{globalThis[api]=src_exports[api]})}export{registerApiGlobally};
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { T as TestFactory, S as SuiteCollector, a as TestFunction, b as SuiteHooks, U as UserOptions } from './types-
|
|
2
|
-
export { C as ComputeMode, F as File, G as GlobalContext, H as HookListener, M as ModuleCache, l as Reporter, R as ResolvedConfig, n as RpcCall, m as RpcMap, p as RpcPayload, o as RpcSend, c as RunMode, h as Suite, S as SuiteCollector, b as SuiteHooks, j as Task, e as TaskBase, f as TaskResult, g as TaskResultPack, d as TaskState, i as Test, k as TestCollector, T as TestFactory, a as TestFunction, U as UserOptions, V as VitestContext, W as WorkerContext } from './types-
|
|
1
|
+
import { T as TestFactory, S as SuiteCollector, a as TestFunction, b as SuiteHooks, U as UserOptions } from './types-53cd5eeb';
|
|
2
|
+
export { C as ComputeMode, F as File, G as GlobalContext, H as HookListener, M as ModuleCache, l as Reporter, R as ResolvedConfig, n as RpcCall, m as RpcMap, p as RpcPayload, o as RpcSend, c as RunMode, h as Suite, S as SuiteCollector, b as SuiteHooks, j as Task, e as TaskBase, f as TaskResult, g as TaskResultPack, d as TaskState, i as Test, k as TestCollector, T as TestFactory, a as TestFunction, U as UserOptions, V as VitestContext, W as WorkerContext } from './types-53cd5eeb';
|
|
3
3
|
export { assert, default as chai, expect, should } from 'chai';
|
|
4
4
|
import sinon from 'sinon';
|
|
5
5
|
export { default as sinon } from 'sinon';
|
|
@@ -37,20 +37,20 @@ declare function createSuiteHooks(): {
|
|
|
37
37
|
afterEach: never[];
|
|
38
38
|
};
|
|
39
39
|
declare const test: {
|
|
40
|
-
(name: string, fn: TestFunction): void;
|
|
40
|
+
(name: string, fn: TestFunction, timeout?: number | undefined): void;
|
|
41
41
|
concurrent: {
|
|
42
|
-
(name: string, fn: TestFunction): void;
|
|
43
|
-
skip(name: string, fn: TestFunction): void;
|
|
44
|
-
only(name: string, fn: TestFunction): void;
|
|
42
|
+
(name: string, fn: TestFunction, timeout?: number | undefined): void;
|
|
43
|
+
skip(name: string, fn: TestFunction, timeout?: number | undefined): void;
|
|
44
|
+
only(name: string, fn: TestFunction, timeout?: number | undefined): void;
|
|
45
45
|
todo(name: string): void;
|
|
46
46
|
};
|
|
47
47
|
skip: {
|
|
48
|
-
(name: string, fn: TestFunction): void;
|
|
49
|
-
concurrent(name: string, fn: TestFunction): void;
|
|
48
|
+
(name: string, fn: TestFunction, timeout?: number | undefined): void;
|
|
49
|
+
concurrent(name: string, fn: TestFunction, timeout?: number | undefined): void;
|
|
50
50
|
};
|
|
51
51
|
only: {
|
|
52
|
-
(name: string, fn: TestFunction): void;
|
|
53
|
-
concurrent(name: string, fn: TestFunction): void;
|
|
52
|
+
(name: string, fn: TestFunction, timeout?: number | undefined): void;
|
|
53
|
+
concurrent(name: string, fn: TestFunction, timeout?: number | undefined): void;
|
|
54
54
|
};
|
|
55
55
|
todo: {
|
|
56
56
|
(name: string): void;
|
|
@@ -79,30 +79,30 @@ declare const describe: {
|
|
|
79
79
|
};
|
|
80
80
|
};
|
|
81
81
|
declare const it: {
|
|
82
|
-
(name: string, fn: TestFunction): void;
|
|
82
|
+
(name: string, fn: TestFunction, timeout?: number | undefined): void;
|
|
83
83
|
concurrent: {
|
|
84
|
-
(name: string, fn: TestFunction): void;
|
|
85
|
-
skip(name: string, fn: TestFunction): void;
|
|
86
|
-
only(name: string, fn: TestFunction): void;
|
|
84
|
+
(name: string, fn: TestFunction, timeout?: number | undefined): void;
|
|
85
|
+
skip(name: string, fn: TestFunction, timeout?: number | undefined): void;
|
|
86
|
+
only(name: string, fn: TestFunction, timeout?: number | undefined): void;
|
|
87
87
|
todo(name: string): void;
|
|
88
88
|
};
|
|
89
89
|
skip: {
|
|
90
|
-
(name: string, fn: TestFunction): void;
|
|
91
|
-
concurrent(name: string, fn: TestFunction): void;
|
|
90
|
+
(name: string, fn: TestFunction, timeout?: number | undefined): void;
|
|
91
|
+
concurrent(name: string, fn: TestFunction, timeout?: number | undefined): void;
|
|
92
92
|
};
|
|
93
93
|
only: {
|
|
94
|
-
(name: string, fn: TestFunction): void;
|
|
95
|
-
concurrent(name: string, fn: TestFunction): void;
|
|
94
|
+
(name: string, fn: TestFunction, timeout?: number | undefined): void;
|
|
95
|
+
concurrent(name: string, fn: TestFunction, timeout?: number | undefined): void;
|
|
96
96
|
};
|
|
97
97
|
todo: {
|
|
98
98
|
(name: string): void;
|
|
99
99
|
concurrent(name: string): void;
|
|
100
100
|
};
|
|
101
101
|
};
|
|
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;
|
|
102
|
+
declare const beforeAll: (fn: SuiteHooks['beforeAll'][0], timeout?: number) => void;
|
|
103
|
+
declare const afterAll: (fn: SuiteHooks['afterAll'][0], timeout?: number) => void;
|
|
104
|
+
declare const beforeEach: (fn: SuiteHooks['beforeEach'][0], timeout?: number) => void;
|
|
105
|
+
declare const afterEach: (fn: SuiteHooks['afterEach'][0], timeout?: number) => void;
|
|
106
106
|
declare function clearContext(): void;
|
|
107
107
|
|
|
108
108
|
declare const mock: sinon.SinonMockStatic;
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{assert,chai,expect,mock,should,sinon,spy,stub}from"./chunk-
|
|
1
|
+
import{assert,chai,expect,mock,should,sinon,spy,stub}from"./chunk-NQCSRT6G.js";import{afterAll,afterEach,beforeAll,beforeEach,clearContext,createSuiteHooks,defaultSuite,describe,it,suite,test}from"./chunk-A73PYES7.js";import"./chunk-2PVIVCXM.js";import"./chunk-64PJVUUV.js";export{afterAll,afterEach,assert,beforeAll,beforeEach,chai,clearContext,createSuiteHooks,defaultSuite,describe,expect,it,mock,should,sinon,spy,stub,suite,test};
|
package/dist/node/cli.d.ts
CHANGED
package/dist/node/cli.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{addSnapshotResult,emptySummary,getSuites,getTests,hasFailed}from"../chunk-HVAZQ6BP.js";import{defaultExcludes,defaultIncludes,distDir}from"../chunk-
|
|
1
|
+
import{addSnapshotResult,emptySummary,getSuites,getTests,hasFailed}from"../chunk-HVAZQ6BP.js";import{defaultExcludes,defaultIncludes,distDir}from"../chunk-2PVIVCXM.js";import{__commonJS,__spreadProps,__spreadValues,__toModule,init_esm_shims}from"../chunk-64PJVUUV.js";var require_slash=__commonJS({"node_modules/.pnpm/slash@3.0.0/node_modules/slash/index.js"(exports,module){init_esm_shims();"use strict";module.exports=path2=>{let isExtendedLengthPath=/^\\\\\?\\/.test(path2),hasNonAscii=/[^\u0000-\u0080]+/.test(path2);return isExtendedLengthPath||hasNonAscii?path2:path2.replace(/\\/g,"/")}}});var require_indent_string=__commonJS({"node_modules/.pnpm/indent-string@4.0.0/node_modules/indent-string/index.js"(exports,module){init_esm_shims();"use strict";module.exports=(string,count=1,options)=>{if(options=__spreadValues({indent:" ",includeEmptyLines:!1},options),typeof string!="string")throw new TypeError(`Expected \`input\` to be a \`string\`, got \`${typeof string}\``);if(typeof count!="number")throw new TypeError(`Expected \`count\` to be a \`number\`, got \`${typeof count}\``);if(typeof options.indent!="string")throw new TypeError(`Expected \`options.indent\` to be a \`string\`, got \`${typeof options.indent}\``);if(count===0)return string;let regex=options.includeEmptyLines?/^/gm:/^(?!\s*$)/gm;return string.replace(regex,options.indent.repeat(count))}}});init_esm_shims();import sade from"sade";import c5 from"picocolors";import{install as installSourceMapSupport}from"source-map-support";var version="0.0.53";init_esm_shims();import{performance}from"perf_hooks";import{relative}from"path";import c4 from"picocolors";init_esm_shims();var import_slash=__toModule(require_slash());import path,{isAbsolute}from"path";import{pluralize}from"jest-util";import c from"picocolors";var formatTestPath=(rootDir,testPath)=>{isAbsolute(testPath)&&(testPath=path.relative(rootDir,testPath));let dirname=path.dirname(testPath),basename=path.basename(testPath);return(0,import_slash.default)(c.dim(dirname+path.sep)+c.bold(basename))},ARROW=" \u203A ",DOWN_ARROW=" \u21B3 ",DOT=" \u2022 ",FAIL_COLOR=v=>c.bold(c.red(v)),OBSOLETE_COLOR=v=>c.bold(c.yellow(v)),SNAPSHOT_ADDED=v=>c.bold(c.green(v)),SNAPSHOT_NOTE=c.dim,SNAPSHOT_REMOVED=v=>c.bold(c.green(v)),SNAPSHOT_SUMMARY=c.bold,SNAPSHOT_UPDATED=v=>c.bold(c.green(v)),updateCommand="re-run mocha with `--update` to update them",getSnapshotSummaryOutput=(rootDir,snapshots)=>{let summary=[];if(snapshots.added&&summary.push(`${SNAPSHOT_ADDED(`${ARROW+pluralize("snapshot",snapshots.added)} written `)}from ${pluralize("test suite",snapshots.filesAdded)}.`),snapshots.unmatched&&summary.push(`${FAIL_COLOR(`${ARROW}${pluralize("snapshot",snapshots.unmatched)} failed`)} from ${pluralize("test suite",snapshots.filesUnmatched)}. ${SNAPSHOT_NOTE(`Inspect your code changes or ${updateCommand} to update them.`)}`),snapshots.updated&&summary.push(`${SNAPSHOT_UPDATED(`${ARROW+pluralize("snapshot",snapshots.updated)} updated `)}from ${pluralize("test suite",snapshots.filesUpdated)}.`),snapshots.filesRemoved&&(snapshots.didUpdate?summary.push(`${SNAPSHOT_REMOVED(`${ARROW}${pluralize("snapshot file",snapshots.filesRemoved)} removed `)}from ${pluralize("test suite",snapshots.filesRemoved)}.`):summary.push(`${OBSOLETE_COLOR(`${ARROW}${pluralize("snapshot file",snapshots.filesRemoved)} obsolete `)}from ${pluralize("test suite",snapshots.filesRemoved)}. ${SNAPSHOT_NOTE(`To remove ${snapshots.filesRemoved===1?"it":"them all"}, ${updateCommand}.`)}`)),snapshots.filesRemovedList&&snapshots.filesRemovedList.length){let[head,...tail]=snapshots.filesRemovedList;summary.push(` ${DOWN_ARROW} ${DOT}${formatTestPath(rootDir,head)}`),tail.forEach(key=>{summary.push(` ${DOT}${formatTestPath(rootDir,key)}`)})}return snapshots.unchecked&&(snapshots.didUpdate?summary.push(`${SNAPSHOT_REMOVED(`${ARROW}${pluralize("snapshot",snapshots.unchecked)} removed `)}from ${pluralize("test suite",snapshots.uncheckedKeysByFile.length)}.`):summary.push(`${OBSOLETE_COLOR(`${ARROW}${pluralize("snapshot",snapshots.unchecked)} obsolete `)}from ${pluralize("test suite",snapshots.uncheckedKeysByFile.length)}. ${SNAPSHOT_NOTE(`To remove ${snapshots.unchecked===1?"it":"them all"}, ${updateCommand}.`)}`),snapshots.uncheckedKeysByFile.forEach(uncheckedFile=>{summary.push(` ${DOWN_ARROW}${formatTestPath(rootDir,uncheckedFile.filePath)}`),uncheckedFile.keys.forEach(key=>{summary.push(` ${DOT}${key}`)})})),summary.length&&summary.unshift(SNAPSHOT_SUMMARY("Snapshot Summary")),summary};init_esm_shims();import{promises as fs,existsSync}from"fs";import c2 from"picocolors";import{createPatch}from"diff";import{notNullish}from"@antfu/utils";import{SourceMapConsumer}from"source-map";async function printError(error){let{server}=process.__vitest__,e=error,codeFramePrinted=!1,nearest=parseStack(e.stack||e.stackStr||"").find(stack=>server.moduleGraph.getModuleById(stack.file));if(nearest){let mod=server.moduleGraph.getModuleById(nearest.file),transformResult=mod==null?void 0:mod.ssrTransformResult,pos=await getOriginalPos(transformResult==null?void 0:transformResult.map,nearest);if(pos&&existsSync(nearest.file)){let sourceCode=await fs.readFile(nearest.file,"utf-8");console.error(`${c2.red(`${c2.bold(e.name||e.nameStr||"Unknown Error")}: ${e.message}`)}`),console.log(c2.gray(`${nearest.file}:${pos.line}:${pos.column}`)),console.log(c2.yellow(generateCodeFrame(sourceCode,pos))),codeFramePrinted=!0}}codeFramePrinted||console.error(e),e.showDiff&&console.error(c2.gray(generateDiff(stringify(e.actual),stringify(e.expected))))}function getOriginalPos(map,{line,column}){return new Promise(resolve2=>{if(!map)return resolve2(null);SourceMapConsumer.with(map,null,consumer=>{let pos=consumer.originalPositionFor({line,column});pos.line!=null&&pos.column!=null?resolve2(pos):resolve2(null)})})}var splitRE=/\r?\n/;function posToNumber(source,pos){if(typeof pos=="number")return pos;let lines=source.split(splitRE),{line,column}=pos,start2=0;for(let i=0;i<line-1;i++)start2+=lines[i].length+1;return start2+column}function generateCodeFrame(source,start2=0,end,range=2){start2=posToNumber(source,start2),end=end||start2;let lines=source.split(splitRE),count=0,res=[];for(let i=0;i<lines.length;i++)if(count+=lines[i].length+1,count>=start2){for(let j=i-range;j<=i+range||end>count;j++){if(j<0||j>=lines.length)continue;let line=j+1;res.push(`${c2.gray(`${line}${" ".repeat(Math.max(3-String(line).length,0))}|`)} ${lines[j]}`);let lineLength=lines[j].length;if(lineLength>200)return"";if(j===i){let pad=start2-(count-lineLength)+1,length=Math.max(1,end>count?lineLength-pad:end-start2);res.push(`${c2.gray(" |")} ${" ".repeat(pad)}${"^".repeat(length)}`)}else if(j>i){if(end>count){let length=Math.max(Math.min(end-count,lineLength),1);res.push(`${c2.gray(" |")} ${"^".repeat(length)}`)}count+=lineLength+1}}break}return res.join(`
|
|
2
2
|
`)}function stringify(obj){return String(obj)}var stackFnCallRE=/at (.*) \((.+):(\d+):(\d+)\)$/,stackBarePathRE=/at ()(.+):(\d+):(\d+)$/;function parseStack(stack){return stack.split(`
|
|
3
3
|
`).map(raw=>{let line=raw.trim(),match=line.match(stackFnCallRE)||line.match(stackBarePathRE);if(!match)return null;let file=match[2];return file.startsWith("file://")&&(file=file.slice(7)),{method:match[1],file:match[2],line:parseInt(match[3]),column:parseInt(match[4])}}).filter(notNullish)}function generateDiff(actual,expected){let diffSize=2048;return actual.length>diffSize&&(actual=`${actual.substring(0,diffSize)} ... Lines skipped`),expected.length>diffSize&&(expected=`${expected.substring(0,diffSize)} ... Lines skipped`),unifiedDiff(actual,expected)}function unifiedDiff(actual,expected){let indent=" ";function cleanUp(line){return line[0]==="+"?indent+c2.green(`${line[0]} ${line.slice(1)}`):line[0]==="-"?indent+c2.red(`${line[0]} ${line.slice(1)}`):line.match(/@@/)?"--":line.match(/\\ No newline/)?null:indent+line}let lines=createPatch("string",actual,expected).split(`
|
|
4
4
|
`).splice(5);return`
|
|
@@ -9,7 +9,7 @@ ${lines.map(cleanUp).filter(notBlank).join(`
|
|
|
9
9
|
`)}`}function notBlank(line){return typeof line!="undefined"&&line!==null}init_esm_shims();var import_indent_string=__toModule(require_indent_string());import{createLogUpdate}from"log-update";import c3 from"picocolors";import figures from"figures";import cliTruncate from"cli-truncate";import stripAnsi from"strip-ansi";import elegantSpinner from"elegant-spinner";import logSymbols from"log-symbols";var DURATION_LONG=300,MAX_HEIGHT=20,pointer=c3.yellow(figures.pointer),skipped=c3.yellow(figures.arrowDown),spinnerMap=new WeakMap,outputMap=new WeakMap,getSymbol=task=>{if(task.mode==="skip"||task.mode==="todo")return skipped;if(!task.result)return c3.gray("\xB7");if(task.result.state==="run"){if(task.type==="suite")return pointer;let spinner=spinnerMap.get(task);return spinner||(spinner=elegantSpinner(),spinnerMap.set(task,spinner)),c3.yellow(spinner())}return task.result.state==="pass"?logSymbols.success:task.result.state==="fail"?task.type==="suite"?pointer:logSymbols.error:" "};function renderTree(tasks,level=0){var _a,_b,_c,_d;let output=[];for(let task of tasks){let delta=1,suffix=task.mode==="skip"||task.mode==="todo"?` ${c3.dim("[skipped]")}`:"",prefix=` ${getSymbol(task)} `;if(task.type==="suite"&&(suffix+=c3.dim(` (${getTests(task).length})`)),(_a=task.result)==null?void 0:_a.end){let duration=task.result.end-task.result.start;duration>DURATION_LONG&&(suffix+=c3.yellow(` ${Math.round(duration)}${c3.dim("ms")}`))}if(task.name?output.push((0,import_indent_string.default)(prefix+task.name+suffix,level,{indent:" "})):delta=0,((_b=task.result)==null?void 0:_b.state)!=="pass"&&outputMap.get(task)!=null){let data=outputMap.get(task);if(typeof data=="string"&&(data=stripAnsi(data.trim().split(`
|
|
10
10
|
`).filter(Boolean).pop()),data===""&&(data=void 0)),data!=null){let out=(0,import_indent_string.default)(`${figures.arrowRight} ${data}`,level,{indent:" "});output.push(` ${c3.gray(cliTruncate(out,process.stdout.columns-3))}`)}}(((_c=task.result)==null?void 0:_c.state)==="fail"||((_d=task.result)==null?void 0:_d.state)==="run")&&task.type==="suite"&&task.tasks.length>0&&(output=output.concat(renderTree(task.tasks,level+delta)))}return output.slice(0,MAX_HEIGHT).join(`
|
|
11
11
|
`)}var createRenderer=_tasks=>{let tasks=_tasks,timer,log=createLogUpdate(process.stdout);function update(){log(renderTree(tasks))}return{start(){return timer?this:(timer=setInterval(update,200),this)},update(_tasks2){return tasks=_tasks2,update(),this},async stop(){return timer&&(clearInterval(timer),timer=void 0),log.clear(),console.log(renderTree(tasks)),this}}};var DefaultReporter=class{constructor(ctx){this.ctx=ctx;console.log(c4.green(`Running tests under ${c4.gray(this.ctx.config.root)}
|
|
12
|
-
`))}start=0;end=0;renderer;filters;relative(path2){return relative(this.ctx.config.root,path2)}onStart(onlyFiles=this.filters){let files=this.ctx.state.getFiles(onlyFiles);this.renderer?this.renderer.update(files):this.renderer=createRenderer(files).start()
|
|
12
|
+
`)),this.start=performance.now()}start=0;end=0;renderer;filters;relative(path2){return relative(this.ctx.config.root,path2)}onStart(onlyFiles=this.filters){let files=this.ctx.state.getFiles(onlyFiles);this.renderer?this.renderer.update(files):this.renderer=createRenderer(files).start()}async onFinished(files=this.ctx.state.getFiles()){var _a,_b,_c;this.end=performance.now(),await this.stopListRender(),console.log();let suites=getSuites(files),tests=getTests(files),failedSuites=suites.filter(i=>{var _a2;return(_a2=i.result)==null?void 0:_a2.error}),runnable=tests.filter(i=>{var _a2,_b2;return((_a2=i.result)==null?void 0:_a2.state)==="pass"||((_b2=i.result)==null?void 0:_b2.state)==="fail"}),passed=tests.filter(i=>{var _a2;return((_a2=i.result)==null?void 0:_a2.state)==="pass"}),failed=tests.filter(i=>{var _a2;return((_a2=i.result)==null?void 0:_a2.state)==="fail"}),skipped2=tests.filter(i=>i.mode==="skip"),todo=tests.filter(i=>i.mode==="todo");if(failedSuites.length){console.error(c4.bold(c4.red(`
|
|
13
13
|
Failed to run ${failedSuites.length} suites:`)));for(let suite of failedSuites)console.error(c4.red(`
|
|
14
14
|
- ${(_a=suite.file)==null?void 0:_a.filepath} > ${suite.name}`)),await printError((_b=suite.result)==null?void 0:_b.error),console.log()}if(failed.length){console.error(c4.bold(c4.red(`
|
|
15
15
|
Failed Tests (${failed.length})`)));for(let test of failed)console.error(`${c4.red(`
|
package/dist/node/worker.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import '../index';
|
|
2
|
-
import { R as ResolvedConfig, n as RpcCall, o as RpcSend, W as WorkerContext } from '../types-
|
|
2
|
+
import { R as ResolvedConfig, n as RpcCall, o as RpcSend, W as WorkerContext } from '../types-53cd5eeb';
|
|
3
3
|
import 'chai';
|
|
4
4
|
import 'sinon';
|
|
5
5
|
import 'worker_threads';
|
package/dist/node/worker.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{distDir}from"../chunk-
|
|
1
|
+
import{distDir}from"../chunk-2PVIVCXM.js";import{init_esm_shims}from"../chunk-64PJVUUV.js";init_esm_shims();import{resolve as resolve2}from"path";import{nanoid}from"nanoid";init_esm_shims();import{builtinModules,createRequire}from"module";import{fileURLToPath,pathToFileURL}from"url";import{dirname,resolve}from"path";import vm from"vm";import{isValidNodeImport}from"mlly";var isWindows=process.platform==="win32",stubRequests={"/@vite/client":{injectQuery:id=>id,createHotContext(){return{accept:()=>{},prune:()=>{}}},updateStyle(){}}};async function executeInViteNode({moduleCache:moduleCache2,root,files,fetch,inline,external}){let externaled=new Set(builtinModules),result=[];for(let file of files)result.push(await cachedRequest(`/@fs/${slash(resolve(file))}`,[]));return result;async function directRequest(id,fsPath,callstack){callstack=[...callstack,id];let request=async dep=>{var _a;if(callstack.includes(dep)){let cacheKey=toFilePath(dep,root);if(!((_a=moduleCache2.get(cacheKey))==null?void 0:_a.exports))throw new Error(`Circular dependency detected
|
|
2
2
|
Stack:
|
|
3
3
|
${[...callstack,dep].reverse().map(p=>`- ${p}`).join(`
|
|
4
4
|
`)}`);return moduleCache2.get(cacheKey).exports}return cachedRequest(dep,callstack)};if(id in stubRequests)return stubRequests[id];let result2=await fetch(id);if(!result2)throw new Error(`failed to load ${id}`);let url=pathToFileURL(fsPath).href,exports={};setCache(fsPath,{transformResult:result2,exports});let __filename2=fileURLToPath(url),context={require:createRequire(url),__filename:__filename2,__dirname:dirname(__filename2),__vite_ssr_import__:request,__vite_ssr_dynamic_import__:request,__vite_ssr_exports__:exports,__vite_ssr_exportAll__:obj=>exportAll(exports,obj),__vite_ssr_import_meta__:{url}};return await vm.runInThisContext(`async (${Object.keys(context).join(",")}) => { ${result2.code} }`,{filename:fsPath,lineOffset:0})(...Object.values(context)),exports}function setCache(id,mod){moduleCache2.has(id)?Object.assign(moduleCache2.get(id),mod):moduleCache2.set(id,mod)}async function shouldExternalize(id){for(let ex of inline)if(typeof ex=="string"){if(id.includes(`/node_modules/${ex}/`))return!1}else if(ex.test(id))return!1;for(let ex of external)if(typeof ex=="string"){if(id.includes(`/node_modules/${ex}/`))return!0}else if(ex.test(id))return!0;return id.includes("/node_modules/")&&!await isValidNodeImport(id)}async function cachedRequest(rawId,callstack){var _a,_b;let id=normalizeId(rawId);if(externaled.has(id))return import(id);let fsPath=toFilePath(id,root);if(externaled.has(fsPath)||await shouldExternalize(fsPath))return externaled.add(fsPath),fsPath.match(/^\w:\//)?import(`/${fsPath}`):import(fsPath);if((_a=moduleCache2.get(fsPath))==null?void 0:_a.promise)return(_b=moduleCache2.get(fsPath))==null?void 0:_b.promise;let promise=directRequest(id,fsPath,callstack);return setCache(fsPath,{promise}),await promise}function exportAll(exports,sourceModule){for(let key in sourceModule)if(key!=="default")try{Object.defineProperty(exports,key,{enumerable:!0,configurable:!0,get(){return sourceModule[key]}})}catch{}}}function normalizeId(id){return id&&id.startsWith("/@id/__x00__")&&(id=`\0${id.slice("/@id/__x00__".length)}`),id&&id.startsWith("/@id/")&&(id=id.slice("/@id/".length)),id.startsWith("__vite-browser-external:")&&(id=id.slice("__vite-browser-external:".length)),id.startsWith("node:")&&(id=id.slice("node:".length)),id}function toFilePath(id,root){id=slash(id);let absolute=id.startsWith("/@fs/")?id.slice(4):id.startsWith(dirname(root))?id:id.startsWith("/")?slash(resolve(root,id.slice(1))):id;return absolute.startsWith("//")&&(absolute=absolute.slice(1)),isWindows&&absolute.startsWith("/")?pathToFileURL(absolute.slice(1)).href:absolute}function slash(path){return path.replace(/\\/g,"/")}var _run,moduleCache=new Map;async function init(ctx){if(_run)return _run;let{config}=ctx;return _run=(await executeInViteNode({root:config.root,files:[resolve2(distDir,"runtime/entry.js")],fetch(id){return process.__vitest_worker__.rpc("fetch",id)},inline:config.depsInline,external:config.depsExternal,moduleCache}))[0].run,_run}async function run(ctx){let{config,port}=ctx,rpcPromiseMap=new Map;process.__vitest_worker__={config,rpc:(method,...args)=>new Promise((resolve3,reject)=>{let id=nanoid();rpcPromiseMap.set(id,{resolve:resolve3,reject}),port.postMessage({method,args,id})}),send(method,...args){port.postMessage({method,args})}},port.addListener("message",async data=>{let api=rpcPromiseMap.get(data.id);api&&(data.error?api.reject(data.error):api.resolve(data.result))});let run2=await init(ctx);return ctx.invalidates&&ctx.invalidates.forEach(i=>moduleCache.delete(i)),ctx.files.forEach(i=>moduleCache.delete(i)),run2(ctx.files,ctx.config)}export{run as default,init};
|
package/dist/runtime/entry.d.ts
CHANGED
package/dist/runtime/entry.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{hasFailed,hasTests,interpretOnlyMode,packSnapshotState,partitionSuiteChildren}from"../chunk-HVAZQ6BP.js";import{clearContext,context,createSuiteHooks,defaultSuite,getFn,getHooks,setHooks}from"../chunk-
|
|
1
|
+
import{hasFailed,hasTests,interpretOnlyMode,packSnapshotState,partitionSuiteChildren}from"../chunk-HVAZQ6BP.js";import{clearContext,context,createSuiteHooks,defaultSuite,getFn,getHooks,setHooks}from"../chunk-A73PYES7.js";import"../chunk-2PVIVCXM.js";import{init_esm_shims}from"../chunk-64PJVUUV.js";init_esm_shims();init_esm_shims();init_esm_shims();import chai from"chai";import SinonChai from"sinon-chai";import Subset from"chai-subset";init_esm_shims();init_esm_shims();import path from"path";import Snap from"jest-snapshot";import{expect}from"chai";init_esm_shims();var rpc=async(method,...args)=>{var _a;return(_a=process.__vitest_worker__)==null?void 0:_a.rpc(method,...args)},send=async(method,...args)=>{var _a;return(_a=process.__vitest_worker__)==null?void 0:_a.send(method,...args)};var{SnapshotState}=Snap,resolveSnapshotPath=testPath=>path.join(path.join(path.dirname(testPath),"__snapshots__"),`${path.basename(testPath)}.snap`),SnapshotClient=class{ctx;testFile="";snapshotState;setTest(test){var _a;this.ctx={file:((_a=test.file)==null?void 0:_a.filepath)||test.name,title:test.name,fullTitle:[test.suite.name,test.name].filter(Boolean).join(" > ")},this.testFile!==this.ctx.file&&(this.snapshotState&&this.saveSnap(),this.snapshotState=new SnapshotState(resolveSnapshotPath(this.ctx.file),process.__vitest_worker__.config.snapshotOptions),this.testFile=this.ctx.file)}clearTest(){this.ctx=void 0}assert(received,message){if(!this.ctx)throw new Error("Snapshot can't not be used outside of test");let{actual,expected,key,pass}=this.snapshotState.match({testName:this.ctx.fullTitle||this.ctx.title||this.ctx.file,received,isInline:!1});pass||expect(actual.trim()).equals(expected?expected.trim():"",message||`Snapshot name: \`${key}\``)}async saveSnap(){if(!this.testFile||!this.snapshotState)return;let result=packSnapshotState(this.testFile,this.snapshotState);await rpc("snapshotSaved",result),this.testFile="",this.snapshotState=void 0}};var _client;function getSnapshotClient(){return _client||(_client=new SnapshotClient),_client}function SnapshotPlugin(){return function(chai2,utils){for(let key of["matchSnapshot","toMatchSnapshot"])utils.addMethod(chai2.Assertion.prototype,key,function(message){let expected=utils.flag(this,"object");getSnapshotClient().assert(expected,message)})}}init_esm_shims();function JestChaiExpect(){return(chai2,utils)=>{function def(name,fn){utils.addMethod(chai2.Assertion.prototype,name,fn)}def("toEqual",function(expected){return this.eql(expected)}),def("toStrictEqual",function(expected){return this.equal(expected)}),def("toBe",function(expected){return this.equal(expected)}),def("toMatchObject",function(expected){return this.containSubset(expected)}),def("toMatch",function(expected){return typeof expected=="string"?this.include(expected):this.match(expected)}),def("toContain",function(item){return this.contain(item)}),def("toContainEqual",function(expected){let obj=utils.flag(this,"object"),index=Array.from(obj).findIndex(item=>{try{chai2.assert.deepEqual(item,expected)}catch{return!1}return!0});this.assert(index!==-1,"expected #{this} to deep equally contain #{exp}","expected #{this} to not deep equally contain #{exp}",expected)}),def("toBeTruthy",function(){let obj=utils.flag(this,"object");this.assert(Boolean(obj),"expected #{this} to be truthy","expected #{this} to not be truthy",obj)}),def("toBeFalsy",function(){let obj=utils.flag(this,"object");this.assert(!obj,"expected #{this} to be falsy","expected #{this} to not be falsy",obj)}),def("toBeNaN",function(){return this.be.NaN}),def("toBeUndefined",function(){return this.be.undefined}),def("toBeNull",function(){return this.be.null}),def("toBeDefined",function(){return this.not.be.undefined}),def("toBeInstanceOf",function(obj){return this.instanceOf(obj)}),def("toHaveBeenCalledTimes",function(number){return this.callCount(number)}),def("toHaveBeenCalledOnce",function(){return this.callCount(1)}),def("toHaveBeenCalled",function(){return this.called}),def("toHaveBeenCalledWith",function(...args){return this.calledWith(...args)})}}var installed=!1;async function setupChai(){installed||(chai.use(SinonChai),chai.use(JestChaiExpect()),chai.use(Subset),chai.use(SnapshotPlugin()),installed=!0)}async function setupEnv(config){if(await setupChai(),config.global&&(await import("../global-P6HP35SI.js")).registerApiGlobally(),config.dom==="happy-dom")return(await import("../happy-dom-EZVJENUI.js")).setupHappyDOM(globalThis).restore;if(config.dom)return(await import("../jsdom-VHB26LUJ.js")).setupJSDOM(globalThis).restore}init_esm_shims();import{performance as performance2}from"perf_hooks";init_esm_shims();import{basename}from"path";import{performance}from"perf_hooks";import{nanoid}from"nanoid";init_esm_shims();function processError(err){return err&&(err.stack&&(err.stackStr=String(err.stack)),err.name&&(err.nameStr=String(err.name)),err)}async function collectTests(paths){let files=[];for(let filepath of paths){let file={id:nanoid(),name:basename(filepath),type:"suite",mode:"run",computeMode:"serial",filepath,tasks:[],suite:{}};setHooks(file,createSuiteHooks()),clearContext();try{await import(filepath);for(let c of[defaultSuite,...context.tasks])if(c.type==="test")file.tasks.push(c);else{let suite=await c.collect(file);(suite.name||suite.tasks.length)&&file.tasks.push(suite)}}catch(e){file.result={start:performance.now(),state:"fail",error:processError(e)}}files.push(file)}let tasks=files.reduce((tasks2,file)=>tasks2.concat(file.tasks),[]);return interpretOnlyMode(tasks),tasks.forEach(i=>{i.type==="suite"&&(i.mode==="skip"?i.tasks.forEach(c=>c.mode==="run"&&(c.mode="skip")):interpretOnlyMode(i.tasks))}),files}async function callHook(suite,name,args){await Promise.all(getHooks(suite)[name].map(fn=>fn(...args)))}function updateTask(task){return rpc("onTaskUpdate",[task.id,task.result])}async function runTest(test){if(test.mode==="run"){test.result={start:performance2.now(),state:"run"},updateTask(test),getSnapshotClient().setTest(test);try{await callHook(test.suite,"beforeEach",[test,test.suite]),await getFn(test)(),test.result.state="pass"}catch(e){test.result.state="fail",test.result.error=processError(e)}try{await callHook(test.suite,"afterEach",[test,test.suite])}catch(e){test.result.state="fail",test.result.error=processError(e)}getSnapshotClient().clearTest(),test.result.end=performance2.now(),updateTask(test)}}async function runSuite(suite){var _a;if(((_a=suite.result)==null?void 0:_a.state)!=="fail"){if(suite.result={start:performance2.now(),state:"run"},updateTask(suite),suite.mode==="skip")suite.result.state="skip";else if(suite.mode==="todo")suite.result.state="todo";else try{await callHook(suite,"beforeAll",[suite]);for(let tasksGroup of partitionSuiteChildren(suite)){let computeMode=tasksGroup[0].computeMode;if(computeMode==="serial")for(let c of tasksGroup)await runSuiteChild(c);else computeMode==="concurrent"&&await Promise.all(tasksGroup.map(c=>runSuiteChild(c)))}await callHook(suite,"afterAll",[suite])}catch(e){suite.result.state="fail",suite.result.error=processError(e)}suite.result.end=performance2.now(),suite.mode==="run"&&(hasTests(suite)?hasFailed(suite)?suite.result.state="fail":suite.result.state="pass":(suite.result.state="fail",suite.result.error||(suite.result.error=new Error(`No tests found in suite ${suite.name}`)))),updateTask(suite)}}async function runSuiteChild(c){return c.type==="test"?runTest(c):runSuite(c)}async function runSuites(suites){for(let suite of suites)await runSuite(suite)}async function startTests(paths){let files=await collectTests(paths);send("onCollected",files),await runSuites(files),await getSnapshotClient().saveSnap()}async function run(files,config){let restore=await setupEnv(config);await startTests(files),restore==null||restore()}export{run};
|
|
@@ -146,26 +146,27 @@ interface Test extends TaskBase {
|
|
|
146
146
|
}
|
|
147
147
|
declare type Task = Test | Suite | File;
|
|
148
148
|
declare type TestFunction = () => Awaitable<void>;
|
|
149
|
+
declare type TestCollectorFn = (name: string, fn: TestFunction, timeout?: number) => void;
|
|
149
150
|
interface ConcurrentCollector {
|
|
150
|
-
(name: string, fn: TestFunction): void;
|
|
151
|
-
only:
|
|
152
|
-
skip:
|
|
151
|
+
(name: string, fn: TestFunction, timeout?: number): void;
|
|
152
|
+
only: TestCollectorFn;
|
|
153
|
+
skip: TestCollectorFn;
|
|
153
154
|
todo: (name: string) => void;
|
|
154
155
|
}
|
|
155
156
|
interface OnlyCollector {
|
|
156
|
-
(name: string, fn: TestFunction): void;
|
|
157
|
-
concurrent:
|
|
157
|
+
(name: string, fn: TestFunction, timeout?: number): void;
|
|
158
|
+
concurrent: TestCollectorFn;
|
|
158
159
|
}
|
|
159
160
|
interface SkipCollector {
|
|
160
|
-
(name: string, fn: TestFunction): void;
|
|
161
|
-
concurrent:
|
|
161
|
+
(name: string, fn: TestFunction, timeout?: number): void;
|
|
162
|
+
concurrent: TestCollectorFn;
|
|
162
163
|
}
|
|
163
164
|
interface TodoCollector {
|
|
164
165
|
(name: string): void;
|
|
165
166
|
concurrent: (name: string) => void;
|
|
166
167
|
}
|
|
167
168
|
interface TestCollector {
|
|
168
|
-
(name: string, fn: TestFunction): void;
|
|
169
|
+
(name: string, fn: TestFunction, timeout?: number): void;
|
|
169
170
|
concurrent: ConcurrentCollector;
|
|
170
171
|
only: OnlyCollector;
|
|
171
172
|
skip: SkipCollector;
|
package/package.json
CHANGED
package/dist/chunk-76F2Y2GL.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{init_esm_shims}from"./chunk-64PJVUUV.js";init_esm_shims();import{resolve}from"path";import{fileURLToPath}from"url";var distDir=resolve(fileURLToPath(import.meta.url),"../../dist"),defaultIncludes=["**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}"],defaultExcludes=["**/node_modules/**","**/dist/**"],globalApis=["suite","test","describe","it","chai","expect","assert","sinon","spy","mock","stub","beforeAll","afterAll","beforeEach","afterEach"];export{distDir,defaultIncludes,defaultExcludes,globalApis};
|
package/dist/chunk-EPZJPNZW.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{init_esm_shims}from"./chunk-64PJVUUV.js";init_esm_shims();import{nanoid}from"nanoid";init_esm_shims();var context={tasks:[],currentSuite:null};init_esm_shims();var fnMap=new WeakMap,hooksMap=new WeakMap;function setFn(key,fn){fnMap.set(key,fn)}function getFn(key){return fnMap.get(key)}function setHooks(key,hooks){hooksMap.set(key,hooks)}function getHooks(key){return hooksMap.get(key)}var suite=createSuite(),defaultSuite=suite("");function getCurrentSuite(){return context.currentSuite||defaultSuite}function createSuiteHooks(){return{beforeAll:[],afterAll:[],beforeEach:[],afterEach:[]}}function createSuiteCollector(name,factory=()=>{},mode,suiteComputeMode){var _a;let tasks=[],factoryQueue=[],suite2;initSuite();let test2=createTestCollector((name2,fn,mode2,computeMode)=>{let test3={id:nanoid(),type:"test",name:name2,mode:mode2,computeMode:computeMode??suiteComputeMode??"serial",suite:{}};setFn(test3,fn),tasks.push(test3)}),collector={type:"collector",name,mode,test:test2,tasks,collect,clear,on:addHook};function addHook(name2,...fn){getHooks(suite2)[name2].push(...fn)}function initSuite(){suite2={id:nanoid(),type:"suite",computeMode:"serial",name,mode,tasks:[],suite:{}},setHooks(suite2,createSuiteHooks())}function clear(){tasks.length=0,factoryQueue.length=0,initSuite()}async function collect(file){if(factoryQueue.length=0,factory){let prev=context.currentSuite;context.currentSuite=collector,await factory(test2),context.currentSuite=prev}let allChildren=await Promise.all([...factoryQueue,...tasks].map(i=>i.type==="collector"?i.collect(file):i));return suite2.file=file,suite2.tasks=allChildren,allChildren.forEach(task=>{task.suite=suite2,file&&(task.file=file)}),suite2}return(_a=context.currentSuite)==null||_a.tasks.push(collector),collector}function createTestCollector(collectTest){function test2(name,fn){collectTest(name,fn,"run")}test2.concurrent=concurrent,test2.skip=skip,test2.only=only,test2.todo=todo;function concurrent(name,fn){collectTest(name,fn,"run","concurrent")}concurrent.skip=(name,fn)=>collectTest(name,fn,"skip","concurrent"),concurrent.only=(name,fn)=>collectTest(name,fn,"only","concurrent"),concurrent.todo=todo;function skip(name,fn){collectTest(name,fn,"skip")}skip.concurrent=concurrent.skip;function only(name,fn){collectTest(name,fn,"only")}only.concurrent=concurrent.only;function todo(name){collectTest(name,()=>{},"todo")}return todo.concurrent=todo,test2}var test=function(){function test2(name,fn){return getCurrentSuite().test(name,fn)}function concurrent(name,fn){return getCurrentSuite().test.concurrent(name,fn)}concurrent.skip=(name,fn)=>getCurrentSuite().test.concurrent.skip(name,fn),concurrent.only=(name,fn)=>getCurrentSuite().test.concurrent.only(name,fn),concurrent.todo=name=>getCurrentSuite().test.concurrent.todo(name);function skip(name,fn){return getCurrentSuite().test.skip(name,fn)}skip.concurrent=(name,fn)=>getCurrentSuite().test.skip.concurrent(name,fn);function only(name,fn){return getCurrentSuite().test.only(name,fn)}only.concurrent=(name,fn)=>getCurrentSuite().test.only.concurrent(name,fn);function todo(name){return getCurrentSuite().test.todo(name)}return todo.concurrent=name=>getCurrentSuite().test.todo.concurrent(name),test2.concurrent=concurrent,test2.skip=skip,test2.only=only,test2.todo=todo,test2}();function createSuite(){function suite2(suiteName,factory){return createSuiteCollector(suiteName,factory,"run")}function concurrent(suiteName,factory){return createSuiteCollector(suiteName,factory,"run","concurrent")}concurrent.skip=(suiteName,factory)=>createSuiteCollector(suiteName,factory,"skip","concurrent"),concurrent.only=(suiteName,factory)=>createSuiteCollector(suiteName,factory,"only","concurrent"),concurrent.todo=suiteName=>createSuiteCollector(suiteName,void 0,"todo");function skip(suiteName,factory){return createSuiteCollector(suiteName,factory,"skip")}skip.concurrent=concurrent.skip;function only(suiteName,factory){return createSuiteCollector(suiteName,factory,"only")}only.concurrent=concurrent.only;function todo(suiteName){return createSuiteCollector(suiteName,void 0,"todo")}return todo.concurrent=concurrent.todo,suite2.concurrent=concurrent,suite2.skip=skip,suite2.only=only,suite2.todo=todo,suite2}var describe=suite,it=test,beforeAll=fn=>getCurrentSuite().on("beforeAll",fn),afterAll=fn=>getCurrentSuite().on("afterAll",fn),beforeEach=fn=>getCurrentSuite().on("beforeEach",fn),afterEach=fn=>getCurrentSuite().on("afterEach",fn);function clearContext(){context.tasks.length=0,defaultSuite.clear(),context.currentSuite=defaultSuite}export{context,getFn,setHooks,getHooks,suite,defaultSuite,createSuiteHooks,test,describe,it,beforeAll,afterAll,beforeEach,afterEach,clearContext};
|