vitest 0.0.35 → 0.0.39
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.gh.md +32 -3
- package/dist/chunk-7SGHSD2B.js +1 -0
- package/dist/chunk-F27UALKJ.js +1 -0
- package/dist/chunk-SAR64N7W.js +1 -0
- package/dist/chunk-TUQVO6ML.js +1 -0
- package/dist/chunk-XPSQDVUG.js +1 -0
- package/dist/global-PFX5FMYU.js +1 -0
- package/dist/happy-dom-RNJZR3YC.js +1 -0
- package/dist/index.d.ts +108 -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 +7 -86
- package/dist/node/entry.d.ts +1 -1
- package/dist/node/entry.js +19 -12
- package/dist/{types.d.ts → types-91b8a38d.d.ts} +75 -26
- 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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vitest",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.39",
|
|
4
4
|
"description": "A blazing fast unit test framework powered by Vite",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"vite",
|
|
@@ -8,6 +8,9 @@
|
|
|
8
8
|
"test",
|
|
9
9
|
"jest"
|
|
10
10
|
],
|
|
11
|
+
"engines": {
|
|
12
|
+
"node": ">=16.0.0"
|
|
13
|
+
},
|
|
11
14
|
"homepage": "https://github.com/antfu/vitest#readme",
|
|
12
15
|
"bugs": {
|
|
13
16
|
"url": "https://github.com/antfu/vitest/issues"
|
|
@@ -40,7 +43,8 @@
|
|
|
40
43
|
],
|
|
41
44
|
"scripts": {
|
|
42
45
|
"prepare": "esmo scripts/generate-types.ts",
|
|
43
|
-
"build": "
|
|
46
|
+
"build": "tsup --dts --minify",
|
|
47
|
+
"dev": "tsup --watch src",
|
|
44
48
|
"lint": "eslint \"{src,test}/**/*.ts\"",
|
|
45
49
|
"prepublishOnly": "nr build",
|
|
46
50
|
"release": "bumpp --commit --push --tag && esmo scripts/publish.ts",
|
|
@@ -48,8 +52,7 @@
|
|
|
48
52
|
"test:core": "node bin/vitest.mjs --dev -r test/core",
|
|
49
53
|
"test:vue": "node bin/vitest.mjs --dev -r test/vue",
|
|
50
54
|
"test:react": "node bin/vitest.mjs --dev -r test/react",
|
|
51
|
-
"coverage": "node bin/vitest.mjs --dev -r test/core --coverage"
|
|
52
|
-
"watch": "tsc -p src/tsconfig.json --watch"
|
|
55
|
+
"coverage": "node bin/vitest.mjs --dev -r test/core --coverage"
|
|
53
56
|
},
|
|
54
57
|
"dependencies": {
|
|
55
58
|
"@antfu/utils": "^0.3.0",
|
|
@@ -91,6 +94,7 @@
|
|
|
91
94
|
"esno": "^0.12.1",
|
|
92
95
|
"npm-run-all": "^4.1.5",
|
|
93
96
|
"rimraf": "^3.0.2",
|
|
97
|
+
"tsup": "^5.10.3",
|
|
94
98
|
"typescript": "^4.5.2",
|
|
95
99
|
"vite": "^2.7.1"
|
|
96
100
|
}
|
package/dist/constants.d.ts
DELETED
package/dist/constants.js
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
export const defaultIncludes = ['**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}'];
|
|
2
|
-
export const defaultExcludes = ['**/node_modules/**', '**/dist/**'];
|
|
3
|
-
export const globalApis = [
|
|
4
|
-
// suite
|
|
5
|
-
'suite',
|
|
6
|
-
'test',
|
|
7
|
-
'describe',
|
|
8
|
-
'it',
|
|
9
|
-
// chai
|
|
10
|
-
'chai',
|
|
11
|
-
'expect',
|
|
12
|
-
'assert',
|
|
13
|
-
// sinon
|
|
14
|
-
'sinon',
|
|
15
|
-
'spy',
|
|
16
|
-
'mock',
|
|
17
|
-
'stub',
|
|
18
|
-
// hooks
|
|
19
|
-
'beforeAll',
|
|
20
|
-
'afterAll',
|
|
21
|
-
'beforeEach',
|
|
22
|
-
'afterEach',
|
|
23
|
-
];
|
|
24
|
-
export const defaultConcurrentTimeout = 5000;
|
package/dist/context.d.ts
DELETED
package/dist/context.js
DELETED
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
// Jest Expect Compact
|
|
2
|
-
// TODO: add more https://jestjs.io/docs/expect
|
|
3
|
-
export function JestChaiExpect() {
|
|
4
|
-
return (chai, utils) => {
|
|
5
|
-
const proto = chai.Assertion.prototype;
|
|
6
|
-
utils.addMethod(proto, 'toEqual', function (expected) {
|
|
7
|
-
return this.eql(expected);
|
|
8
|
-
});
|
|
9
|
-
utils.addMethod(proto, 'toStrictEqual', function (expected) {
|
|
10
|
-
return this.equal(expected);
|
|
11
|
-
});
|
|
12
|
-
utils.addMethod(proto, 'toBe', function (expected) {
|
|
13
|
-
return this.equal(expected);
|
|
14
|
-
});
|
|
15
|
-
utils.addMethod(proto, 'toMatchObject', function (expected) {
|
|
16
|
-
return this.containSubset(expected);
|
|
17
|
-
});
|
|
18
|
-
utils.addMethod(proto, 'toMatch', function (expected) {
|
|
19
|
-
if (typeof expected === 'string')
|
|
20
|
-
return this.include(expected);
|
|
21
|
-
else
|
|
22
|
-
return this.match(expected);
|
|
23
|
-
});
|
|
24
|
-
utils.addMethod(proto, 'toContain', function (item) {
|
|
25
|
-
return this.contain(item);
|
|
26
|
-
});
|
|
27
|
-
utils.addMethod(proto, 'toBeTruthy', function () {
|
|
28
|
-
const obj = utils.flag(this, 'object');
|
|
29
|
-
this.assert(Boolean(obj), 'expected #{this} to be truthy', 'expected #{this} to not be truthy', obj);
|
|
30
|
-
});
|
|
31
|
-
utils.addMethod(proto, 'toBeFalsy', function () {
|
|
32
|
-
const obj = utils.flag(this, 'object');
|
|
33
|
-
this.assert(!obj, 'expected #{this} to be falsy', 'expected #{this} to not be falsy', obj);
|
|
34
|
-
});
|
|
35
|
-
utils.addMethod(proto, 'toBeNaN', function () {
|
|
36
|
-
return this.be.NaN;
|
|
37
|
-
});
|
|
38
|
-
utils.addMethod(proto, 'toBeUndefined', function () {
|
|
39
|
-
return this.be.undefined;
|
|
40
|
-
});
|
|
41
|
-
utils.addMethod(proto, 'toBeNull', function () {
|
|
42
|
-
return this.be.null;
|
|
43
|
-
});
|
|
44
|
-
utils.addMethod(proto, 'toBeDefined', function () {
|
|
45
|
-
return this.not.be.undefined;
|
|
46
|
-
});
|
|
47
|
-
utils.addMethod(proto, 'toBeInstanceOf', function (obj) {
|
|
48
|
-
return this.instanceOf(obj);
|
|
49
|
-
});
|
|
50
|
-
// mock
|
|
51
|
-
utils.addMethod(proto, 'toHaveBeenCalledTimes', function (number) {
|
|
52
|
-
return this.callCount(number);
|
|
53
|
-
});
|
|
54
|
-
utils.addMethod(proto, 'toHaveBeenCalledOnce', function () {
|
|
55
|
-
return this.callCount(1);
|
|
56
|
-
});
|
|
57
|
-
utils.addMethod(proto, 'toHaveBeenCalled', function () {
|
|
58
|
-
return this.called;
|
|
59
|
-
});
|
|
60
|
-
utils.addMethod(proto, 'toHaveBeenCalled', function () {
|
|
61
|
-
return this.called;
|
|
62
|
-
});
|
|
63
|
-
utils.addMethod(proto, 'toHaveBeenCalledWith', function (...args) {
|
|
64
|
-
return this.calledWith(...args);
|
|
65
|
-
});
|
|
66
|
-
};
|
|
67
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import chai from 'chai';
|
|
2
|
-
import SinonChai from 'sinon-chai';
|
|
3
|
-
import Subset from 'chai-subset';
|
|
4
|
-
import { JestChaiExpect } from './jest-expect';
|
|
5
|
-
import { SnapshotPlugin } from './snapshot';
|
|
6
|
-
export async function setupChai(config) {
|
|
7
|
-
chai.use(SinonChai);
|
|
8
|
-
chai.use(JestChaiExpect());
|
|
9
|
-
chai.use(Subset);
|
|
10
|
-
chai.use(await SnapshotPlugin(config));
|
|
11
|
-
}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { ChaiPlugin } from '../types';
|
|
2
|
-
import { SnapshotManager } from './manager';
|
|
3
|
-
export interface SnapshotOptions {
|
|
4
|
-
root: string;
|
|
5
|
-
update?: boolean;
|
|
6
|
-
}
|
|
7
|
-
export declare function getSnapshotManager(): SnapshotManager;
|
|
8
|
-
export declare function SnapshotPlugin(options: SnapshotOptions): Promise<ChaiPlugin>;
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import Snap from 'jest-snapshot';
|
|
2
|
-
import { SnapshotManager } from './manager';
|
|
3
|
-
const { addSerializer } = Snap;
|
|
4
|
-
let _manager;
|
|
5
|
-
export function getSnapshotManager() {
|
|
6
|
-
return _manager;
|
|
7
|
-
}
|
|
8
|
-
export async function SnapshotPlugin(options) {
|
|
9
|
-
const { root: rootDir } = options;
|
|
10
|
-
_manager = new SnapshotManager({
|
|
11
|
-
rootDir,
|
|
12
|
-
update: options.update,
|
|
13
|
-
});
|
|
14
|
-
_manager.snapshotResolver = await Snap.buildSnapshotResolver({
|
|
15
|
-
transform: [],
|
|
16
|
-
rootDir,
|
|
17
|
-
});
|
|
18
|
-
return function (chai, utils) {
|
|
19
|
-
for (const key of ['matchSnapshot', 'toMatchSnapshot']) {
|
|
20
|
-
utils.addMethod(chai.Assertion.prototype, key, function (message) {
|
|
21
|
-
const expected = utils.flag(this, 'object');
|
|
22
|
-
_manager.assert(expected, message);
|
|
23
|
-
});
|
|
24
|
-
}
|
|
25
|
-
chai.expect.addSnapshotSerializer = addSerializer;
|
|
26
|
-
};
|
|
27
|
-
}
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import type { SnapshotStateType, SnapshotResolver } from 'jest-snapshot';
|
|
2
|
-
import type { SnapshotStateOptions } from 'jest-snapshot/build/State';
|
|
3
|
-
import { Task } from '../../../types';
|
|
4
|
-
import { SnapshotSummary } from './utils/types';
|
|
5
|
-
export interface Context {
|
|
6
|
-
file: string;
|
|
7
|
-
title?: string;
|
|
8
|
-
fullTitle?: string;
|
|
9
|
-
}
|
|
10
|
-
export declare class SnapshotManager {
|
|
11
|
-
snapshotState: SnapshotStateType | null;
|
|
12
|
-
snapshotSummary: SnapshotSummary;
|
|
13
|
-
snapshotOptions: SnapshotStateOptions;
|
|
14
|
-
context: Context | null;
|
|
15
|
-
testFile: string;
|
|
16
|
-
snapshotResolver: SnapshotResolver | null;
|
|
17
|
-
rootDir: string;
|
|
18
|
-
constructor({ rootDir, update, snapshotResolver, }: {
|
|
19
|
-
rootDir: string;
|
|
20
|
-
update?: boolean;
|
|
21
|
-
snapshotResolver?: SnapshotResolver | null;
|
|
22
|
-
});
|
|
23
|
-
onFileChanged(): void;
|
|
24
|
-
setTask(task: Task): void;
|
|
25
|
-
setContext(context: Context): void;
|
|
26
|
-
assert(received: unknown, message: string): void;
|
|
27
|
-
clear(): void;
|
|
28
|
-
saveSnap(): void;
|
|
29
|
-
report(): string[] | undefined;
|
|
30
|
-
}
|
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
import chai from 'chai';
|
|
2
|
-
import Snap from 'jest-snapshot';
|
|
3
|
-
import { packSnapshotState, addSnapshotResult, makeEmptySnapshotSummary, } from './utils/jest-test-result-helper';
|
|
4
|
-
import { getSnapshotSummaryOutput } from './utils/jest-reporters-lite';
|
|
5
|
-
const { expect } = chai;
|
|
6
|
-
const { SnapshotState } = Snap;
|
|
7
|
-
export class SnapshotManager {
|
|
8
|
-
constructor({ rootDir, update, snapshotResolver = null, }) {
|
|
9
|
-
this.snapshotState = null;
|
|
10
|
-
this.context = null;
|
|
11
|
-
this.testFile = '';
|
|
12
|
-
this.rootDir = rootDir;
|
|
13
|
-
this.snapshotResolver = snapshotResolver;
|
|
14
|
-
const env = process.env;
|
|
15
|
-
const CI = !!env.CI;
|
|
16
|
-
const UPDATE_SNAPSHOT = update || env.UPDATE_SNAPSHOT;
|
|
17
|
-
this.snapshotOptions = {
|
|
18
|
-
updateSnapshot: CI && !UPDATE_SNAPSHOT
|
|
19
|
-
? 'none'
|
|
20
|
-
: UPDATE_SNAPSHOT
|
|
21
|
-
? 'all'
|
|
22
|
-
: 'new',
|
|
23
|
-
};
|
|
24
|
-
this.snapshotSummary = makeEmptySnapshotSummary(this.snapshotOptions);
|
|
25
|
-
}
|
|
26
|
-
onFileChanged() {
|
|
27
|
-
if (!this.context)
|
|
28
|
-
return;
|
|
29
|
-
if (this.snapshotState !== null)
|
|
30
|
-
this.saveSnap();
|
|
31
|
-
this.testFile = this.context.file;
|
|
32
|
-
this.snapshotState = new SnapshotState(this.snapshotResolver.resolveSnapshotPath(this.testFile), this.snapshotOptions);
|
|
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
|
-
}
|
|
42
|
-
setContext(context) {
|
|
43
|
-
if (!context.title || !context.file)
|
|
44
|
-
return;
|
|
45
|
-
this.context = context;
|
|
46
|
-
if (this.testFile !== context.file)
|
|
47
|
-
this.onFileChanged();
|
|
48
|
-
}
|
|
49
|
-
assert(received, message) {
|
|
50
|
-
if (!this.snapshotState || !this.context)
|
|
51
|
-
return;
|
|
52
|
-
const { actual, expected, key, pass } = this.snapshotState.match({
|
|
53
|
-
testName: this.context.fullTitle || this.context.title || this.context.file,
|
|
54
|
-
received,
|
|
55
|
-
isInline: false,
|
|
56
|
-
});
|
|
57
|
-
if (!pass) {
|
|
58
|
-
expect(actual.trim()).equals(expected ? expected.trim() : '', message || `Snapshot name: \`${key}\``);
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
clear() {
|
|
62
|
-
this.snapshotSummary = makeEmptySnapshotSummary(this.snapshotOptions);
|
|
63
|
-
}
|
|
64
|
-
saveSnap() {
|
|
65
|
-
if (!this.testFile || !this.snapshotState)
|
|
66
|
-
return;
|
|
67
|
-
const packedSnapshotState = packSnapshotState(this.snapshotState);
|
|
68
|
-
addSnapshotResult(this.snapshotSummary, packedSnapshotState, this.testFile);
|
|
69
|
-
this.testFile = '';
|
|
70
|
-
this.snapshotState = null;
|
|
71
|
-
}
|
|
72
|
-
report() {
|
|
73
|
-
const outputs = getSnapshotSummaryOutput(this.rootDir, this.snapshotSummary);
|
|
74
|
-
if (outputs.length > 1)
|
|
75
|
-
return outputs;
|
|
76
|
-
}
|
|
77
|
-
}
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
|
|
3
|
-
*
|
|
4
|
-
* This source code is licensed under the MIT license found in the
|
|
5
|
-
* LICENSE file in the root directory of this source tree.
|
|
6
|
-
*/
|
|
7
|
-
import path from 'path';
|
|
8
|
-
export const replaceRootDirInPath = (rootDir, filePath) => {
|
|
9
|
-
if (!/^<rootDir>/.test(filePath))
|
|
10
|
-
return filePath;
|
|
11
|
-
return path.resolve(rootDir, path.normalize(`./${filePath.substr('<rootDir>'.length)}`));
|
|
12
|
-
};
|
|
13
|
-
export function replaceRootDirInObject(rootDir, config) {
|
|
14
|
-
const newConfig = {};
|
|
15
|
-
for (const configKey of Object.keys(config)) {
|
|
16
|
-
newConfig[configKey]
|
|
17
|
-
= configKey === 'rootDir'
|
|
18
|
-
? config[configKey]
|
|
19
|
-
: _replaceRootDirTags(rootDir, config[configKey]);
|
|
20
|
-
}
|
|
21
|
-
return newConfig;
|
|
22
|
-
}
|
|
23
|
-
export function _replaceRootDirTags(rootDir, config) {
|
|
24
|
-
if (config == null)
|
|
25
|
-
return config;
|
|
26
|
-
switch (typeof config) {
|
|
27
|
-
case 'object':
|
|
28
|
-
if (Array.isArray(config)) {
|
|
29
|
-
/// can be string[] or {}[]
|
|
30
|
-
return config.map(item => _replaceRootDirTags(rootDir, item));
|
|
31
|
-
}
|
|
32
|
-
if (config instanceof RegExp)
|
|
33
|
-
return config;
|
|
34
|
-
return replaceRootDirInObject(rootDir, config);
|
|
35
|
-
case 'string':
|
|
36
|
-
return replaceRootDirInPath(rootDir, config);
|
|
37
|
-
}
|
|
38
|
-
return config;
|
|
39
|
-
}
|
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
|
|
3
|
-
*
|
|
4
|
-
* This source code is licensed under the MIT license found in the
|
|
5
|
-
* LICENSE file in the root directory of this source tree.
|
|
6
|
-
*/
|
|
7
|
-
import path, { isAbsolute } from 'path';
|
|
8
|
-
import { pluralize } from 'jest-util';
|
|
9
|
-
import slash from 'slash';
|
|
10
|
-
import c from 'picocolors';
|
|
11
|
-
const formatTestPath = (rootDir, testPath) => {
|
|
12
|
-
if (isAbsolute(testPath))
|
|
13
|
-
testPath = path.relative(rootDir, testPath);
|
|
14
|
-
const dirname = path.dirname(testPath);
|
|
15
|
-
const basename = path.basename(testPath);
|
|
16
|
-
return slash(c.dim(dirname + path.sep) + c.bold(basename));
|
|
17
|
-
};
|
|
18
|
-
const ARROW = ' \u203A ';
|
|
19
|
-
const DOWN_ARROW = ' \u21B3 ';
|
|
20
|
-
const DOT = ' \u2022 ';
|
|
21
|
-
const FAIL_COLOR = (v) => c.bold(c.red(v));
|
|
22
|
-
const OBSOLETE_COLOR = (v) => c.bold(c.yellow(v));
|
|
23
|
-
const SNAPSHOT_ADDED = (v) => c.bold(c.green(v));
|
|
24
|
-
const SNAPSHOT_NOTE = c.dim;
|
|
25
|
-
const SNAPSHOT_REMOVED = (v) => c.bold(c.green(v));
|
|
26
|
-
const SNAPSHOT_SUMMARY = c.bold;
|
|
27
|
-
const SNAPSHOT_UPDATED = (v) => c.bold(c.green(v));
|
|
28
|
-
const updateCommand = 're-run mocha with `--update` to update them';
|
|
29
|
-
export const getSnapshotSummaryOutput = (rootDir, snapshots) => {
|
|
30
|
-
const summary = [];
|
|
31
|
-
summary.push(SNAPSHOT_SUMMARY('Snapshot Summary'));
|
|
32
|
-
if (snapshots.added) {
|
|
33
|
-
summary.push(`${SNAPSHOT_ADDED(`${ARROW + pluralize('snapshot', snapshots.added)} written `)}from ${pluralize('test suite', snapshots.filesAdded)}.`);
|
|
34
|
-
}
|
|
35
|
-
if (snapshots.unmatched) {
|
|
36
|
-
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.`)}`);
|
|
37
|
-
}
|
|
38
|
-
if (snapshots.updated) {
|
|
39
|
-
summary.push(`${SNAPSHOT_UPDATED(`${ARROW + pluralize('snapshot', snapshots.updated)} updated `)}from ${pluralize('test suite', snapshots.filesUpdated)}.`);
|
|
40
|
-
}
|
|
41
|
-
if (snapshots.filesRemoved) {
|
|
42
|
-
if (snapshots.didUpdate) {
|
|
43
|
-
summary.push(`${SNAPSHOT_REMOVED(`${ARROW}${pluralize('snapshot file', snapshots.filesRemoved)} removed `)}from ${pluralize('test suite', snapshots.filesRemoved)}.`);
|
|
44
|
-
}
|
|
45
|
-
else {
|
|
46
|
-
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}.`)}`);
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
if (snapshots.filesRemovedList && snapshots.filesRemovedList.length) {
|
|
50
|
-
const [head, ...tail] = snapshots.filesRemovedList;
|
|
51
|
-
summary.push(` ${DOWN_ARROW} ${DOT}${formatTestPath(rootDir, head)}`);
|
|
52
|
-
tail.forEach((key) => {
|
|
53
|
-
summary.push(` ${DOT}${formatTestPath(rootDir, key)}`);
|
|
54
|
-
});
|
|
55
|
-
}
|
|
56
|
-
if (snapshots.unchecked) {
|
|
57
|
-
if (snapshots.didUpdate) {
|
|
58
|
-
summary.push(`${SNAPSHOT_REMOVED(`${ARROW}${pluralize('snapshot', snapshots.unchecked)} removed `)}from ${pluralize('test suite', snapshots.uncheckedKeysByFile.length)}.`);
|
|
59
|
-
}
|
|
60
|
-
else {
|
|
61
|
-
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}.`)}`);
|
|
62
|
-
}
|
|
63
|
-
snapshots.uncheckedKeysByFile.forEach((uncheckedFile) => {
|
|
64
|
-
summary.push(` ${DOWN_ARROW}${formatTestPath(rootDir, uncheckedFile.filePath)}`);
|
|
65
|
-
uncheckedFile.keys.forEach((key) => {
|
|
66
|
-
summary.push(` ${DOT}${key}`);
|
|
67
|
-
});
|
|
68
|
-
});
|
|
69
|
-
}
|
|
70
|
-
return summary;
|
|
71
|
-
};
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import { SnapshotStateType } from 'jest-snapshot';
|
|
2
|
-
import { SnapshotStateOptions } from 'jest-snapshot/build/State';
|
|
3
|
-
import { SnapshotSummary, SnapshotResult } from './types';
|
|
4
|
-
export declare const makeEmptySnapshotSummary: (options: SnapshotStateOptions) => SnapshotSummary;
|
|
5
|
-
export declare const packSnapshotState: (snapshotState: SnapshotStateType) => SnapshotResult;
|
|
6
|
-
export declare const addSnapshotResult: (snapshotSummary: SnapshotSummary, snapshotResult: SnapshotResult, testFilePath: string) => void;
|
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
|
|
3
|
-
*
|
|
4
|
-
* This source code is licensed under the MIT license found in the
|
|
5
|
-
* LICENSE file in the root directory of this source tree.
|
|
6
|
-
*/
|
|
7
|
-
// @ts-ignore
|
|
8
|
-
import Test from '@jest/test-result';
|
|
9
|
-
const { makeEmptyAggregatedTestResult, } = Test;
|
|
10
|
-
export const makeEmptySnapshotSummary = (options) => {
|
|
11
|
-
const summary = makeEmptyAggregatedTestResult().snapshot;
|
|
12
|
-
summary.didUpdate = options.updateSnapshot === 'all';
|
|
13
|
-
return summary;
|
|
14
|
-
};
|
|
15
|
-
export const packSnapshotState = (snapshotState) => {
|
|
16
|
-
const snapshot = {
|
|
17
|
-
added: 0,
|
|
18
|
-
fileDeleted: false,
|
|
19
|
-
matched: 0,
|
|
20
|
-
unchecked: 0,
|
|
21
|
-
uncheckedKeys: [],
|
|
22
|
-
unmatched: 0,
|
|
23
|
-
updated: 0,
|
|
24
|
-
};
|
|
25
|
-
const uncheckedCount = snapshotState.getUncheckedCount();
|
|
26
|
-
const uncheckedKeys = snapshotState.getUncheckedKeys();
|
|
27
|
-
if (uncheckedCount)
|
|
28
|
-
snapshotState.removeUncheckedKeys();
|
|
29
|
-
const status = snapshotState.save();
|
|
30
|
-
snapshot.fileDeleted = status.deleted;
|
|
31
|
-
snapshot.added = snapshotState.added;
|
|
32
|
-
snapshot.matched = snapshotState.matched;
|
|
33
|
-
snapshot.unmatched = snapshotState.unmatched;
|
|
34
|
-
snapshot.updated = snapshotState.updated;
|
|
35
|
-
snapshot.unchecked = !status.deleted ? uncheckedCount : 0;
|
|
36
|
-
// Copy the array to prevent memory leaks
|
|
37
|
-
snapshot.uncheckedKeys = Array.from(uncheckedKeys);
|
|
38
|
-
return snapshot;
|
|
39
|
-
};
|
|
40
|
-
export const addSnapshotResult = (snapshotSummary, snapshotResult, testFilePath) => {
|
|
41
|
-
// Snapshot data
|
|
42
|
-
if (snapshotResult.added)
|
|
43
|
-
snapshotSummary.filesAdded++;
|
|
44
|
-
if (snapshotResult.fileDeleted)
|
|
45
|
-
snapshotSummary.filesRemoved++;
|
|
46
|
-
if (snapshotResult.unmatched)
|
|
47
|
-
snapshotSummary.filesUnmatched++;
|
|
48
|
-
if (snapshotResult.updated)
|
|
49
|
-
snapshotSummary.filesUpdated++;
|
|
50
|
-
snapshotSummary.added += snapshotResult.added;
|
|
51
|
-
snapshotSummary.matched += snapshotResult.matched;
|
|
52
|
-
snapshotSummary.unchecked += snapshotResult.unchecked;
|
|
53
|
-
if (snapshotResult.uncheckedKeys && snapshotResult.uncheckedKeys.length > 0) {
|
|
54
|
-
snapshotSummary.uncheckedKeysByFile.push({
|
|
55
|
-
filePath: testFilePath,
|
|
56
|
-
keys: snapshotResult.uncheckedKeys,
|
|
57
|
-
});
|
|
58
|
-
}
|
|
59
|
-
snapshotSummary.unmatched += snapshotResult.unmatched;
|
|
60
|
-
snapshotSummary.updated += snapshotResult.updated;
|
|
61
|
-
snapshotSummary.total
|
|
62
|
-
+= snapshotResult.added
|
|
63
|
-
+ snapshotResult.matched
|
|
64
|
-
+ snapshotResult.unmatched
|
|
65
|
-
+ snapshotResult.updated;
|
|
66
|
-
};
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
export interface SnapshotResult {
|
|
2
|
-
added: number;
|
|
3
|
-
fileDeleted: boolean;
|
|
4
|
-
matched: number;
|
|
5
|
-
unchecked: number;
|
|
6
|
-
uncheckedKeys: Array<string>;
|
|
7
|
-
unmatched: number;
|
|
8
|
-
updated: number;
|
|
9
|
-
}
|
|
10
|
-
export interface UncheckedSnapshot {
|
|
11
|
-
filePath: string;
|
|
12
|
-
keys: Array<string>;
|
|
13
|
-
}
|
|
14
|
-
export interface SnapshotSummary {
|
|
15
|
-
added: number;
|
|
16
|
-
didUpdate: boolean;
|
|
17
|
-
failure: boolean;
|
|
18
|
-
filesAdded: number;
|
|
19
|
-
filesRemoved: number;
|
|
20
|
-
filesRemovedList: Array<string>;
|
|
21
|
-
filesUnmatched: number;
|
|
22
|
-
filesUpdated: number;
|
|
23
|
-
matched: number;
|
|
24
|
-
total: number;
|
|
25
|
-
unchecked: number;
|
|
26
|
-
uncheckedKeysByFile: Array<UncheckedSnapshot>;
|
|
27
|
-
unmatched: number;
|
|
28
|
-
updated: number;
|
|
29
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { Window } from 'happy-dom';
|
|
2
|
-
import { KEYS } from './keys';
|
|
3
|
-
export function setupHappyDOM(global) {
|
|
4
|
-
const win = new Window();
|
|
5
|
-
const keys = KEYS.concat(Object.getOwnPropertyNames(win))
|
|
6
|
-
.filter(k => !k.startsWith('_'))
|
|
7
|
-
.filter(k => !(k in global));
|
|
8
|
-
for (const key of keys)
|
|
9
|
-
// @ts-expect-error
|
|
10
|
-
global[key] = win[key];
|
|
11
|
-
return {
|
|
12
|
-
dom: win,
|
|
13
|
-
restore() {
|
|
14
|
-
win.happyDOM.cancelAsync();
|
|
15
|
-
keys.forEach(key => delete global[key]);
|
|
16
|
-
},
|
|
17
|
-
};
|
|
18
|
-
}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { JSDOM } from 'jsdom';
|
|
2
|
-
import { KEYS } from './keys';
|
|
3
|
-
export function setupJSDOM(global) {
|
|
4
|
-
const dom = new JSDOM('<!DOCTYPE html>', {
|
|
5
|
-
pretendToBeVisual: true,
|
|
6
|
-
runScripts: 'dangerously',
|
|
7
|
-
// TODO: options
|
|
8
|
-
url: 'http://localhost:3000',
|
|
9
|
-
});
|
|
10
|
-
const keys = KEYS.concat(Object.getOwnPropertyNames(dom.window))
|
|
11
|
-
.filter(k => !k.startsWith('_'))
|
|
12
|
-
.filter(k => !(k in global));
|
|
13
|
-
for (const key of keys)
|
|
14
|
-
global[key] = dom.window[key];
|
|
15
|
-
return {
|
|
16
|
-
dom,
|
|
17
|
-
restore() {
|
|
18
|
-
keys.forEach(key => delete global[key]);
|
|
19
|
-
},
|
|
20
|
-
};
|
|
21
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const KEYS: string[];
|