@vitest/expect 2.0.4 → 2.1.0-beta.1
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/index.d.ts +9 -4
- package/dist/index.js +68 -60
- package/package.json +4 -4
package/dist/index.d.ts
CHANGED
@@ -1,18 +1,23 @@
|
|
1
1
|
import * as tinyrainbow from 'tinyrainbow';
|
2
2
|
import { Formatter } from 'tinyrainbow';
|
3
3
|
import { stringify, Constructable } from '@vitest/utils';
|
4
|
-
import { diff } from '@vitest/utils/diff';
|
4
|
+
import { diff, printDiffOrStringify } from '@vitest/utils/diff';
|
5
5
|
export { DiffOptions } from '@vitest/utils/diff';
|
6
6
|
|
7
|
+
declare function matcherHint(matcherName: string, received?: string, expected?: string, options?: MatcherHintOptions): string;
|
8
|
+
declare function printReceived(object: unknown): string;
|
9
|
+
declare function printExpected(value: unknown): string;
|
7
10
|
declare function getMatcherUtils(): {
|
8
11
|
EXPECTED_COLOR: tinyrainbow.Formatter;
|
9
12
|
RECEIVED_COLOR: tinyrainbow.Formatter;
|
10
13
|
INVERTED_COLOR: tinyrainbow.Formatter;
|
11
14
|
BOLD_WEIGHT: tinyrainbow.Formatter;
|
12
15
|
DIM_COLOR: tinyrainbow.Formatter;
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
+
diff: typeof diff;
|
17
|
+
matcherHint: typeof matcherHint;
|
18
|
+
printReceived: typeof printReceived;
|
19
|
+
printExpected: typeof printExpected;
|
20
|
+
printDiffOrStringify: typeof printDiffOrStringify;
|
16
21
|
};
|
17
22
|
declare function addCustomEqualityTesters(newTesters: Array<Tester>): void;
|
18
23
|
|
package/dist/index.js
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
import { getType, stringify, isObject, assertTypes } from '@vitest/utils';
|
2
2
|
import c from 'tinyrainbow';
|
3
|
-
import { diff } from '@vitest/utils/diff';
|
3
|
+
import { diff, printDiffOrStringify } from '@vitest/utils/diff';
|
4
4
|
import { isMockFunction } from '@vitest/spy';
|
5
5
|
import { processError } from '@vitest/utils/error';
|
6
6
|
import { use, util } from 'chai';
|
@@ -42,74 +42,82 @@ function setState(state, expect) {
|
|
42
42
|
map.set(expect, current);
|
43
43
|
}
|
44
44
|
|
45
|
+
const EXPECTED_COLOR = c.green;
|
46
|
+
const RECEIVED_COLOR = c.red;
|
47
|
+
const INVERTED_COLOR = c.inverse;
|
48
|
+
const BOLD_WEIGHT = c.bold;
|
49
|
+
const DIM_COLOR = c.dim;
|
50
|
+
function matcherHint(matcherName, received = "received", expected = "expected", options = {}) {
|
51
|
+
const {
|
52
|
+
comment = "",
|
53
|
+
isDirectExpectCall = false,
|
54
|
+
// seems redundant with received === ''
|
55
|
+
isNot = false,
|
56
|
+
promise = "",
|
57
|
+
secondArgument = "",
|
58
|
+
expectedColor = EXPECTED_COLOR,
|
59
|
+
receivedColor = RECEIVED_COLOR,
|
60
|
+
secondArgumentColor = EXPECTED_COLOR
|
61
|
+
} = options;
|
62
|
+
let hint = "";
|
63
|
+
let dimString = "expect";
|
64
|
+
if (!isDirectExpectCall && received !== "") {
|
65
|
+
hint += DIM_COLOR(`${dimString}(`) + receivedColor(received);
|
66
|
+
dimString = ")";
|
67
|
+
}
|
68
|
+
if (promise !== "") {
|
69
|
+
hint += DIM_COLOR(`${dimString}.`) + promise;
|
70
|
+
dimString = "";
|
71
|
+
}
|
72
|
+
if (isNot) {
|
73
|
+
hint += `${DIM_COLOR(`${dimString}.`)}not`;
|
74
|
+
dimString = "";
|
75
|
+
}
|
76
|
+
if (matcherName.includes(".")) {
|
77
|
+
dimString += matcherName;
|
78
|
+
} else {
|
79
|
+
hint += DIM_COLOR(`${dimString}.`) + matcherName;
|
80
|
+
dimString = "";
|
81
|
+
}
|
82
|
+
if (expected === "") {
|
83
|
+
dimString += "()";
|
84
|
+
} else {
|
85
|
+
hint += DIM_COLOR(`${dimString}(`) + expectedColor(expected);
|
86
|
+
if (secondArgument) {
|
87
|
+
hint += DIM_COLOR(", ") + secondArgumentColor(secondArgument);
|
88
|
+
}
|
89
|
+
dimString = ")";
|
90
|
+
}
|
91
|
+
if (comment !== "") {
|
92
|
+
dimString += ` // ${comment}`;
|
93
|
+
}
|
94
|
+
if (dimString !== "") {
|
95
|
+
hint += DIM_COLOR(dimString);
|
96
|
+
}
|
97
|
+
return hint;
|
98
|
+
}
|
99
|
+
const SPACE_SYMBOL = "\xB7";
|
100
|
+
function replaceTrailingSpaces(text) {
|
101
|
+
return text.replace(/\s+$/gm, (spaces) => SPACE_SYMBOL.repeat(spaces.length));
|
102
|
+
}
|
103
|
+
function printReceived(object) {
|
104
|
+
return RECEIVED_COLOR(replaceTrailingSpaces(stringify(object)));
|
105
|
+
}
|
106
|
+
function printExpected(value) {
|
107
|
+
return EXPECTED_COLOR(replaceTrailingSpaces(stringify(value)));
|
108
|
+
}
|
45
109
|
function getMatcherUtils() {
|
46
|
-
const EXPECTED_COLOR = c.green;
|
47
|
-
const RECEIVED_COLOR = c.red;
|
48
|
-
const INVERTED_COLOR = c.inverse;
|
49
|
-
const BOLD_WEIGHT = c.bold;
|
50
|
-
const DIM_COLOR = c.dim;
|
51
|
-
function matcherHint(matcherName, received = "received", expected = "expected", options = {}) {
|
52
|
-
const {
|
53
|
-
comment = "",
|
54
|
-
isDirectExpectCall = false,
|
55
|
-
// seems redundant with received === ''
|
56
|
-
isNot = false,
|
57
|
-
promise = "",
|
58
|
-
secondArgument = "",
|
59
|
-
expectedColor = EXPECTED_COLOR,
|
60
|
-
receivedColor = RECEIVED_COLOR,
|
61
|
-
secondArgumentColor = EXPECTED_COLOR
|
62
|
-
} = options;
|
63
|
-
let hint = "";
|
64
|
-
let dimString = "expect";
|
65
|
-
if (!isDirectExpectCall && received !== "") {
|
66
|
-
hint += DIM_COLOR(`${dimString}(`) + receivedColor(received);
|
67
|
-
dimString = ")";
|
68
|
-
}
|
69
|
-
if (promise !== "") {
|
70
|
-
hint += DIM_COLOR(`${dimString}.`) + promise;
|
71
|
-
dimString = "";
|
72
|
-
}
|
73
|
-
if (isNot) {
|
74
|
-
hint += `${DIM_COLOR(`${dimString}.`)}not`;
|
75
|
-
dimString = "";
|
76
|
-
}
|
77
|
-
if (matcherName.includes(".")) {
|
78
|
-
dimString += matcherName;
|
79
|
-
} else {
|
80
|
-
hint += DIM_COLOR(`${dimString}.`) + matcherName;
|
81
|
-
dimString = "";
|
82
|
-
}
|
83
|
-
if (expected === "") {
|
84
|
-
dimString += "()";
|
85
|
-
} else {
|
86
|
-
hint += DIM_COLOR(`${dimString}(`) + expectedColor(expected);
|
87
|
-
if (secondArgument) {
|
88
|
-
hint += DIM_COLOR(", ") + secondArgumentColor(secondArgument);
|
89
|
-
}
|
90
|
-
dimString = ")";
|
91
|
-
}
|
92
|
-
if (comment !== "") {
|
93
|
-
dimString += ` // ${comment}`;
|
94
|
-
}
|
95
|
-
if (dimString !== "") {
|
96
|
-
hint += DIM_COLOR(dimString);
|
97
|
-
}
|
98
|
-
return hint;
|
99
|
-
}
|
100
|
-
const SPACE_SYMBOL = "\xB7";
|
101
|
-
const replaceTrailingSpaces = (text) => text.replace(/\s+$/gm, (spaces) => SPACE_SYMBOL.repeat(spaces.length));
|
102
|
-
const printReceived = (object) => RECEIVED_COLOR(replaceTrailingSpaces(stringify(object)));
|
103
|
-
const printExpected = (value) => EXPECTED_COLOR(replaceTrailingSpaces(stringify(value)));
|
104
110
|
return {
|
105
111
|
EXPECTED_COLOR,
|
106
112
|
RECEIVED_COLOR,
|
107
113
|
INVERTED_COLOR,
|
108
114
|
BOLD_WEIGHT,
|
109
115
|
DIM_COLOR,
|
116
|
+
diff,
|
110
117
|
matcherHint,
|
111
118
|
printReceived,
|
112
|
-
printExpected
|
119
|
+
printExpected,
|
120
|
+
printDiffOrStringify
|
113
121
|
};
|
114
122
|
}
|
115
123
|
function addCustomEqualityTesters(newTesters) {
|
package/package.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"name": "@vitest/expect",
|
3
3
|
"type": "module",
|
4
|
-
"version": "2.0.
|
4
|
+
"version": "2.1.0-beta.1",
|
5
5
|
"description": "Jest's expect matchers as a Chai plugin",
|
6
6
|
"license": "MIT",
|
7
7
|
"funding": "https://opencollective.com/vitest",
|
@@ -32,13 +32,13 @@
|
|
32
32
|
"dependencies": {
|
33
33
|
"chai": "^5.1.1",
|
34
34
|
"tinyrainbow": "^1.2.0",
|
35
|
-
"@vitest/
|
36
|
-
"@vitest/
|
35
|
+
"@vitest/spy": "2.1.0-beta.1",
|
36
|
+
"@vitest/utils": "2.1.0-beta.1"
|
37
37
|
},
|
38
38
|
"devDependencies": {
|
39
39
|
"@types/chai": "4.3.6",
|
40
40
|
"rollup-plugin-copy": "^3.5.0",
|
41
|
-
"@vitest/runner": "2.0.
|
41
|
+
"@vitest/runner": "2.1.0-beta.1"
|
42
42
|
},
|
43
43
|
"scripts": {
|
44
44
|
"build": "rimraf dist && rollup -c",
|