vitest 0.0.14 → 0.0.15
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/{cli-entry.d.ts → entry.d.ts} +0 -0
- package/dist/entry.js +38 -0
- package/dist/index.d.ts +2 -4
- package/dist/index.js +2 -4
- package/dist/integrations/chai/index.d.ts +3 -0
- package/dist/integrations/chai/index.js +3 -0
- package/dist/{chai.d.ts → integrations/chai/jest-expect.d.ts} +2 -5
- package/dist/{chai.js → integrations/chai/jest-expect.js} +5 -14
- 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 +17 -0
- package/dist/{snapshot → integrations/chai/snapshot}/index.js +1 -1
- package/dist/{snapshot → integrations/chai/snapshot}/manager.d.ts +0 -0
- package/dist/{snapshot → integrations/chai/snapshot}/manager.js +0 -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 +3 -0
- package/dist/run.js +3 -1
- package/dist/types.d.ts +7 -1
- package/package.json +14 -10
- package/dist/cli-entry.js +0 -28
- 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
|
+
}
|
|
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,6 @@
|
|
|
1
|
-
import sinon from 'sinon';
|
|
2
1
|
export * from './types';
|
|
3
2
|
export * from './suite';
|
|
4
3
|
export * from './config';
|
|
5
|
-
export * from './chai';
|
|
4
|
+
export * from './integrations/chai';
|
|
5
|
+
export * from './integrations/sinon';
|
|
6
6
|
export { beforeAll, afterAll, beforeEach, afterEach, beforeFile, afterFile, beforeSuite, afterSuite } from './hooks';
|
|
7
|
-
export { sinon };
|
|
8
|
-
export declare const mock: sinon.SinonMockStatic, spy: sinon.SinonSpyStatic, stub: sinon.SinonStubStatic;
|
package/dist/index.js
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
import sinon from 'sinon';
|
|
2
1
|
export * from './types';
|
|
3
2
|
export * from './suite';
|
|
4
3
|
export * from './config';
|
|
5
|
-
export * from './chai';
|
|
4
|
+
export * from './integrations/chai';
|
|
5
|
+
export * from './integrations/sinon';
|
|
6
6
|
export { beforeAll, afterAll, beforeEach, afterEach, beforeFile, afterFile, beforeSuite, afterSuite } from './hooks';
|
|
7
|
-
export { sinon };
|
|
8
|
-
export const { mock, spy, stub } = sinon;
|
|
@@ -1,11 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export declare function
|
|
3
|
-
export { assert, should, expect } from 'chai';
|
|
1
|
+
import { ChaiPlugin } from './types';
|
|
2
|
+
export declare function JestChaiExpect(): ChaiPlugin;
|
|
4
3
|
declare global {
|
|
5
4
|
namespace Chai {
|
|
6
5
|
interface Assertion {
|
|
7
|
-
toMatchSnapshot(message?: string): Assertion;
|
|
8
|
-
matchSnapshot(message?: string): Assertion;
|
|
9
6
|
toEqual(expected: any): void;
|
|
10
7
|
toStrictEqual(expected: any): void;
|
|
11
8
|
toBe(expected: any): void;
|
|
@@ -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);
|
|
@@ -43,6 +35,5 @@ export async function setupChai(config) {
|
|
|
43
35
|
utils.addMethod(proto, 'toBeDefined', function () {
|
|
44
36
|
return this.not.be.undefined;
|
|
45
37
|
});
|
|
46
|
-
}
|
|
38
|
+
};
|
|
47
39
|
}
|
|
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,17 @@
|
|
|
1
|
+
import { ChaiPlugin } from '../types';
|
|
2
|
+
export interface SnapshotOptions {
|
|
3
|
+
rootDir: string;
|
|
4
|
+
update?: boolean;
|
|
5
|
+
}
|
|
6
|
+
export declare function SnapshotPlugin(options: SnapshotOptions): Promise<ChaiPlugin>;
|
|
7
|
+
declare global {
|
|
8
|
+
namespace Chai {
|
|
9
|
+
interface Assertion {
|
|
10
|
+
toMatchSnapshot(message?: string): Assertion;
|
|
11
|
+
matchSnapshot(message?: string): Assertion;
|
|
12
|
+
}
|
|
13
|
+
interface ExpectStatic {
|
|
14
|
+
addSnapshotSerializer: import('pretty-format').Plugin;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
}
|
|
File without changes
|
|
File without changes
|
|
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
|
+
}
|
package/dist/run.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
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
5
|
import { afterEachHook, afterFileHook, afterAllHook, afterSuiteHook, beforeEachHook, beforeFileHook, beforeAllHook, beforeSuiteHook } from './hooks';
|
|
@@ -111,6 +111,8 @@ export async function run(config) {
|
|
|
111
111
|
await ((_b = reporter.onStart) === null || _b === void 0 ? void 0 : _b.call(reporter, config));
|
|
112
112
|
if (config.global)
|
|
113
113
|
(await import('./global')).registerApiGlobally();
|
|
114
|
+
if (config.jsdom)
|
|
115
|
+
(await import('./integrations/jsdom')).setupJSDOM(globalThis);
|
|
114
116
|
const files = await collectFiles(paths);
|
|
115
117
|
const ctx = {
|
|
116
118
|
files,
|
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;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vitest",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.15",
|
|
4
4
|
"description": "",
|
|
5
5
|
"keywords": [],
|
|
6
6
|
"homepage": "https://github.com/antfu/vitest#readme",
|
|
@@ -33,6 +33,16 @@
|
|
|
33
33
|
"bin",
|
|
34
34
|
"*.d.ts"
|
|
35
35
|
],
|
|
36
|
+
"scripts": {
|
|
37
|
+
"prepare": "esmo scripts/generate-types.ts",
|
|
38
|
+
"build": "rimraf dist && tsc -p src/tsconfig.json",
|
|
39
|
+
"lint": "eslint \"{src,test}/**/*.ts\"",
|
|
40
|
+
"prepublishOnly": "nr build",
|
|
41
|
+
"release": "bumpp --commit --push --tag && pnpm publish",
|
|
42
|
+
"test": "node bin/vitest.mjs --dev",
|
|
43
|
+
"test:update": "nr test -u",
|
|
44
|
+
"watch": "tsc -p src/tsconfig.json --watch"
|
|
45
|
+
},
|
|
36
46
|
"dependencies": {
|
|
37
47
|
"@jest/test-result": "^27.4.2",
|
|
38
48
|
"@types/chai": "^4.2.22",
|
|
@@ -42,6 +52,7 @@
|
|
|
42
52
|
"find-up": "^6.2.0",
|
|
43
53
|
"jest-snapshot": "^27.4.2",
|
|
44
54
|
"jest-util": "^27.4.2",
|
|
55
|
+
"jsdom": "^19.0.0",
|
|
45
56
|
"minimist": "^1.2.5",
|
|
46
57
|
"ora": "^6.0.1",
|
|
47
58
|
"picocolors": "^1.0.0",
|
|
@@ -51,6 +62,7 @@
|
|
|
51
62
|
"devDependencies": {
|
|
52
63
|
"@antfu/eslint-config": "^0.11.1",
|
|
53
64
|
"@antfu/ni": "^0.11.0",
|
|
65
|
+
"@types/jsdom": "^16.2.13",
|
|
54
66
|
"@types/minimist": "^1.2.2",
|
|
55
67
|
"@types/node": "^16.11.11",
|
|
56
68
|
"@types/sinon": "^10.0.6",
|
|
@@ -60,13 +72,5 @@
|
|
|
60
72
|
"rimraf": "^3.0.2",
|
|
61
73
|
"typescript": "^4.5.2",
|
|
62
74
|
"vite": "^2.6.14"
|
|
63
|
-
},
|
|
64
|
-
"scripts": {
|
|
65
|
-
"build": "rimraf dist && tsc -p src/tsconfig.json",
|
|
66
|
-
"lint": "eslint \"{src,test}/**/*.ts\"",
|
|
67
|
-
"release": "bumpp --commit --push --tag && pnpm publish",
|
|
68
|
-
"test": "node bin/vitest.mjs --dev",
|
|
69
|
-
"test:update": "nr test -u",
|
|
70
|
-
"watch": "tsc -p src/tsconfig.json --watch"
|
|
71
75
|
}
|
|
72
|
-
}
|
|
76
|
+
}
|
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/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 {};
|