vitest 0.0.35 → 0.0.36
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/dist/chunk-4OVO6RD6.js +1 -0
- package/dist/chunk-CUG6SVUZ.js +1 -0
- package/dist/chunk-F27UALKJ.js +1 -0
- package/dist/chunk-XPSQDVUG.js +1 -0
- package/dist/global-CKRMAXWF.js +1 -0
- package/dist/happy-dom-RNJZR3YC.js +1 -0
- package/dist/index.d.ts +73 -6
- package/dist/index.js +1 -4
- package/dist/jsdom-6QAZGE6T.js +1 -0
- package/dist/node/cli.d.ts +5 -1
- package/dist/node/cli.js +8 -86
- package/dist/node/entry.d.ts +1 -1
- package/dist/node/entry.js +19 -12
- package/dist/{types.d.ts → types-d3253f2d.d.ts} +69 -18
- package/package.json +8 -4
- package/dist/constants.d.ts +0 -4
- package/dist/constants.js +0 -24
- package/dist/context.d.ts +0 -2
- package/dist/context.js +0 -4
- package/dist/integrations/chai/index.d.ts +0 -3
- package/dist/integrations/chai/index.js +0 -3
- package/dist/integrations/chai/jest-expect.d.ts +0 -2
- package/dist/integrations/chai/jest-expect.js +0 -67
- package/dist/integrations/chai/setup.d.ts +0 -2
- package/dist/integrations/chai/setup.js +0 -11
- package/dist/integrations/chai/snapshot/index.d.ts +0 -8
- package/dist/integrations/chai/snapshot/index.js +0 -27
- package/dist/integrations/chai/snapshot/manager.d.ts +0 -30
- package/dist/integrations/chai/snapshot/manager.js +0 -77
- package/dist/integrations/chai/snapshot/utils/jest-config-helper.d.ts +0 -3
- package/dist/integrations/chai/snapshot/utils/jest-config-helper.js +0 -39
- package/dist/integrations/chai/snapshot/utils/jest-reporters-lite.d.ts +0 -2
- package/dist/integrations/chai/snapshot/utils/jest-reporters-lite.js +0 -71
- package/dist/integrations/chai/snapshot/utils/jest-test-result-helper.d.ts +0 -6
- package/dist/integrations/chai/snapshot/utils/jest-test-result-helper.js +0 -66
- package/dist/integrations/chai/snapshot/utils/types.d.ts +0 -29
- package/dist/integrations/chai/snapshot/utils/types.js +0 -1
- package/dist/integrations/chai/types.d.ts +0 -3
- package/dist/integrations/chai/types.js +0 -1
- package/dist/integrations/dom/happy-dom.d.ts +0 -5
- package/dist/integrations/dom/happy-dom.js +0 -18
- package/dist/integrations/dom/jsdom.d.ts +0 -5
- package/dist/integrations/dom/jsdom.js +0 -21
- package/dist/integrations/dom/keys.d.ts +0 -1
- package/dist/integrations/dom/keys.js +0 -220
- package/dist/integrations/global.d.ts +0 -1
- package/dist/integrations/global.js +0 -8
- package/dist/integrations/sinon.d.ts +0 -3
- package/dist/integrations/sinon.js +0 -5
- package/dist/node/node.d.ts +0 -27
- package/dist/node/node.js +0 -167
- package/dist/reporters/default.d.ts +0 -24
- package/dist/reporters/default.js +0 -149
- package/dist/reporters/error.d.ts +0 -9
- package/dist/reporters/error.js +0 -183
- package/dist/run/index.d.ts +0 -8
- package/dist/run/index.js +0 -271
- package/dist/suite.d.ts +0 -56
- package/dist/suite.js +0 -142
- package/dist/types.js +0 -1
- package/dist/utils/hook.d.ts +0 -5
- package/dist/utils/hook.js +0 -14
package/dist/reporters/error.js
DELETED
|
@@ -1,183 +0,0 @@
|
|
|
1
|
-
/* eslint-disable no-console */
|
|
2
|
-
import { promises as fs, existsSync } from 'fs';
|
|
3
|
-
import c from 'picocolors';
|
|
4
|
-
import * as diff from 'diff';
|
|
5
|
-
import { notNullish } from '@antfu/utils';
|
|
6
|
-
import { SourceMapConsumer } from 'source-map';
|
|
7
|
-
export async function printError(error) {
|
|
8
|
-
var _a;
|
|
9
|
-
if (!(error instanceof Error)) {
|
|
10
|
-
console.error(error);
|
|
11
|
-
return;
|
|
12
|
-
}
|
|
13
|
-
const { moduleCache } = process.__vite_node__;
|
|
14
|
-
const e = error;
|
|
15
|
-
let codeFramePrinted = false;
|
|
16
|
-
const stacks = parseStack(e.stack || '');
|
|
17
|
-
const nearest = stacks.find(stack => moduleCache.has(stack.file));
|
|
18
|
-
if (nearest) {
|
|
19
|
-
const transformResult = (_a = moduleCache.get(nearest.file)) === null || _a === void 0 ? void 0 : _a.transformResult;
|
|
20
|
-
const pos = await getOriginalPos(transformResult === null || transformResult === void 0 ? void 0 : transformResult.map, nearest);
|
|
21
|
-
if (pos && existsSync(nearest.file)) {
|
|
22
|
-
const sourceCode = await fs.readFile(nearest.file, 'utf-8');
|
|
23
|
-
console.error(`${c.red(`${c.bold(e.name)}: ${e.message}`)}`);
|
|
24
|
-
console.log(c.gray(`${nearest.file}:${pos.line}:${pos.column}`));
|
|
25
|
-
console.log(c.yellow(generateCodeFrame(sourceCode, pos)));
|
|
26
|
-
codeFramePrinted = true;
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
if (!codeFramePrinted)
|
|
30
|
-
console.error(e);
|
|
31
|
-
if (e.showDiff)
|
|
32
|
-
console.error(c.gray(generateDiff(stringify(e.actual), stringify(e.expected))));
|
|
33
|
-
}
|
|
34
|
-
function getOriginalPos(map, { line, column }) {
|
|
35
|
-
return new Promise((resolve) => {
|
|
36
|
-
if (!map)
|
|
37
|
-
return resolve(null);
|
|
38
|
-
SourceMapConsumer.with(map, null, (consumer) => {
|
|
39
|
-
const pos = consumer.originalPositionFor({ line, column });
|
|
40
|
-
if (pos.line != null && pos.column != null)
|
|
41
|
-
resolve(pos);
|
|
42
|
-
else
|
|
43
|
-
resolve(null);
|
|
44
|
-
});
|
|
45
|
-
});
|
|
46
|
-
}
|
|
47
|
-
const splitRE = /\r?\n/;
|
|
48
|
-
export function posToNumber(source, pos) {
|
|
49
|
-
if (typeof pos === 'number')
|
|
50
|
-
return pos;
|
|
51
|
-
const lines = source.split(splitRE);
|
|
52
|
-
const { line, column } = pos;
|
|
53
|
-
let start = 0;
|
|
54
|
-
for (let i = 0; i < line - 1; i++)
|
|
55
|
-
start += lines[i].length + 1;
|
|
56
|
-
return start + column;
|
|
57
|
-
}
|
|
58
|
-
export function numberToPos(source, offset) {
|
|
59
|
-
if (typeof offset !== 'number')
|
|
60
|
-
return offset;
|
|
61
|
-
if (offset > source.length) {
|
|
62
|
-
throw new Error(`offset is longer than source length! offset ${offset} > length ${source.length}`);
|
|
63
|
-
}
|
|
64
|
-
const lines = source.split(splitRE);
|
|
65
|
-
let counted = 0;
|
|
66
|
-
let line = 0;
|
|
67
|
-
let column = 0;
|
|
68
|
-
for (; line < lines.length; line++) {
|
|
69
|
-
const lineLength = lines[line].length + 1;
|
|
70
|
-
if (counted + lineLength >= offset) {
|
|
71
|
-
column = offset - counted + 1;
|
|
72
|
-
break;
|
|
73
|
-
}
|
|
74
|
-
counted += lineLength;
|
|
75
|
-
}
|
|
76
|
-
return { line: line + 1, column };
|
|
77
|
-
}
|
|
78
|
-
export function generateCodeFrame(source, start = 0, end, range = 2) {
|
|
79
|
-
start = posToNumber(source, start);
|
|
80
|
-
end = end || start;
|
|
81
|
-
const lines = source.split(splitRE);
|
|
82
|
-
let count = 0;
|
|
83
|
-
const res = [];
|
|
84
|
-
for (let i = 0; i < lines.length; i++) {
|
|
85
|
-
count += lines[i].length + 1;
|
|
86
|
-
if (count >= start) {
|
|
87
|
-
for (let j = i - range; j <= i + range || end > count; j++) {
|
|
88
|
-
if (j < 0 || j >= lines.length)
|
|
89
|
-
continue;
|
|
90
|
-
const line = j + 1;
|
|
91
|
-
res.push(`${c.gray(`${line}${' '.repeat(Math.max(3 - String(line).length, 0))}|`)} ${lines[j]}`);
|
|
92
|
-
const lineLength = lines[j].length;
|
|
93
|
-
if (j === i) {
|
|
94
|
-
// push underline
|
|
95
|
-
const pad = start - (count - lineLength) + 1;
|
|
96
|
-
const length = Math.max(1, end > count ? lineLength - pad : end - start);
|
|
97
|
-
res.push(`${c.gray(' |')} ${' '.repeat(pad)}${'^'.repeat(length)}`);
|
|
98
|
-
}
|
|
99
|
-
else if (j > i) {
|
|
100
|
-
if (end > count) {
|
|
101
|
-
const length = Math.max(Math.min(end - count, lineLength), 1);
|
|
102
|
-
res.push(`${c.gray(' |')} ${'^'.repeat(length)}`);
|
|
103
|
-
}
|
|
104
|
-
count += lineLength + 1;
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
break;
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
return res.join('\n');
|
|
111
|
-
}
|
|
112
|
-
function stringify(obj) {
|
|
113
|
-
// TODO: handle more types
|
|
114
|
-
return String(obj);
|
|
115
|
-
}
|
|
116
|
-
const stackFnCallRE = /at (.*) \((.+):(\d+):(\d+)\)$/;
|
|
117
|
-
const stackBarePathRE = /at ()(.+):(\d+):(\d+)$/;
|
|
118
|
-
function parseStack(stack) {
|
|
119
|
-
const lines = stack.split('\n');
|
|
120
|
-
const stackFrames = lines.map((raw) => {
|
|
121
|
-
const line = raw.trim();
|
|
122
|
-
const match = line.match(stackFnCallRE) || line.match(stackBarePathRE);
|
|
123
|
-
if (!match)
|
|
124
|
-
return null;
|
|
125
|
-
let file = match[2];
|
|
126
|
-
if (file.startsWith('file://'))
|
|
127
|
-
file = file.slice(7);
|
|
128
|
-
return {
|
|
129
|
-
method: match[1],
|
|
130
|
-
file: match[2],
|
|
131
|
-
line: parseInt(match[3]),
|
|
132
|
-
column: parseInt(match[4]),
|
|
133
|
-
};
|
|
134
|
-
});
|
|
135
|
-
return stackFrames.filter(notNullish);
|
|
136
|
-
}
|
|
137
|
-
/**
|
|
138
|
-
* Returns a diff between 2 strings with coloured ANSI output.
|
|
139
|
-
*
|
|
140
|
-
* @description
|
|
141
|
-
* The diff will be either inline or unified dependent on the value
|
|
142
|
-
* of `Base.inlineDiff`.
|
|
143
|
-
*
|
|
144
|
-
* @param {string} actual
|
|
145
|
-
* @param {string} expected
|
|
146
|
-
* @return {string} Diff
|
|
147
|
-
*/
|
|
148
|
-
function generateDiff(actual, expected) {
|
|
149
|
-
const diffSize = 2048;
|
|
150
|
-
if (actual.length > diffSize)
|
|
151
|
-
actual = `${actual.substring(0, diffSize)} ... Lines skipped`;
|
|
152
|
-
if (expected.length > diffSize)
|
|
153
|
-
expected = `${expected.substring(0, diffSize)} ... Lines skipped`;
|
|
154
|
-
return unifiedDiff(actual, expected);
|
|
155
|
-
}
|
|
156
|
-
/**
|
|
157
|
-
* Returns unified diff between two strings with coloured ANSI output.
|
|
158
|
-
*
|
|
159
|
-
* @private
|
|
160
|
-
* @param {String} actual
|
|
161
|
-
* @param {String} expected
|
|
162
|
-
* @return {string} The diff.
|
|
163
|
-
*/
|
|
164
|
-
function unifiedDiff(actual, expected) {
|
|
165
|
-
const indent = ' ';
|
|
166
|
-
function cleanUp(line) {
|
|
167
|
-
if (line[0] === '+')
|
|
168
|
-
return indent + c.green(`${line[0]} ${line.slice(1)}`);
|
|
169
|
-
if (line[0] === '-')
|
|
170
|
-
return indent + c.red(`${line[0]} ${line.slice(1)}`);
|
|
171
|
-
if (line.match(/@@/))
|
|
172
|
-
return '--';
|
|
173
|
-
if (line.match(/\\ No newline/))
|
|
174
|
-
return null;
|
|
175
|
-
return indent + line;
|
|
176
|
-
}
|
|
177
|
-
const msg = diff.createPatch('string', actual, expected);
|
|
178
|
-
const lines = msg.split('\n').splice(5);
|
|
179
|
-
return (`\n${indent}${c.red('- actual')}\n${indent}${c.green('+ expected')}\n\n${lines.map(cleanUp).filter(notBlank).join('\n')}`);
|
|
180
|
-
}
|
|
181
|
-
function notBlank(line) {
|
|
182
|
-
return typeof line !== 'undefined' && line !== null;
|
|
183
|
-
}
|
package/dist/run/index.d.ts
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { File, ResolvedConfig, Task, RunnerContext, Suite } from '../types';
|
|
2
|
-
export declare function runTask(task: Task, ctx: RunnerContext): Promise<void>;
|
|
3
|
-
export declare function collectFiles(paths: string[]): Promise<Record<string, File>>;
|
|
4
|
-
export declare function runSuite(suite: Suite, ctx: RunnerContext): Promise<void>;
|
|
5
|
-
export declare function runFile(file: File, ctx: RunnerContext): Promise<void>;
|
|
6
|
-
export declare function runFiles(filesMap: Record<string, File>, ctx: RunnerContext): Promise<void>;
|
|
7
|
-
export declare function run(config: ResolvedConfig): Promise<void>;
|
|
8
|
-
export declare function startWatcher(ctx: RunnerContext): Promise<void>;
|
package/dist/run/index.js
DELETED
|
@@ -1,271 +0,0 @@
|
|
|
1
|
-
import fg from 'fast-glob';
|
|
2
|
-
import { slash } from '@antfu/utils';
|
|
3
|
-
import { setupChai } from '../integrations/chai/setup';
|
|
4
|
-
import { clearContext, defaultSuite } from '../suite';
|
|
5
|
-
import { context } from '../context';
|
|
6
|
-
import { DefaultReporter } from '../reporters/default';
|
|
7
|
-
import { defaultIncludes, defaultExcludes } from '../constants';
|
|
8
|
-
import { getSnapshotManager } from '../integrations/chai/snapshot';
|
|
9
|
-
async function callHook(suite, name, args) {
|
|
10
|
-
await Promise.all(suite.hooks[name].map(fn => fn(...args)));
|
|
11
|
-
}
|
|
12
|
-
export async function runTask(task, ctx) {
|
|
13
|
-
var _a, _b, _c;
|
|
14
|
-
const { reporter } = ctx;
|
|
15
|
-
(_a = getSnapshotManager()) === null || _a === void 0 ? void 0 : _a.setTask(task);
|
|
16
|
-
await ((_b = reporter.onTaskBegin) === null || _b === void 0 ? void 0 : _b.call(reporter, task, ctx));
|
|
17
|
-
if (task.mode === 'run') {
|
|
18
|
-
try {
|
|
19
|
-
await callHook(task.suite, 'beforeEach', [task, task.suite]);
|
|
20
|
-
await task.fn();
|
|
21
|
-
task.state = 'pass';
|
|
22
|
-
}
|
|
23
|
-
catch (e) {
|
|
24
|
-
task.state = 'fail';
|
|
25
|
-
task.error = e;
|
|
26
|
-
process.exitCode = 1;
|
|
27
|
-
}
|
|
28
|
-
try {
|
|
29
|
-
await callHook(task.suite, 'afterEach', [task, task.suite]);
|
|
30
|
-
}
|
|
31
|
-
catch (e) {
|
|
32
|
-
task.state = 'fail';
|
|
33
|
-
task.error = e;
|
|
34
|
-
process.exitCode = 1;
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
await ((_c = reporter.onTaskEnd) === null || _c === void 0 ? void 0 : _c.call(reporter, task, ctx));
|
|
38
|
-
}
|
|
39
|
-
export async function collectFiles(paths) {
|
|
40
|
-
const files = {};
|
|
41
|
-
for (const filepath of paths) {
|
|
42
|
-
const file = {
|
|
43
|
-
filepath,
|
|
44
|
-
suites: [],
|
|
45
|
-
collected: false,
|
|
46
|
-
};
|
|
47
|
-
clearContext();
|
|
48
|
-
try {
|
|
49
|
-
await import(filepath);
|
|
50
|
-
const collectors = [defaultSuite, ...context.suites];
|
|
51
|
-
for (const c of collectors) {
|
|
52
|
-
context.currentSuite = c;
|
|
53
|
-
file.suites.push(await c.collect(file));
|
|
54
|
-
}
|
|
55
|
-
file.collected = true;
|
|
56
|
-
}
|
|
57
|
-
catch (e) {
|
|
58
|
-
file.error = e;
|
|
59
|
-
file.collected = false;
|
|
60
|
-
process.exitCode = 1;
|
|
61
|
-
}
|
|
62
|
-
files[filepath] = file;
|
|
63
|
-
}
|
|
64
|
-
const allFiles = Object.values(files);
|
|
65
|
-
const allSuites = allFiles.reduce((suites, file) => suites.concat(file.suites), []);
|
|
66
|
-
interpretOnlyMode(allSuites);
|
|
67
|
-
allSuites.forEach((i) => {
|
|
68
|
-
if (i.mode === 'skip')
|
|
69
|
-
i.tasks.forEach(t => t.mode === 'run' && (t.mode = 'skip'));
|
|
70
|
-
else
|
|
71
|
-
interpretOnlyMode(i.tasks);
|
|
72
|
-
i.tasks.forEach(t => t.mode === 'skip' && (t.state = 'skip'));
|
|
73
|
-
});
|
|
74
|
-
return files;
|
|
75
|
-
}
|
|
76
|
-
/**
|
|
77
|
-
* If any items been marked as `only`, mark all other items as `skip`.
|
|
78
|
-
*/
|
|
79
|
-
function interpretOnlyMode(items) {
|
|
80
|
-
if (items.some(i => i.mode === 'only')) {
|
|
81
|
-
items.forEach((i) => {
|
|
82
|
-
if (i.mode === 'run')
|
|
83
|
-
i.mode = 'skip';
|
|
84
|
-
else if (i.mode === 'only')
|
|
85
|
-
i.mode = 'run';
|
|
86
|
-
});
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
export async function runSuite(suite, ctx) {
|
|
90
|
-
var _a, _b;
|
|
91
|
-
const { reporter } = ctx;
|
|
92
|
-
await ((_a = reporter.onSuiteBegin) === null || _a === void 0 ? void 0 : _a.call(reporter, suite, ctx));
|
|
93
|
-
if (suite.mode === 'skip') {
|
|
94
|
-
suite.status = 'skip';
|
|
95
|
-
}
|
|
96
|
-
else if (suite.mode === 'todo') {
|
|
97
|
-
suite.status = 'todo';
|
|
98
|
-
}
|
|
99
|
-
else {
|
|
100
|
-
try {
|
|
101
|
-
await callHook(suite, 'beforeAll', [suite]);
|
|
102
|
-
for (const taskGroup of partitionTasks(suite.tasks)) {
|
|
103
|
-
if (taskGroup[0].concurrent) {
|
|
104
|
-
await Promise.all(taskGroup.map(t => runTask(t, ctx)));
|
|
105
|
-
}
|
|
106
|
-
else {
|
|
107
|
-
for (const t of taskGroup)
|
|
108
|
-
await runTask(t, ctx);
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
await callHook(suite, 'afterAll', [suite]);
|
|
112
|
-
}
|
|
113
|
-
catch (e) {
|
|
114
|
-
suite.error = e;
|
|
115
|
-
suite.status = 'fail';
|
|
116
|
-
process.exitCode = 1;
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
await ((_b = reporter.onSuiteEnd) === null || _b === void 0 ? void 0 : _b.call(reporter, suite, ctx));
|
|
120
|
-
}
|
|
121
|
-
/**
|
|
122
|
-
* Partition consecutive serial and concurrent tasks in groups
|
|
123
|
-
*/
|
|
124
|
-
function partitionTasks(tasks) {
|
|
125
|
-
let taskGroup = [];
|
|
126
|
-
const groupedTasks = [];
|
|
127
|
-
for (const task of tasks) {
|
|
128
|
-
if (taskGroup.length === 0 || !!task.concurrent === !!taskGroup[0].concurrent) {
|
|
129
|
-
taskGroup.push(task);
|
|
130
|
-
}
|
|
131
|
-
else {
|
|
132
|
-
groupedTasks.push(taskGroup);
|
|
133
|
-
taskGroup = [task];
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
if (taskGroup.length > 0)
|
|
137
|
-
groupedTasks.push(taskGroup);
|
|
138
|
-
return groupedTasks;
|
|
139
|
-
}
|
|
140
|
-
export async function runFile(file, ctx) {
|
|
141
|
-
var _a, _b;
|
|
142
|
-
const { reporter } = ctx;
|
|
143
|
-
const runnableSuites = file.suites.filter(i => i.mode === 'run');
|
|
144
|
-
if (runnableSuites.length === 0)
|
|
145
|
-
return;
|
|
146
|
-
await ((_a = reporter.onFileBegin) === null || _a === void 0 ? void 0 : _a.call(reporter, file, ctx));
|
|
147
|
-
if (ctx.config.parallel) {
|
|
148
|
-
await Promise.all(file.suites.map(suite => runSuite(suite, ctx)));
|
|
149
|
-
}
|
|
150
|
-
else {
|
|
151
|
-
for (const suite of file.suites)
|
|
152
|
-
await runSuite(suite, ctx);
|
|
153
|
-
}
|
|
154
|
-
await ((_b = reporter.onFileEnd) === null || _b === void 0 ? void 0 : _b.call(reporter, file, ctx));
|
|
155
|
-
}
|
|
156
|
-
export async function runFiles(filesMap, ctx) {
|
|
157
|
-
var _a;
|
|
158
|
-
const { reporter } = ctx;
|
|
159
|
-
await ((_a = reporter.onCollected) === null || _a === void 0 ? void 0 : _a.call(reporter, Object.values(filesMap), ctx));
|
|
160
|
-
for (const file of Object.values(filesMap))
|
|
161
|
-
await runFile(file, ctx);
|
|
162
|
-
}
|
|
163
|
-
export async function run(config) {
|
|
164
|
-
var _a, _b, _c;
|
|
165
|
-
config.reporter = config.reporter || new DefaultReporter();
|
|
166
|
-
const { reporter } = config;
|
|
167
|
-
// if watch, tell `vite-node` not to end the process
|
|
168
|
-
if (config.watch)
|
|
169
|
-
process.__vite_node__.watch = true;
|
|
170
|
-
// setup chai
|
|
171
|
-
await setupChai(config);
|
|
172
|
-
// collect files
|
|
173
|
-
let testFilepaths = await fg(config.includes || defaultIncludes, {
|
|
174
|
-
absolute: true,
|
|
175
|
-
cwd: config.root,
|
|
176
|
-
ignore: config.excludes || defaultExcludes,
|
|
177
|
-
});
|
|
178
|
-
// if name filters are provided by the CLI
|
|
179
|
-
if ((_a = config.filters) === null || _a === void 0 ? void 0 : _a.length)
|
|
180
|
-
testFilepaths = testFilepaths.filter(i => config.filters.some(f => i.includes(f)));
|
|
181
|
-
if (!testFilepaths.length) {
|
|
182
|
-
console.error('No test files found');
|
|
183
|
-
process.exitCode = 1;
|
|
184
|
-
return;
|
|
185
|
-
}
|
|
186
|
-
// setup envs
|
|
187
|
-
if (config.global)
|
|
188
|
-
(await import('../integrations/global')).registerApiGlobally();
|
|
189
|
-
if (config.dom === 'happy-dom')
|
|
190
|
-
(await import('../integrations/dom/happy-dom')).setupHappyDOM(globalThis);
|
|
191
|
-
else if (config.dom)
|
|
192
|
-
(await import('../integrations/dom/jsdom')).setupJSDOM(globalThis);
|
|
193
|
-
await ((_b = reporter.onStart) === null || _b === void 0 ? void 0 : _b.call(reporter, config));
|
|
194
|
-
const filesMap = await collectFiles(testFilepaths);
|
|
195
|
-
const snapshotManager = getSnapshotManager();
|
|
196
|
-
const ctx = {
|
|
197
|
-
filesMap,
|
|
198
|
-
get files() {
|
|
199
|
-
return Object.values(this.filesMap);
|
|
200
|
-
},
|
|
201
|
-
get suites() {
|
|
202
|
-
return Object.values(this.filesMap)
|
|
203
|
-
.reduce((suites, file) => suites.concat(file.suites), []);
|
|
204
|
-
},
|
|
205
|
-
get tasks() {
|
|
206
|
-
return this.suites
|
|
207
|
-
.reduce((tasks, suite) => tasks.concat(suite.tasks), []);
|
|
208
|
-
},
|
|
209
|
-
config,
|
|
210
|
-
reporter,
|
|
211
|
-
snapshotManager,
|
|
212
|
-
};
|
|
213
|
-
await runFiles(filesMap, ctx);
|
|
214
|
-
snapshotManager.saveSnap();
|
|
215
|
-
await ((_c = reporter.onFinished) === null || _c === void 0 ? void 0 : _c.call(reporter, ctx));
|
|
216
|
-
if (config.watch)
|
|
217
|
-
await startWatcher(ctx);
|
|
218
|
-
}
|
|
219
|
-
export async function startWatcher(ctx) {
|
|
220
|
-
var _a;
|
|
221
|
-
const { reporter, snapshotManager, filesMap } = ctx;
|
|
222
|
-
await ((_a = reporter.onWatcherStart) === null || _a === void 0 ? void 0 : _a.call(reporter, ctx));
|
|
223
|
-
let timer;
|
|
224
|
-
const changedTests = new Set();
|
|
225
|
-
const seen = new Set();
|
|
226
|
-
const { server, moduleCache } = process.__vite_node__;
|
|
227
|
-
server.watcher.on('change', async (id) => {
|
|
228
|
-
id = slash(id);
|
|
229
|
-
getDependencyTests(id, ctx, changedTests, seen);
|
|
230
|
-
seen.forEach(i => moduleCache.delete(i));
|
|
231
|
-
seen.clear();
|
|
232
|
-
if (changedTests.size === 0)
|
|
233
|
-
return;
|
|
234
|
-
clearTimeout(timer);
|
|
235
|
-
timer = setTimeout(async () => {
|
|
236
|
-
var _a, _b, _c;
|
|
237
|
-
if (changedTests.size === 0)
|
|
238
|
-
return;
|
|
239
|
-
snapshotManager.clear();
|
|
240
|
-
const paths = Array.from(changedTests);
|
|
241
|
-
changedTests.clear();
|
|
242
|
-
await ((_a = reporter.onWatcherRerun) === null || _a === void 0 ? void 0 : _a.call(reporter, paths, id, ctx));
|
|
243
|
-
paths.forEach(i => moduleCache.delete(i));
|
|
244
|
-
const newFilesMap = await collectFiles(paths);
|
|
245
|
-
Object.assign(filesMap, newFilesMap);
|
|
246
|
-
await runFiles(newFilesMap, ctx);
|
|
247
|
-
snapshotManager.saveSnap();
|
|
248
|
-
await ((_b = reporter.onFinished) === null || _b === void 0 ? void 0 : _b.call(reporter, ctx, Object.values(newFilesMap)));
|
|
249
|
-
await ((_c = reporter.onWatcherStart) === null || _c === void 0 ? void 0 : _c.call(reporter, ctx));
|
|
250
|
-
}, 100);
|
|
251
|
-
});
|
|
252
|
-
// add an empty promise so it never resolves
|
|
253
|
-
await new Promise(() => { });
|
|
254
|
-
}
|
|
255
|
-
function getDependencyTests(id, ctx, set = new Set(), seen = new Set()) {
|
|
256
|
-
if (seen.has(id) || set.has(id))
|
|
257
|
-
return set;
|
|
258
|
-
seen.add(id);
|
|
259
|
-
if (id in ctx.filesMap) {
|
|
260
|
-
set.add(id);
|
|
261
|
-
return set;
|
|
262
|
-
}
|
|
263
|
-
const mod = process.__vite_node__.server.moduleGraph.getModuleById(id);
|
|
264
|
-
if (mod) {
|
|
265
|
-
mod.importers.forEach((i) => {
|
|
266
|
-
if (i.id)
|
|
267
|
-
getDependencyTests(i.id, ctx, set, seen);
|
|
268
|
-
});
|
|
269
|
-
}
|
|
270
|
-
return set;
|
|
271
|
-
}
|
package/dist/suite.d.ts
DELETED
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
import { SuiteCollector, TestFactory, TestFunction, Suite } from './types';
|
|
2
|
-
export declare const defaultSuite: SuiteCollector;
|
|
3
|
-
export declare const test: {
|
|
4
|
-
(name: string, fn: TestFunction): void;
|
|
5
|
-
concurrent: {
|
|
6
|
-
(name: string, fn: TestFunction, timeout?: number | undefined): void;
|
|
7
|
-
skip(name: string, fn: TestFunction, timeout?: number | undefined): void;
|
|
8
|
-
only(name: string, fn: TestFunction, timeout?: number | undefined): void;
|
|
9
|
-
todo(name: string): void;
|
|
10
|
-
};
|
|
11
|
-
skip: {
|
|
12
|
-
(name: string, fn: TestFunction): void;
|
|
13
|
-
concurrent(name: string, fn: TestFunction, timeout?: number | undefined): void;
|
|
14
|
-
};
|
|
15
|
-
only: {
|
|
16
|
-
(name: string, fn: TestFunction): void;
|
|
17
|
-
concurrent(name: string, fn: TestFunction, timeout?: number | undefined): void;
|
|
18
|
-
};
|
|
19
|
-
todo: {
|
|
20
|
-
(name: string): void;
|
|
21
|
-
concurrent(name: string): void;
|
|
22
|
-
};
|
|
23
|
-
};
|
|
24
|
-
export declare function suite(suiteName: string, factory?: TestFactory): SuiteCollector;
|
|
25
|
-
export declare namespace suite {
|
|
26
|
-
var skip: (suiteName: string, factory?: TestFactory | undefined) => SuiteCollector;
|
|
27
|
-
var only: (suiteName: string, factory?: TestFactory | undefined) => SuiteCollector;
|
|
28
|
-
var todo: (suiteName: string) => SuiteCollector;
|
|
29
|
-
}
|
|
30
|
-
export declare const describe: typeof suite;
|
|
31
|
-
export declare const it: {
|
|
32
|
-
(name: string, fn: TestFunction): void;
|
|
33
|
-
concurrent: {
|
|
34
|
-
(name: string, fn: TestFunction, timeout?: number | undefined): void;
|
|
35
|
-
skip(name: string, fn: TestFunction, timeout?: number | undefined): void;
|
|
36
|
-
only(name: string, fn: TestFunction, timeout?: number | undefined): void;
|
|
37
|
-
todo(name: string): void;
|
|
38
|
-
};
|
|
39
|
-
skip: {
|
|
40
|
-
(name: string, fn: TestFunction): void;
|
|
41
|
-
concurrent(name: string, fn: TestFunction, timeout?: number | undefined): void;
|
|
42
|
-
};
|
|
43
|
-
only: {
|
|
44
|
-
(name: string, fn: TestFunction): void;
|
|
45
|
-
concurrent(name: string, fn: TestFunction, timeout?: number | undefined): void;
|
|
46
|
-
};
|
|
47
|
-
todo: {
|
|
48
|
-
(name: string): void;
|
|
49
|
-
concurrent(name: string): void;
|
|
50
|
-
};
|
|
51
|
-
};
|
|
52
|
-
export declare const beforeAll: (fn: Suite['hooks']['beforeAll'][0]) => void;
|
|
53
|
-
export declare const afterAll: (fn: Suite['hooks']['afterAll'][0]) => void;
|
|
54
|
-
export declare const beforeEach: (fn: Suite['hooks']['beforeEach'][0]) => void;
|
|
55
|
-
export declare const afterEach: (fn: Suite['hooks']['afterEach'][0]) => void;
|
|
56
|
-
export declare function clearContext(): void;
|
package/dist/suite.js
DELETED
|
@@ -1,142 +0,0 @@
|
|
|
1
|
-
import { context } from './context';
|
|
2
|
-
import { defaultConcurrentTimeout } from './constants';
|
|
3
|
-
export const defaultSuite = suite('');
|
|
4
|
-
function getCurrentSuite() {
|
|
5
|
-
return context.currentSuite || defaultSuite;
|
|
6
|
-
}
|
|
7
|
-
function createSuiteCollector(name, factory = () => { }, mode) {
|
|
8
|
-
const queue = [];
|
|
9
|
-
const factoryQueue = [];
|
|
10
|
-
const suiteBase = {
|
|
11
|
-
name,
|
|
12
|
-
mode,
|
|
13
|
-
hooks: {
|
|
14
|
-
beforeAll: [],
|
|
15
|
-
afterAll: [],
|
|
16
|
-
beforeEach: [],
|
|
17
|
-
afterEach: [],
|
|
18
|
-
},
|
|
19
|
-
};
|
|
20
|
-
const test = createTestCollector((name, fn, mode, concurrent) => {
|
|
21
|
-
queue.push({
|
|
22
|
-
name,
|
|
23
|
-
mode,
|
|
24
|
-
concurrent,
|
|
25
|
-
suite: {},
|
|
26
|
-
state: (mode !== 'run' && mode !== 'only') ? mode : undefined,
|
|
27
|
-
fn,
|
|
28
|
-
});
|
|
29
|
-
});
|
|
30
|
-
const collector = {
|
|
31
|
-
name,
|
|
32
|
-
mode,
|
|
33
|
-
test,
|
|
34
|
-
collect,
|
|
35
|
-
clear,
|
|
36
|
-
on: addHook,
|
|
37
|
-
};
|
|
38
|
-
function addHook(name, ...fn) {
|
|
39
|
-
suiteBase.hooks[name].push(...fn);
|
|
40
|
-
}
|
|
41
|
-
function clear() {
|
|
42
|
-
queue.length = 0;
|
|
43
|
-
factoryQueue.length = 0;
|
|
44
|
-
}
|
|
45
|
-
async function collect(file) {
|
|
46
|
-
factoryQueue.length = 0;
|
|
47
|
-
if (factory)
|
|
48
|
-
await factory(test);
|
|
49
|
-
const tasks = [...factoryQueue, ...queue];
|
|
50
|
-
const suite = Object.assign(Object.assign({}, suiteBase), { tasks,
|
|
51
|
-
file });
|
|
52
|
-
tasks.forEach((task) => {
|
|
53
|
-
task.suite = suite;
|
|
54
|
-
if (file)
|
|
55
|
-
task.file = file;
|
|
56
|
-
});
|
|
57
|
-
return suite;
|
|
58
|
-
}
|
|
59
|
-
context.currentSuite = collector;
|
|
60
|
-
context.suites.push(collector);
|
|
61
|
-
return collector;
|
|
62
|
-
}
|
|
63
|
-
function createConcurrentOptions(timeout) {
|
|
64
|
-
return { timeout: timeout !== null && timeout !== void 0 ? timeout : defaultConcurrentTimeout };
|
|
65
|
-
}
|
|
66
|
-
function createTestCollector(collectTask) {
|
|
67
|
-
function test(name, fn) {
|
|
68
|
-
collectTask(name, fn, 'run');
|
|
69
|
-
}
|
|
70
|
-
test.concurrent = concurrent;
|
|
71
|
-
test.skip = skip;
|
|
72
|
-
test.only = only;
|
|
73
|
-
test.todo = todo;
|
|
74
|
-
function concurrent(name, fn, timeout) {
|
|
75
|
-
collectTask(name, fn, 'run', createConcurrentOptions(timeout));
|
|
76
|
-
}
|
|
77
|
-
concurrent.skip = (name, fn, timeout) => collectTask(name, fn, 'skip', createConcurrentOptions(timeout));
|
|
78
|
-
concurrent.only = (name, fn, timeout) => collectTask(name, fn, 'only', createConcurrentOptions(timeout));
|
|
79
|
-
concurrent.todo = todo;
|
|
80
|
-
function skip(name, fn) {
|
|
81
|
-
collectTask(name, fn, 'skip');
|
|
82
|
-
}
|
|
83
|
-
skip.concurrent = concurrent.skip;
|
|
84
|
-
function only(name, fn) {
|
|
85
|
-
collectTask(name, fn, 'only');
|
|
86
|
-
}
|
|
87
|
-
only.concurrent = concurrent.only;
|
|
88
|
-
function todo(name) {
|
|
89
|
-
collectTask(name, () => { }, 'todo');
|
|
90
|
-
}
|
|
91
|
-
todo.concurrent = todo;
|
|
92
|
-
return test;
|
|
93
|
-
}
|
|
94
|
-
// apis
|
|
95
|
-
export const test = (function () {
|
|
96
|
-
function test(name, fn) {
|
|
97
|
-
return getCurrentSuite().test(name, fn);
|
|
98
|
-
}
|
|
99
|
-
function concurrent(name, fn, timeout) {
|
|
100
|
-
return getCurrentSuite().test.concurrent(name, fn, timeout);
|
|
101
|
-
}
|
|
102
|
-
concurrent.skip = (name, fn, timeout) => getCurrentSuite().test.concurrent.skip(name, fn, timeout);
|
|
103
|
-
concurrent.only = (name, fn, timeout) => getCurrentSuite().test.concurrent.only(name, fn, timeout);
|
|
104
|
-
concurrent.todo = (name) => getCurrentSuite().test.concurrent.todo(name);
|
|
105
|
-
function skip(name, fn) {
|
|
106
|
-
return getCurrentSuite().test.skip(name, fn);
|
|
107
|
-
}
|
|
108
|
-
skip.concurrent = (name, fn, timeout) => getCurrentSuite().test.skip.concurrent(name, fn, timeout);
|
|
109
|
-
function only(name, fn) {
|
|
110
|
-
return getCurrentSuite().test.only(name, fn);
|
|
111
|
-
}
|
|
112
|
-
only.concurrent = (name, fn, timeout) => getCurrentSuite().test.only.concurrent(name, fn, timeout);
|
|
113
|
-
function todo(name) {
|
|
114
|
-
return getCurrentSuite().test.todo(name);
|
|
115
|
-
}
|
|
116
|
-
todo.concurrent = (name) => getCurrentSuite().test.todo.concurrent(name);
|
|
117
|
-
test.concurrent = concurrent;
|
|
118
|
-
test.skip = skip;
|
|
119
|
-
test.only = only;
|
|
120
|
-
test.todo = todo;
|
|
121
|
-
return test;
|
|
122
|
-
})();
|
|
123
|
-
export function suite(suiteName, factory) {
|
|
124
|
-
return createSuiteCollector(suiteName, factory, 'run');
|
|
125
|
-
}
|
|
126
|
-
suite.skip = (suiteName, factory) => createSuiteCollector(suiteName, factory, 'skip');
|
|
127
|
-
suite.only = (suiteName, factory) => createSuiteCollector(suiteName, factory, 'only');
|
|
128
|
-
suite.todo = (suiteName) => createSuiteCollector(suiteName, undefined, 'todo');
|
|
129
|
-
// alias
|
|
130
|
-
export const describe = suite;
|
|
131
|
-
export const it = test;
|
|
132
|
-
// hooks
|
|
133
|
-
export const beforeAll = (fn) => getCurrentSuite().on('beforeAll', fn);
|
|
134
|
-
export const afterAll = (fn) => getCurrentSuite().on('afterAll', fn);
|
|
135
|
-
export const beforeEach = (fn) => getCurrentSuite().on('beforeEach', fn);
|
|
136
|
-
export const afterEach = (fn) => getCurrentSuite().on('afterEach', fn);
|
|
137
|
-
// utils
|
|
138
|
-
export function clearContext() {
|
|
139
|
-
context.suites.length = 0;
|
|
140
|
-
defaultSuite.clear();
|
|
141
|
-
context.currentSuite = defaultSuite;
|
|
142
|
-
}
|
package/dist/types.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/dist/utils/hook.d.ts
DELETED
package/dist/utils/hook.js
DELETED