vitest 0.0.14 → 0.0.18
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.md +5 -3
- package/bin/vitest.mjs +1 -1
- package/dist/cli.js +22 -29
- package/dist/constants.js +6 -5
- package/dist/{cli-entry.d.ts → entry.d.ts} +0 -0
- package/dist/entry.js +38 -0
- package/dist/index.d.ts +27 -5
- package/dist/index.js +3 -5
- package/dist/integrations/chai/index.d.ts +3 -0
- package/dist/integrations/chai/index.js +3 -0
- package/dist/integrations/chai/jest-expect.d.ts +2 -0
- package/dist/{chai.js → integrations/chai/jest-expect.js} +19 -15
- package/dist/integrations/chai/setup.d.ts +2 -0
- package/dist/integrations/chai/setup.js +12 -0
- package/dist/integrations/chai/snapshot/index.d.ts +8 -0
- package/dist/{snapshot → integrations/chai/snapshot}/index.js +3 -13
- package/dist/{snapshot → integrations/chai/snapshot}/manager.d.ts +2 -0
- package/dist/{snapshot → integrations/chai/snapshot}/manager.js +8 -0
- package/dist/{snapshot → integrations/chai/snapshot}/utils/jest-config-helper.d.ts +0 -0
- package/dist/{snapshot → integrations/chai/snapshot}/utils/jest-config-helper.js +0 -0
- package/dist/{snapshot → integrations/chai/snapshot}/utils/jest-reporters-lite.d.ts +0 -0
- package/dist/{snapshot → integrations/chai/snapshot}/utils/jest-reporters-lite.js +0 -0
- package/dist/{snapshot → integrations/chai/snapshot}/utils/jest-test-result-helper.d.ts +0 -0
- package/dist/{snapshot → integrations/chai/snapshot}/utils/jest-test-result-helper.js +0 -0
- package/dist/{snapshot → integrations/chai/snapshot}/utils/types.d.ts +0 -0
- package/dist/{snapshot → integrations/chai/snapshot}/utils/types.js +0 -0
- package/dist/integrations/chai/types.d.ts +3 -0
- package/dist/integrations/chai/types.js +1 -0
- package/dist/integrations/jsdom.d.ts +5 -0
- package/dist/integrations/jsdom.js +20 -0
- package/dist/integrations/sinon.d.ts +3 -0
- package/dist/integrations/sinon.js +5 -0
- package/dist/reporters/default.d.ts +13 -8
- package/dist/reporters/default.js +60 -54
- package/dist/run.js +29 -21
- package/dist/suite.d.ts +5 -1
- package/dist/suite.js +32 -16
- package/dist/types.d.ts +27 -13
- package/global.d.ts +2 -5
- package/package.json +5 -1
- package/dist/chai.d.ts +0 -24
- package/dist/cli-entry.js +0 -28
- package/dist/hooks.d.ts +0 -49
- package/dist/hooks.js +0 -17
- package/dist/snapshot/index.d.ts +0 -9
package/README.md
CHANGED
|
@@ -6,10 +6,11 @@ A blazing fast test runner powered by Vite.
|
|
|
6
6
|
|
|
7
7
|
## Features
|
|
8
8
|
|
|
9
|
-
- [Vite](https://vitejs.dev/)'s config, transformers, resolvers, and plugins.
|
|
9
|
+
- [Vite](https://vitejs.dev/)'s config, transformers, resolvers, and plugins.
|
|
10
10
|
- [Jest Snapshot](https://jestjs.io/docs/snapshot-testing)
|
|
11
11
|
- [Chai](https://www.chaijs.com/) for assertions
|
|
12
12
|
- [Sinon](https://sinonjs.org/) for mocking
|
|
13
|
+
- [JSDOM](https://github.com/jsdom/jsdom) for DOM mocking
|
|
13
14
|
- Async suite / test, top level await
|
|
14
15
|
- ESM friendly
|
|
15
16
|
- Out-of-box TypeScript support
|
|
@@ -20,11 +21,12 @@ import { it, describe, expect, assert } from 'vitest'
|
|
|
20
21
|
|
|
21
22
|
describe('suite name', () => {
|
|
22
23
|
it('foo', () => {
|
|
23
|
-
|
|
24
|
+
expect(1 + 1).toEqual(2)
|
|
25
|
+
expect(true).to.be.true
|
|
24
26
|
})
|
|
25
27
|
|
|
26
28
|
it('bar', () => {
|
|
27
|
-
|
|
29
|
+
assert.equal(Math.sqrt(4), 2)
|
|
28
30
|
})
|
|
29
31
|
|
|
30
32
|
it('snapshot', () => {
|
package/bin/vitest.mjs
CHANGED
package/dist/cli.js
CHANGED
|
@@ -1,36 +1,29 @@
|
|
|
1
|
-
|
|
2
|
-
import { resolve, dirname } from 'path';
|
|
1
|
+
var _a;
|
|
3
2
|
import minimist from 'minimist';
|
|
4
|
-
import
|
|
5
|
-
import { run } from './
|
|
6
|
-
|
|
3
|
+
import c from 'picocolors';
|
|
4
|
+
import { run } from './run';
|
|
5
|
+
const { log } = console;
|
|
7
6
|
const argv = minimist(process.argv.slice(2), {
|
|
8
7
|
alias: {
|
|
9
|
-
|
|
8
|
+
u: 'update',
|
|
9
|
+
w: 'watch',
|
|
10
10
|
},
|
|
11
11
|
string: ['root', 'config'],
|
|
12
|
-
boolean: ['dev'],
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
resolve(__dirname, argv.dev ? '../src/cli-entry.ts' : './cli-entry.js'),
|
|
21
|
-
],
|
|
22
|
-
config: configPath,
|
|
23
|
-
defaultConfig: {
|
|
24
|
-
optimizeDeps: {
|
|
25
|
-
exclude: [
|
|
26
|
-
'vitest',
|
|
27
|
-
],
|
|
28
|
-
},
|
|
29
|
-
},
|
|
30
|
-
shouldExternalize(id) {
|
|
31
|
-
if (id.includes('/node_modules/vitest/'))
|
|
32
|
-
return false;
|
|
33
|
-
else
|
|
34
|
-
return id.includes('/node_modules/');
|
|
12
|
+
boolean: ['update', 'dev', 'global', 'watch', 'jsdom'],
|
|
13
|
+
unknown(name) {
|
|
14
|
+
if (name[0] === '-') {
|
|
15
|
+
console.error(c.red(`Unknown argument: ${name}`));
|
|
16
|
+
help();
|
|
17
|
+
process.exit(1);
|
|
18
|
+
}
|
|
19
|
+
return true;
|
|
35
20
|
},
|
|
36
21
|
});
|
|
22
|
+
// @ts-expect-error
|
|
23
|
+
const server = (_a = process === null || process === void 0 ? void 0 : process.__vite_node__) === null || _a === void 0 ? void 0 : _a.server;
|
|
24
|
+
const viteConfig = (server === null || server === void 0 ? void 0 : server.config) || {};
|
|
25
|
+
const testOptions = viteConfig.test || {};
|
|
26
|
+
await run(Object.assign(Object.assign(Object.assign({}, argv), testOptions), { server, updateSnapshot: argv.update, rootDir: argv.root || process.cwd(), nameFilters: argv._ }));
|
|
27
|
+
function help() {
|
|
28
|
+
log('Help: finish help');
|
|
29
|
+
}
|
package/dist/constants.js
CHANGED
|
@@ -1,22 +1,23 @@
|
|
|
1
1
|
export const defaultIncludes = ['**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}'];
|
|
2
2
|
export const defaultExcludes = ['**/node_modules/**', '**/dist/**'];
|
|
3
3
|
export const globalApis = [
|
|
4
|
+
// suite
|
|
4
5
|
'suite',
|
|
5
6
|
'test',
|
|
6
7
|
'describe',
|
|
7
8
|
'it',
|
|
9
|
+
// chai
|
|
10
|
+
'chai',
|
|
8
11
|
'expect',
|
|
9
12
|
'assert',
|
|
13
|
+
// sinon
|
|
14
|
+
'sinon',
|
|
10
15
|
'spy',
|
|
11
16
|
'mock',
|
|
12
17
|
'stub',
|
|
13
|
-
|
|
18
|
+
// hooks
|
|
14
19
|
'beforeAll',
|
|
15
20
|
'afterAll',
|
|
16
21
|
'beforeEach',
|
|
17
22
|
'afterEach',
|
|
18
|
-
'beforeFile',
|
|
19
|
-
'afterFile',
|
|
20
|
-
'beforeSuite',
|
|
21
|
-
'afterSuite',
|
|
22
23
|
];
|
|
File without changes
|
package/dist/entry.js
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { fileURLToPath } from 'url';
|
|
2
|
+
import { resolve, dirname } from 'path';
|
|
3
|
+
import minimist from 'minimist';
|
|
4
|
+
import { findUp } from 'find-up';
|
|
5
|
+
import { run } from './node.js';
|
|
6
|
+
process.env.VITEST = 'true';
|
|
7
|
+
const argv = minimist(process.argv.slice(2), {
|
|
8
|
+
alias: {
|
|
9
|
+
c: 'config',
|
|
10
|
+
},
|
|
11
|
+
string: ['root', 'config'],
|
|
12
|
+
boolean: ['dev'],
|
|
13
|
+
});
|
|
14
|
+
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
15
|
+
const root = resolve(argv.root || process.cwd());
|
|
16
|
+
const configPath = argv.config
|
|
17
|
+
? resolve(root, argv.config)
|
|
18
|
+
: await findUp(['vitest.config.ts', 'vitest.config.js', 'vitest.config.mjs', 'vite.config.ts', 'vite.config.js', 'vite.config.mjs'], { cwd: root });
|
|
19
|
+
await run({
|
|
20
|
+
root,
|
|
21
|
+
files: [
|
|
22
|
+
resolve(__dirname, argv.dev ? '../src/cli.ts' : './cli.js'),
|
|
23
|
+
],
|
|
24
|
+
config: configPath,
|
|
25
|
+
defaultConfig: {
|
|
26
|
+
optimizeDeps: {
|
|
27
|
+
exclude: [
|
|
28
|
+
'vitest',
|
|
29
|
+
],
|
|
30
|
+
},
|
|
31
|
+
},
|
|
32
|
+
shouldExternalize(id) {
|
|
33
|
+
if (id.includes('/node_modules/vitest/'))
|
|
34
|
+
return false;
|
|
35
|
+
else
|
|
36
|
+
return id.includes('/node_modules/');
|
|
37
|
+
},
|
|
38
|
+
});
|
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,30 @@
|
|
|
1
|
-
import sinon from 'sinon';
|
|
2
1
|
export * from './types';
|
|
3
2
|
export * from './suite';
|
|
4
3
|
export * from './config';
|
|
5
|
-
export * from './chai';
|
|
6
|
-
export
|
|
7
|
-
|
|
8
|
-
|
|
4
|
+
export * from './integrations/chai';
|
|
5
|
+
export * from './integrations/sinon';
|
|
6
|
+
declare global {
|
|
7
|
+
namespace Chai {
|
|
8
|
+
interface Assertion {
|
|
9
|
+
toMatchSnapshot(message?: string): Assertion;
|
|
10
|
+
matchSnapshot(message?: string): Assertion;
|
|
11
|
+
toEqual(expected: any): void;
|
|
12
|
+
toStrictEqual(expected: any): void;
|
|
13
|
+
toBe(expected: any): void;
|
|
14
|
+
toContain(item: any): void;
|
|
15
|
+
toBeTruthy(): void;
|
|
16
|
+
toBeFalsy(): void;
|
|
17
|
+
toBeNaN(): void;
|
|
18
|
+
toBeUndefined(): void;
|
|
19
|
+
toBeNull(): void;
|
|
20
|
+
toBeDefined(): void;
|
|
21
|
+
toBeInstanceOf(c: any): void;
|
|
22
|
+
toBeCalledTimes(n: number): void;
|
|
23
|
+
toBeCalledOnce(): void;
|
|
24
|
+
toBeCalled(): void;
|
|
25
|
+
}
|
|
26
|
+
interface ExpectStatic {
|
|
27
|
+
addSnapshotSerializer: import('pretty-format').Plugin;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
package/dist/index.js
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-namespace */
|
|
2
2
|
export * from './types';
|
|
3
3
|
export * from './suite';
|
|
4
4
|
export * from './config';
|
|
5
|
-
export * from './chai';
|
|
6
|
-
export
|
|
7
|
-
export { sinon };
|
|
8
|
-
export const { mock, spy, stub } = sinon;
|
|
5
|
+
export * from './integrations/chai';
|
|
6
|
+
export * from './integrations/sinon';
|
|
@@ -1,15 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
chai.use(SinonChai);
|
|
6
|
-
chai.use(await SnapshotPlugin({
|
|
7
|
-
rootDir: config.rootDir || process.cwd(),
|
|
8
|
-
update: config.updateSnapshot,
|
|
9
|
-
}));
|
|
10
|
-
// Jest Compact
|
|
11
|
-
// TODO: add more https://jestjs.io/docs/expect
|
|
12
|
-
chai.use((chai, utils) => {
|
|
1
|
+
// Jest Expect Compact
|
|
2
|
+
// TODO: add more https://jestjs.io/docs/expect
|
|
3
|
+
export function JestChaiExpect() {
|
|
4
|
+
return (chai, utils) => {
|
|
13
5
|
const proto = chai.Assertion.prototype;
|
|
14
6
|
utils.addMethod(proto, 'toEqual', function (expected) {
|
|
15
7
|
return this.eql(expected);
|
|
@@ -18,7 +10,7 @@ export async function setupChai(config) {
|
|
|
18
10
|
return this.equal(expected);
|
|
19
11
|
});
|
|
20
12
|
utils.addMethod(proto, 'toBe', function (expected) {
|
|
21
|
-
return this.
|
|
13
|
+
return this.equal(expected);
|
|
22
14
|
});
|
|
23
15
|
utils.addMethod(proto, 'toContain', function (item) {
|
|
24
16
|
return this.contain(item);
|
|
@@ -43,6 +35,18 @@ export async function setupChai(config) {
|
|
|
43
35
|
utils.addMethod(proto, 'toBeDefined', function () {
|
|
44
36
|
return this.not.be.undefined;
|
|
45
37
|
});
|
|
46
|
-
|
|
38
|
+
utils.addMethod(proto, 'toBeInstanceOf', function (obj) {
|
|
39
|
+
return this.instanceOf(obj);
|
|
40
|
+
});
|
|
41
|
+
// mock
|
|
42
|
+
utils.addMethod(proto, 'toBeCalledTimes', function (number) {
|
|
43
|
+
return this.callCount(number);
|
|
44
|
+
});
|
|
45
|
+
utils.addMethod(proto, 'toBeCalledOnce', function () {
|
|
46
|
+
return this.callCount(1);
|
|
47
|
+
});
|
|
48
|
+
utils.addMethod(proto, 'toBeCalled', function () {
|
|
49
|
+
return this.called;
|
|
50
|
+
});
|
|
51
|
+
};
|
|
47
52
|
}
|
|
48
|
-
export { assert, should, expect } from 'chai';
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import chai from 'chai';
|
|
2
|
+
import SinonChai from 'sinon-chai';
|
|
3
|
+
import { JestChaiExpect } from './jest-expect';
|
|
4
|
+
import { SnapshotPlugin } from './snapshot';
|
|
5
|
+
export async function setupChai(config) {
|
|
6
|
+
chai.use(SinonChai);
|
|
7
|
+
chai.use(JestChaiExpect());
|
|
8
|
+
chai.use(await SnapshotPlugin({
|
|
9
|
+
rootDir: config.rootDir || process.cwd(),
|
|
10
|
+
update: config.updateSnapshot,
|
|
11
|
+
}));
|
|
12
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { ChaiPlugin } from '../types';
|
|
2
|
+
import { SnapshotManager } from './manager';
|
|
3
|
+
export interface SnapshotOptions {
|
|
4
|
+
rootDir: string;
|
|
5
|
+
update?: boolean;
|
|
6
|
+
}
|
|
7
|
+
export declare function getSnapshotManager(): SnapshotManager;
|
|
8
|
+
export declare function SnapshotPlugin(options: SnapshotOptions): Promise<ChaiPlugin>;
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import Snap from 'jest-snapshot';
|
|
2
|
-
import { afterAll, beforeEach } from '../hooks';
|
|
3
2
|
import { SnapshotManager } from './manager';
|
|
4
3
|
const { addSerializer } = Snap;
|
|
5
4
|
let _manager;
|
|
5
|
+
export function getSnapshotManager() {
|
|
6
|
+
return _manager;
|
|
7
|
+
}
|
|
6
8
|
export async function SnapshotPlugin(options) {
|
|
7
9
|
const { rootDir } = options;
|
|
8
10
|
_manager = new SnapshotManager({
|
|
@@ -14,18 +16,6 @@ export async function SnapshotPlugin(options) {
|
|
|
14
16
|
rootDir,
|
|
15
17
|
});
|
|
16
18
|
return function (chai, utils) {
|
|
17
|
-
beforeEach((task) => {
|
|
18
|
-
var _a;
|
|
19
|
-
_manager.setContext({
|
|
20
|
-
file: ((_a = task.file) === null || _a === void 0 ? void 0 : _a.filepath) || task.name,
|
|
21
|
-
title: task.name,
|
|
22
|
-
fullTitle: [task.suite.name, task.name].filter(Boolean).join(' > '),
|
|
23
|
-
});
|
|
24
|
-
});
|
|
25
|
-
afterAll(() => {
|
|
26
|
-
_manager.saveSnap();
|
|
27
|
-
_manager.report();
|
|
28
|
-
});
|
|
29
19
|
for (const key of ['matchSnapshot', 'toMatchSnapshot']) {
|
|
30
20
|
utils.addMethod(chai.Assertion.prototype, key, function (message) {
|
|
31
21
|
const expected = utils.flag(this, 'object');
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { SnapshotStateType, SnapshotResolver } from 'jest-snapshot';
|
|
2
2
|
import type { SnapshotStateOptions } from 'jest-snapshot/build/State';
|
|
3
|
+
import { Task } from '../../../types';
|
|
3
4
|
import { SnapshotSummary } from './utils/types';
|
|
4
5
|
export interface Context {
|
|
5
6
|
file: string;
|
|
@@ -20,6 +21,7 @@ export declare class SnapshotManager {
|
|
|
20
21
|
snapshotResolver?: SnapshotResolver | null;
|
|
21
22
|
});
|
|
22
23
|
onFileChanged(): void;
|
|
24
|
+
setTask(task: Task): void;
|
|
23
25
|
setContext(context: Context): void;
|
|
24
26
|
assert(received: unknown, message: string): void;
|
|
25
27
|
saveSnap(): void;
|
|
@@ -31,6 +31,14 @@ export class SnapshotManager {
|
|
|
31
31
|
this.testFile = this.context.file;
|
|
32
32
|
this.snapshotState = new SnapshotState(this.snapshotResolver.resolveSnapshotPath(this.testFile), this.snapshotOptions);
|
|
33
33
|
}
|
|
34
|
+
setTask(task) {
|
|
35
|
+
var _a;
|
|
36
|
+
this.setContext({
|
|
37
|
+
file: ((_a = task.file) === null || _a === void 0 ? void 0 : _a.filepath) || task.name,
|
|
38
|
+
title: task.name,
|
|
39
|
+
fullTitle: [task.suite.name, task.name].filter(Boolean).join(' > '),
|
|
40
|
+
});
|
|
41
|
+
}
|
|
34
42
|
setContext(context) {
|
|
35
43
|
if (!context.title || !context.file)
|
|
36
44
|
return;
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { JSDOM } from 'jsdom';
|
|
2
|
+
export function setupJSDOM(global) {
|
|
3
|
+
const dom = new JSDOM('<!DOCTYPE html>', {
|
|
4
|
+
pretendToBeVisual: true,
|
|
5
|
+
runScripts: 'dangerously',
|
|
6
|
+
// TODO: options
|
|
7
|
+
url: 'http://localhost:3000',
|
|
8
|
+
});
|
|
9
|
+
const keys = Object.getOwnPropertyNames(dom.window)
|
|
10
|
+
.filter(k => !k.startsWith('_'))
|
|
11
|
+
.filter(k => !(k in global));
|
|
12
|
+
for (const key of keys)
|
|
13
|
+
global[key] = dom.window[key];
|
|
14
|
+
return {
|
|
15
|
+
dom,
|
|
16
|
+
restore() {
|
|
17
|
+
keys.forEach(key => delete global[key]);
|
|
18
|
+
},
|
|
19
|
+
};
|
|
20
|
+
}
|
|
@@ -1,19 +1,24 @@
|
|
|
1
|
-
import
|
|
1
|
+
import Listr from 'listr';
|
|
2
|
+
import { Reporter, RunnerContext, Task } from '../types';
|
|
3
|
+
interface TaskPromise {
|
|
4
|
+
promise: Promise<void>;
|
|
5
|
+
resolve: () => void;
|
|
6
|
+
reject: (e: unknown) => void;
|
|
7
|
+
}
|
|
2
8
|
export declare class DefaultReporter implements Reporter {
|
|
3
9
|
indent: number;
|
|
4
10
|
start: number;
|
|
5
11
|
end: number;
|
|
12
|
+
listr: Listr | null;
|
|
13
|
+
listrPromise: Promise<void> | null;
|
|
14
|
+
taskMap: Map<Task, TaskPromise>;
|
|
6
15
|
onStart(): void;
|
|
7
|
-
onCollected(): void;
|
|
8
|
-
onSuiteBegin(suite: Suite): void;
|
|
9
|
-
onSuiteEnd(suite: Suite): void;
|
|
10
|
-
onFileBegin(file: File): void;
|
|
11
|
-
onFileEnd(): void;
|
|
12
|
-
onTaskBegin(task: Task): void;
|
|
16
|
+
onCollected(ctx: RunnerContext): void;
|
|
13
17
|
onTaskEnd(task: Task): void;
|
|
14
|
-
onFinished({ files }: RunnerContext): void
|
|
18
|
+
onFinished({ files }: RunnerContext): Promise<void>;
|
|
15
19
|
private getIndent;
|
|
16
20
|
private log;
|
|
17
21
|
private error;
|
|
18
22
|
onSnapshotUpdate(): void;
|
|
19
23
|
}
|
|
24
|
+
export {};
|
|
@@ -1,69 +1,75 @@
|
|
|
1
|
-
import { relative } from 'path';
|
|
2
1
|
import { performance } from 'perf_hooks';
|
|
2
|
+
import { relative } from 'path';
|
|
3
3
|
import c from 'picocolors';
|
|
4
|
-
import
|
|
5
|
-
const
|
|
6
|
-
const CHECK = '✔ ';
|
|
7
|
-
const CROSS = '⤫ ';
|
|
4
|
+
import Listr from 'listr';
|
|
5
|
+
const CROSS = '✖ ';
|
|
8
6
|
export class DefaultReporter {
|
|
9
7
|
constructor() {
|
|
10
8
|
this.indent = 0;
|
|
11
9
|
this.start = 0;
|
|
12
10
|
this.end = 0;
|
|
11
|
+
this.listr = null;
|
|
12
|
+
this.listrPromise = null;
|
|
13
|
+
this.taskMap = new Map();
|
|
13
14
|
}
|
|
14
15
|
onStart() {
|
|
15
16
|
this.indent = 0;
|
|
16
17
|
}
|
|
17
|
-
onCollected() {
|
|
18
|
+
onCollected(ctx) {
|
|
18
19
|
this.start = performance.now();
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
20
|
+
this.taskMap = new Map();
|
|
21
|
+
const tasks = ctx.files.reduce((acc, file) => acc.concat(file.suites.flatMap(i => i.tasks)), []);
|
|
22
|
+
tasks.forEach((t) => {
|
|
23
|
+
const obj = {};
|
|
24
|
+
obj.promise = new Promise((resolve, reject) => {
|
|
25
|
+
obj.resolve = resolve;
|
|
26
|
+
obj.reject = reject;
|
|
27
|
+
});
|
|
28
|
+
this.taskMap.set(t, obj);
|
|
29
|
+
});
|
|
30
|
+
const createTasksListr = (tasks) => {
|
|
31
|
+
return tasks.map((task) => {
|
|
32
|
+
return {
|
|
33
|
+
title: task.name,
|
|
34
|
+
skip: () => task.mode === 'skip',
|
|
35
|
+
task: async () => {
|
|
36
|
+
var _a;
|
|
37
|
+
return await ((_a = this.taskMap.get(task)) === null || _a === void 0 ? void 0 : _a.promise);
|
|
38
|
+
},
|
|
39
|
+
};
|
|
40
|
+
});
|
|
41
|
+
};
|
|
42
|
+
const listrOptions = {
|
|
43
|
+
exitOnError: false,
|
|
44
|
+
};
|
|
45
|
+
this.listr = new Listr(ctx.files.map((file) => {
|
|
46
|
+
return {
|
|
47
|
+
title: relative(process.cwd(), file.filepath),
|
|
48
|
+
task: () => {
|
|
49
|
+
return new Listr(file.suites.flatMap((suite) => {
|
|
50
|
+
if (!suite.name)
|
|
51
|
+
return createTasksListr(suite.tasks);
|
|
52
|
+
return [{
|
|
53
|
+
title: suite.name,
|
|
54
|
+
skip: () => suite.mode !== 'run',
|
|
55
|
+
task: () => new Listr(createTasksListr(suite.tasks), listrOptions),
|
|
56
|
+
}];
|
|
57
|
+
}), listrOptions);
|
|
58
|
+
},
|
|
59
|
+
};
|
|
60
|
+
}), listrOptions);
|
|
61
|
+
this.listrPromise = this.listr.run().catch(() => { });
|
|
46
62
|
}
|
|
47
63
|
onTaskEnd(task) {
|
|
48
|
-
var _a;
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
this.
|
|
53
|
-
}
|
|
54
|
-
else if (task.state === 'skip') {
|
|
55
|
-
this.log(c.dim(c.yellow(`${DOT + task.name} (skipped)`)));
|
|
56
|
-
}
|
|
57
|
-
else if (task.state === 'todo') {
|
|
58
|
-
this.log(c.dim(`${DOT + task.name} (todo)`));
|
|
59
|
-
}
|
|
60
|
-
else {
|
|
61
|
-
this.error(`${c.red(`${CROSS}${task.name}`)}`);
|
|
62
|
-
process.exitCode = 1;
|
|
63
|
-
}
|
|
64
|
-
this.indent -= 1;
|
|
64
|
+
var _a, _b;
|
|
65
|
+
if (task.state === 'fail')
|
|
66
|
+
(_a = this.taskMap.get(task)) === null || _a === void 0 ? void 0 : _a.reject(task.error);
|
|
67
|
+
else
|
|
68
|
+
(_b = this.taskMap.get(task)) === null || _b === void 0 ? void 0 : _b.resolve();
|
|
65
69
|
}
|
|
66
|
-
onFinished({ files }) {
|
|
70
|
+
async onFinished({ files }) {
|
|
71
|
+
await this.listrPromise;
|
|
72
|
+
this.log();
|
|
67
73
|
this.end = performance.now();
|
|
68
74
|
const failedFiles = files.filter(i => i.error);
|
|
69
75
|
const tasks = files.reduce((acc, file) => acc.concat(file.suites.flatMap(i => i.tasks)), []);
|
|
@@ -85,14 +91,14 @@ export class DefaultReporter {
|
|
|
85
91
|
this.error(c.bold(`\nFailed Tests (${failed.length})`));
|
|
86
92
|
failed.forEach((task) => {
|
|
87
93
|
var _a;
|
|
88
|
-
this.error(`\n${CROSS + c.inverse(c.red(' FAIL '))} ${[task.suite.name, task.name].filter(Boolean).join(' > ')} ${c.gray(`${(_a = task.file) === null || _a === void 0 ? void 0 : _a.filepath}`)}`);
|
|
94
|
+
this.error(`\n${CROSS + c.inverse(c.red(' FAIL '))} ${[task.suite.name, task.name].filter(Boolean).join(' > ')} ${c.gray(c.dim(`${(_a = task.file) === null || _a === void 0 ? void 0 : _a.filepath}`))}`);
|
|
89
95
|
console.error(task.error || 'Unknown error');
|
|
90
96
|
this.log();
|
|
91
97
|
});
|
|
92
98
|
}
|
|
93
|
-
this.log(c.green(`Passed ${passed.length} / ${runable.length}`));
|
|
99
|
+
this.log(c.bold(c.green(`Passed ${passed.length} / ${runable.length}`)));
|
|
94
100
|
if (failed.length)
|
|
95
|
-
this.log(c.red(`Failed ${failed.length} / ${runable.length}`));
|
|
101
|
+
this.log(c.bold(c.red(`Failed ${failed.length} / ${runable.length}`)));
|
|
96
102
|
if (skipped.length)
|
|
97
103
|
this.log(c.yellow(`Skipped ${skipped.length}`));
|
|
98
104
|
if (todo.length)
|
package/dist/run.js
CHANGED
|
@@ -1,16 +1,20 @@
|
|
|
1
1
|
import fg from 'fast-glob';
|
|
2
|
-
import { setupChai } from './chai';
|
|
2
|
+
import { setupChai } from './integrations/chai/setup';
|
|
3
3
|
import { clearContext, defaultSuite } from './suite';
|
|
4
4
|
import { context } from './context';
|
|
5
|
-
import { afterEachHook, afterFileHook, afterAllHook, afterSuiteHook, beforeEachHook, beforeFileHook, beforeAllHook, beforeSuiteHook } from './hooks';
|
|
6
5
|
import { DefaultReporter } from './reporters/default';
|
|
7
6
|
import { defaultIncludes, defaultExcludes } from './constants';
|
|
7
|
+
import { getSnapshotManager } from './integrations/chai/snapshot';
|
|
8
|
+
async function callHook(suite, name, args) {
|
|
9
|
+
await Promise.all(suite.hooks[name].map(fn => fn(...args)));
|
|
10
|
+
}
|
|
8
11
|
export async function runTask(task, ctx) {
|
|
9
|
-
var _a, _b;
|
|
12
|
+
var _a, _b, _c;
|
|
10
13
|
const { reporter } = ctx;
|
|
11
|
-
|
|
14
|
+
(_a = getSnapshotManager()) === null || _a === void 0 ? void 0 : _a.setTask(task);
|
|
15
|
+
await ((_b = reporter.onTaskBegin) === null || _b === void 0 ? void 0 : _b.call(reporter, task, ctx));
|
|
12
16
|
if (task.mode === 'run') {
|
|
13
|
-
await
|
|
17
|
+
await callHook(task.suite, 'afterEach', [task, task.suite]);
|
|
14
18
|
try {
|
|
15
19
|
await task.fn();
|
|
16
20
|
task.state = 'pass';
|
|
@@ -19,9 +23,9 @@ export async function runTask(task, ctx) {
|
|
|
19
23
|
task.state = 'fail';
|
|
20
24
|
task.error = e;
|
|
21
25
|
}
|
|
22
|
-
await
|
|
26
|
+
await callHook(task.suite, 'afterEach', [task, task.suite]);
|
|
23
27
|
}
|
|
24
|
-
await ((
|
|
28
|
+
await ((_c = reporter.onTaskEnd) === null || _c === void 0 ? void 0 : _c.call(reporter, task, ctx));
|
|
25
29
|
}
|
|
26
30
|
export async function collectFiles(paths) {
|
|
27
31
|
const files = [];
|
|
@@ -72,23 +76,24 @@ function interpretOnlyMode(items) {
|
|
|
72
76
|
}
|
|
73
77
|
}
|
|
74
78
|
export async function runFile(file, ctx) {
|
|
75
|
-
var _a, _b
|
|
79
|
+
var _a, _b;
|
|
76
80
|
const { reporter } = ctx;
|
|
77
81
|
const runableSuites = file.suites.filter(i => i.mode === 'run');
|
|
78
82
|
if (runableSuites.length === 0)
|
|
79
83
|
return;
|
|
80
84
|
await ((_a = reporter.onFileBegin) === null || _a === void 0 ? void 0 : _a.call(reporter, file, ctx));
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
await
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
await (
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
85
|
+
// TODO: support toggling parallel or serial
|
|
86
|
+
await Promise.all(file.suites.map(async (suite) => {
|
|
87
|
+
var _a, _b;
|
|
88
|
+
await ((_a = reporter.onSuiteBegin) === null || _a === void 0 ? void 0 : _a.call(reporter, suite, ctx));
|
|
89
|
+
await callHook(suite, 'beforeAll', [suite]);
|
|
90
|
+
await Promise.all(suite.tasks.map(i => runTask(i, ctx)));
|
|
91
|
+
// for (const t of suite.tasks)
|
|
92
|
+
// await runTask(t, ctx)
|
|
93
|
+
await callHook(suite, 'afterAll', [suite]);
|
|
94
|
+
await ((_b = reporter.onSuiteEnd) === null || _b === void 0 ? void 0 : _b.call(reporter, suite, ctx));
|
|
95
|
+
}));
|
|
96
|
+
await ((_b = reporter.onFileEnd) === null || _b === void 0 ? void 0 : _b.call(reporter, file, ctx));
|
|
92
97
|
}
|
|
93
98
|
export async function run(config) {
|
|
94
99
|
var _a, _b, _c, _d;
|
|
@@ -111,6 +116,8 @@ export async function run(config) {
|
|
|
111
116
|
await ((_b = reporter.onStart) === null || _b === void 0 ? void 0 : _b.call(reporter, config));
|
|
112
117
|
if (config.global)
|
|
113
118
|
(await import('./global')).registerApiGlobally();
|
|
119
|
+
if (config.jsdom)
|
|
120
|
+
(await import('./integrations/jsdom')).setupJSDOM(globalThis);
|
|
114
121
|
const files = await collectFiles(paths);
|
|
115
122
|
const ctx = {
|
|
116
123
|
files,
|
|
@@ -118,9 +125,10 @@ export async function run(config) {
|
|
|
118
125
|
reporter,
|
|
119
126
|
};
|
|
120
127
|
await ((_c = reporter.onCollected) === null || _c === void 0 ? void 0 : _c.call(reporter, ctx));
|
|
121
|
-
await beforeAllHook.fire();
|
|
122
128
|
for (const file of files)
|
|
123
129
|
await runFile(file, ctx);
|
|
124
|
-
|
|
130
|
+
const snapshot = getSnapshotManager();
|
|
131
|
+
snapshot === null || snapshot === void 0 ? void 0 : snapshot.saveSnap();
|
|
132
|
+
snapshot === null || snapshot === void 0 ? void 0 : snapshot.report();
|
|
125
133
|
await ((_d = reporter.onFinished) === null || _d === void 0 ? void 0 : _d.call(reporter, ctx));
|
|
126
134
|
}
|
package/dist/suite.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { SuiteCollector, TestFactory, TestFunction } from './types';
|
|
1
|
+
import { SuiteCollector, TestFactory, TestFunction, Suite } from './types';
|
|
2
2
|
export declare const defaultSuite: SuiteCollector;
|
|
3
3
|
export declare const test: {
|
|
4
4
|
(name: string, fn: TestFunction): void;
|
|
@@ -19,4 +19,8 @@ export declare const it: {
|
|
|
19
19
|
only(name: string, fn: TestFunction): void;
|
|
20
20
|
todo(name: string): void;
|
|
21
21
|
};
|
|
22
|
+
export declare const beforeAll: (fn: Suite['hooks']['beforeAll'][0]) => void;
|
|
23
|
+
export declare const afterAll: (fn: Suite['hooks']['afterAll'][0]) => void;
|
|
24
|
+
export declare const beforeEach: (fn: Suite['hooks']['beforeEach'][0]) => void;
|
|
25
|
+
export declare const afterEach: (fn: Suite['hooks']['afterEach'][0]) => void;
|
|
22
26
|
export declare function clearContext(): void;
|
package/dist/suite.js
CHANGED
|
@@ -3,20 +3,30 @@ export const defaultSuite = suite('');
|
|
|
3
3
|
function getCurrentSuite() {
|
|
4
4
|
return context.currentSuite || defaultSuite;
|
|
5
5
|
}
|
|
6
|
-
|
|
7
|
-
test.skip = (name, fn) => getCurrentSuite().test.skip(name, fn);
|
|
8
|
-
test.only = (name, fn) => getCurrentSuite().test.only(name, fn);
|
|
9
|
-
test.todo = (name) => getCurrentSuite().test.todo(name);
|
|
10
|
-
function createSuiteCollector(mode, suiteName, factory) {
|
|
6
|
+
function createSuiteCollector(name, factory = () => { }, mode) {
|
|
11
7
|
const queue = [];
|
|
12
8
|
const factoryQueue = [];
|
|
9
|
+
const suiteBase = {
|
|
10
|
+
name,
|
|
11
|
+
mode,
|
|
12
|
+
hooks: {
|
|
13
|
+
beforeAll: [],
|
|
14
|
+
afterAll: [],
|
|
15
|
+
beforeEach: [],
|
|
16
|
+
afterEach: [],
|
|
17
|
+
},
|
|
18
|
+
};
|
|
13
19
|
const collector = {
|
|
14
|
-
name
|
|
20
|
+
name,
|
|
15
21
|
mode,
|
|
16
22
|
test,
|
|
17
23
|
collect,
|
|
18
24
|
clear,
|
|
25
|
+
on: addHook,
|
|
19
26
|
};
|
|
27
|
+
function addHook(name, ...fn) {
|
|
28
|
+
suiteBase.hooks[name].push(...fn);
|
|
29
|
+
}
|
|
20
30
|
function collectTask(name, fn, mode) {
|
|
21
31
|
queue.push({
|
|
22
32
|
name,
|
|
@@ -41,12 +51,8 @@ function createSuiteCollector(mode, suiteName, factory) {
|
|
|
41
51
|
if (factory)
|
|
42
52
|
await factory(test);
|
|
43
53
|
const tasks = [...factoryQueue, ...queue];
|
|
44
|
-
const suite = {
|
|
45
|
-
|
|
46
|
-
mode: collector.mode,
|
|
47
|
-
tasks,
|
|
48
|
-
file,
|
|
49
|
-
};
|
|
54
|
+
const suite = Object.assign(Object.assign({}, suiteBase), { tasks,
|
|
55
|
+
file });
|
|
50
56
|
tasks.forEach((task) => {
|
|
51
57
|
task.suite = suite;
|
|
52
58
|
if (file)
|
|
@@ -58,15 +64,25 @@ function createSuiteCollector(mode, suiteName, factory) {
|
|
|
58
64
|
context.suites.push(collector);
|
|
59
65
|
return collector;
|
|
60
66
|
}
|
|
67
|
+
// apis
|
|
68
|
+
export const test = (name, fn) => getCurrentSuite().test(name, fn);
|
|
69
|
+
test.skip = (name, fn) => getCurrentSuite().test.skip(name, fn);
|
|
70
|
+
test.only = (name, fn) => getCurrentSuite().test.only(name, fn);
|
|
71
|
+
test.todo = (name) => getCurrentSuite().test.todo(name);
|
|
61
72
|
export function suite(suiteName, factory) {
|
|
62
|
-
return createSuiteCollector(
|
|
73
|
+
return createSuiteCollector(suiteName, factory, 'run');
|
|
63
74
|
}
|
|
64
|
-
suite.skip = (suiteName, factory) => createSuiteCollector(
|
|
65
|
-
suite.only = (suiteName, factory) => createSuiteCollector(
|
|
66
|
-
suite.todo = (suiteName) => createSuiteCollector('todo'
|
|
75
|
+
suite.skip = (suiteName, factory) => createSuiteCollector(suiteName, factory, 'skip');
|
|
76
|
+
suite.only = (suiteName, factory) => createSuiteCollector(suiteName, factory, 'only');
|
|
77
|
+
suite.todo = (suiteName) => createSuiteCollector(suiteName, undefined, 'todo');
|
|
67
78
|
// alias
|
|
68
79
|
export const describe = suite;
|
|
69
80
|
export const it = test;
|
|
81
|
+
// hooks
|
|
82
|
+
export const beforeAll = (fn) => getCurrentSuite().on('beforeAll', fn);
|
|
83
|
+
export const afterAll = (fn) => getCurrentSuite().on('afterAll', fn);
|
|
84
|
+
export const beforeEach = (fn) => getCurrentSuite().on('beforeEach', fn);
|
|
85
|
+
export const afterEach = (fn) => getCurrentSuite().on('afterEach', fn);
|
|
70
86
|
// utils
|
|
71
87
|
export function clearContext() {
|
|
72
88
|
context.suites.length = 0;
|
package/dist/types.d.ts
CHANGED
|
@@ -8,7 +8,13 @@ export interface UserOptions {
|
|
|
8
8
|
*
|
|
9
9
|
* @default false
|
|
10
10
|
*/
|
|
11
|
-
global?:
|
|
11
|
+
global?: boolean;
|
|
12
|
+
/**
|
|
13
|
+
* Use `js-dom` to mock browser APIs
|
|
14
|
+
*
|
|
15
|
+
* @default false
|
|
16
|
+
*/
|
|
17
|
+
jsdom?: boolean;
|
|
12
18
|
}
|
|
13
19
|
export interface Config extends UserOptions {
|
|
14
20
|
rootDir?: string;
|
|
@@ -35,18 +41,26 @@ export interface TestCollector {
|
|
|
35
41
|
skip: (name: string, fn: TestFunction) => void;
|
|
36
42
|
todo: (name: string) => void;
|
|
37
43
|
}
|
|
44
|
+
export declare type HookListener<T extends any[]> = (...args: T) => Awaitable<void>;
|
|
38
45
|
export interface Suite {
|
|
39
46
|
name: string;
|
|
40
47
|
mode: RunMode;
|
|
41
48
|
tasks: Task[];
|
|
42
49
|
file?: File;
|
|
50
|
+
hooks: {
|
|
51
|
+
beforeAll: HookListener<[Suite]>[];
|
|
52
|
+
afterAll: HookListener<[Suite]>[];
|
|
53
|
+
beforeEach: HookListener<[Task, Suite]>[];
|
|
54
|
+
afterEach: HookListener<[Task, Suite]>[];
|
|
55
|
+
};
|
|
43
56
|
}
|
|
44
57
|
export interface SuiteCollector {
|
|
45
|
-
name: string;
|
|
46
|
-
mode: RunMode;
|
|
58
|
+
readonly name: string;
|
|
59
|
+
readonly mode: RunMode;
|
|
47
60
|
test: TestCollector;
|
|
48
61
|
collect: (file?: File) => Promise<Suite>;
|
|
49
62
|
clear: () => void;
|
|
63
|
+
on: <T extends keyof Suite['hooks']>(name: T, ...fn: Suite['hooks'][T]) => void;
|
|
50
64
|
}
|
|
51
65
|
export declare type TestFactory = (test: (name: string, fn: TestFunction) => void) => Awaitable<void>;
|
|
52
66
|
export interface File {
|
|
@@ -65,14 +79,14 @@ export interface GlobalContext {
|
|
|
65
79
|
currentSuite: SuiteCollector | null;
|
|
66
80
|
}
|
|
67
81
|
export interface Reporter {
|
|
68
|
-
onStart
|
|
69
|
-
onCollected
|
|
70
|
-
onFinished
|
|
71
|
-
onSuiteBegin
|
|
72
|
-
onSuiteEnd
|
|
73
|
-
onFileBegin
|
|
74
|
-
onFileEnd
|
|
75
|
-
onTaskBegin
|
|
76
|
-
onTaskEnd
|
|
77
|
-
onSnapshotUpdate
|
|
82
|
+
onStart?: (userOptions: Config) => Awaitable<void>;
|
|
83
|
+
onCollected?: (ctx: RunnerContext) => Awaitable<void>;
|
|
84
|
+
onFinished?: (ctx: RunnerContext) => Awaitable<void>;
|
|
85
|
+
onSuiteBegin?: (suite: Suite, ctx: RunnerContext) => Awaitable<void>;
|
|
86
|
+
onSuiteEnd?: (suite: Suite, ctx: RunnerContext) => Awaitable<void>;
|
|
87
|
+
onFileBegin?: (file: File, ctx: RunnerContext) => Awaitable<void>;
|
|
88
|
+
onFileEnd?: (file: File, ctx: RunnerContext) => Awaitable<void>;
|
|
89
|
+
onTaskBegin?: (task: Task, ctx: RunnerContext) => Awaitable<void>;
|
|
90
|
+
onTaskEnd?: (task: Task, ctx: RunnerContext) => Awaitable<void>;
|
|
91
|
+
onSnapshotUpdate?: () => Awaitable<void>;
|
|
78
92
|
}
|
package/global.d.ts
CHANGED
|
@@ -3,19 +3,16 @@ declare global {
|
|
|
3
3
|
const test: typeof import('vitest')['test']
|
|
4
4
|
const describe: typeof import('vitest')['describe']
|
|
5
5
|
const it: typeof import('vitest')['it']
|
|
6
|
+
const chai: typeof import('vitest')['chai']
|
|
6
7
|
const expect: typeof import('vitest')['expect']
|
|
7
8
|
const assert: typeof import('vitest')['assert']
|
|
9
|
+
const sinon: typeof import('vitest')['sinon']
|
|
8
10
|
const spy: typeof import('vitest')['spy']
|
|
9
11
|
const mock: typeof import('vitest')['mock']
|
|
10
12
|
const stub: typeof import('vitest')['stub']
|
|
11
|
-
const sinon: typeof import('vitest')['sinon']
|
|
12
13
|
const beforeAll: typeof import('vitest')['beforeAll']
|
|
13
14
|
const afterAll: typeof import('vitest')['afterAll']
|
|
14
15
|
const beforeEach: typeof import('vitest')['beforeEach']
|
|
15
16
|
const afterEach: typeof import('vitest')['afterEach']
|
|
16
|
-
const beforeFile: typeof import('vitest')['beforeFile']
|
|
17
|
-
const afterFile: typeof import('vitest')['afterFile']
|
|
18
|
-
const beforeSuite: typeof import('vitest')['beforeSuite']
|
|
19
|
-
const afterSuite: typeof import('vitest')['afterSuite']
|
|
20
17
|
}
|
|
21
18
|
export {}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vitest",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.18",
|
|
4
4
|
"description": "",
|
|
5
5
|
"keywords": [],
|
|
6
6
|
"homepage": "https://github.com/antfu/vitest#readme",
|
|
@@ -42,6 +42,8 @@
|
|
|
42
42
|
"find-up": "^6.2.0",
|
|
43
43
|
"jest-snapshot": "^27.4.2",
|
|
44
44
|
"jest-util": "^27.4.2",
|
|
45
|
+
"jsdom": "^19.0.0",
|
|
46
|
+
"listr": "^0.14.3",
|
|
45
47
|
"minimist": "^1.2.5",
|
|
46
48
|
"ora": "^6.0.1",
|
|
47
49
|
"picocolors": "^1.0.0",
|
|
@@ -51,6 +53,8 @@
|
|
|
51
53
|
"devDependencies": {
|
|
52
54
|
"@antfu/eslint-config": "^0.11.1",
|
|
53
55
|
"@antfu/ni": "^0.11.0",
|
|
56
|
+
"@types/jsdom": "^16.2.13",
|
|
57
|
+
"@types/listr": "^0.14.4",
|
|
54
58
|
"@types/minimist": "^1.2.2",
|
|
55
59
|
"@types/node": "^16.11.11",
|
|
56
60
|
"@types/sinon": "^10.0.6",
|
package/dist/chai.d.ts
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { Config } from 'vitest';
|
|
2
|
-
export declare function setupChai(config: Config): Promise<void>;
|
|
3
|
-
export { assert, should, expect } from 'chai';
|
|
4
|
-
declare global {
|
|
5
|
-
namespace Chai {
|
|
6
|
-
interface Assertion {
|
|
7
|
-
toMatchSnapshot(message?: string): Assertion;
|
|
8
|
-
matchSnapshot(message?: string): Assertion;
|
|
9
|
-
toEqual(expected: any): void;
|
|
10
|
-
toStrictEqual(expected: any): void;
|
|
11
|
-
toBe(expected: any): void;
|
|
12
|
-
toContain(item: any): void;
|
|
13
|
-
toBeTruthy(): void;
|
|
14
|
-
toBeFalsy(): void;
|
|
15
|
-
toBeNaN(): void;
|
|
16
|
-
toBeUndefined(): void;
|
|
17
|
-
toBeNull(): void;
|
|
18
|
-
toBeDefined(): void;
|
|
19
|
-
}
|
|
20
|
-
interface ExpectStatic {
|
|
21
|
-
addSnapshotSerializer: import('pretty-format').Plugin;
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
}
|
package/dist/cli-entry.js
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
var _a;
|
|
2
|
-
import minimist from 'minimist';
|
|
3
|
-
import c from 'picocolors';
|
|
4
|
-
import { run } from './run';
|
|
5
|
-
const { log } = console;
|
|
6
|
-
const argv = minimist(process.argv.slice(2), {
|
|
7
|
-
alias: {
|
|
8
|
-
u: 'update',
|
|
9
|
-
},
|
|
10
|
-
string: ['root', 'config'],
|
|
11
|
-
boolean: ['update', 'dev', 'global'],
|
|
12
|
-
unknown(name) {
|
|
13
|
-
if (name[0] === '-') {
|
|
14
|
-
console.error(c.red(`Unknown argument: ${name}`));
|
|
15
|
-
help();
|
|
16
|
-
process.exit(1);
|
|
17
|
-
}
|
|
18
|
-
return true;
|
|
19
|
-
},
|
|
20
|
-
});
|
|
21
|
-
// @ts-expect-error
|
|
22
|
-
const server = (_a = process === null || process === void 0 ? void 0 : process.__vite_node__) === null || _a === void 0 ? void 0 : _a.server;
|
|
23
|
-
const viteConfig = (server === null || server === void 0 ? void 0 : server.config) || {};
|
|
24
|
-
const testOptions = viteConfig.test || {};
|
|
25
|
-
await run(Object.assign(Object.assign({}, testOptions), { server, global: argv.global, updateSnapshot: argv.update, rootDir: argv.root || process.cwd(), nameFilters: argv._ }));
|
|
26
|
-
function help() {
|
|
27
|
-
log('Help: finish help');
|
|
28
|
-
}
|
package/dist/hooks.d.ts
DELETED
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import { File, Suite, Task } from './types';
|
|
2
|
-
export declare const beforeAllHook: {
|
|
3
|
-
on(fn: (...args: any[]) => void | Promise<void>): void;
|
|
4
|
-
fire(...args: any[]): Promise<void>;
|
|
5
|
-
clear(): void;
|
|
6
|
-
};
|
|
7
|
-
export declare const afterAllHook: {
|
|
8
|
-
on(fn: (...args: any[]) => void | Promise<void>): void;
|
|
9
|
-
fire(...args: any[]): Promise<void>;
|
|
10
|
-
clear(): void;
|
|
11
|
-
};
|
|
12
|
-
export declare const beforeEachHook: {
|
|
13
|
-
on(fn: (args_0: Task) => void | Promise<void>): void;
|
|
14
|
-
fire(args_0: Task): Promise<void>;
|
|
15
|
-
clear(): void;
|
|
16
|
-
};
|
|
17
|
-
export declare const afterEachHook: {
|
|
18
|
-
on(fn: (args_0: Task) => void | Promise<void>): void;
|
|
19
|
-
fire(args_0: Task): Promise<void>;
|
|
20
|
-
clear(): void;
|
|
21
|
-
};
|
|
22
|
-
export declare const beforeFileHook: {
|
|
23
|
-
on(fn: (args_0: File) => void | Promise<void>): void;
|
|
24
|
-
fire(args_0: File): Promise<void>;
|
|
25
|
-
clear(): void;
|
|
26
|
-
};
|
|
27
|
-
export declare const afterFileHook: {
|
|
28
|
-
on(fn: (args_0: File) => void | Promise<void>): void;
|
|
29
|
-
fire(args_0: File): Promise<void>;
|
|
30
|
-
clear(): void;
|
|
31
|
-
};
|
|
32
|
-
export declare const beforeSuiteHook: {
|
|
33
|
-
on(fn: (args_0: Suite) => void | Promise<void>): void;
|
|
34
|
-
fire(args_0: Suite): Promise<void>;
|
|
35
|
-
clear(): void;
|
|
36
|
-
};
|
|
37
|
-
export declare const afterSuiteHook: {
|
|
38
|
-
on(fn: (args_0: Suite) => void | Promise<void>): void;
|
|
39
|
-
fire(args_0: Suite): Promise<void>;
|
|
40
|
-
clear(): void;
|
|
41
|
-
};
|
|
42
|
-
export declare const beforeAll: (fn: (...args: any[]) => void | Promise<void>) => void;
|
|
43
|
-
export declare const afterAll: (fn: (...args: any[]) => void | Promise<void>) => void;
|
|
44
|
-
export declare const beforeEach: (fn: (args_0: Task) => void | Promise<void>) => void;
|
|
45
|
-
export declare const afterEach: (fn: (args_0: Task) => void | Promise<void>) => void;
|
|
46
|
-
export declare const beforeFile: (fn: (args_0: File) => void | Promise<void>) => void;
|
|
47
|
-
export declare const afterFile: (fn: (args_0: File) => void | Promise<void>) => void;
|
|
48
|
-
export declare const beforeSuite: (fn: (args_0: Suite) => void | Promise<void>) => void;
|
|
49
|
-
export declare const afterSuite: (fn: (args_0: Suite) => void | Promise<void>) => void;
|
package/dist/hooks.js
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { createHook } from './utils/hook';
|
|
2
|
-
export const beforeAllHook = createHook();
|
|
3
|
-
export const afterAllHook = createHook();
|
|
4
|
-
export const beforeEachHook = createHook();
|
|
5
|
-
export const afterEachHook = createHook();
|
|
6
|
-
export const beforeFileHook = createHook();
|
|
7
|
-
export const afterFileHook = createHook();
|
|
8
|
-
export const beforeSuiteHook = createHook();
|
|
9
|
-
export const afterSuiteHook = createHook();
|
|
10
|
-
export const beforeAll = beforeAllHook.on;
|
|
11
|
-
export const afterAll = afterAllHook.on;
|
|
12
|
-
export const beforeEach = beforeEachHook.on;
|
|
13
|
-
export const afterEach = afterEachHook.on;
|
|
14
|
-
export const beforeFile = beforeFileHook.on;
|
|
15
|
-
export const afterFile = afterFileHook.on;
|
|
16
|
-
export const beforeSuite = beforeSuiteHook.on;
|
|
17
|
-
export const afterSuite = afterSuiteHook.on;
|
package/dist/snapshot/index.d.ts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { use as chaiUse } from 'chai';
|
|
2
|
-
declare type FirstFunctionArgument<T> = T extends (arg: infer A) => unknown ? A : never;
|
|
3
|
-
declare type ChaiPlugin = FirstFunctionArgument<typeof chaiUse>;
|
|
4
|
-
export interface SnapshotOptions {
|
|
5
|
-
rootDir: string;
|
|
6
|
-
update?: boolean;
|
|
7
|
-
}
|
|
8
|
-
export declare function SnapshotPlugin(options: SnapshotOptions): Promise<ChaiPlugin>;
|
|
9
|
-
export {};
|