@sprucelabs/test 9.0.50 → 9.0.51
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/build/lib/AssertionError.js +1 -2
- package/build/lib/assert.js +27 -18
- package/build/lib/assert.utility.js +9 -10
- package/build/lib/decorators.js +4 -4
- package/package.json +1 -1
|
@@ -6,10 +6,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
const StackCleaner_1 = __importDefault(require("./StackCleaner"));
|
|
7
7
|
class AssertionError extends Error {
|
|
8
8
|
constructor(message, stack) {
|
|
9
|
-
var _a;
|
|
10
9
|
super(message);
|
|
11
10
|
this.message = StackCleaner_1.default.clean(message ? `${message}\n` : '');
|
|
12
|
-
this.stack = StackCleaner_1.default.clean(`${this.message}${(
|
|
11
|
+
this.stack = StackCleaner_1.default.clean(`${this.message}${(stack ?? this.stack ?? '').replace(message, '')}`);
|
|
13
12
|
}
|
|
14
13
|
}
|
|
15
14
|
exports.default = AssertionError;
|
package/build/lib/assert.js
CHANGED
|
@@ -21,44 +21,49 @@ const assert = {
|
|
|
21
21
|
isExactType,
|
|
22
22
|
isNumber(actual, message) {
|
|
23
23
|
if (typeof actual !== 'number') {
|
|
24
|
-
this.fail(message
|
|
24
|
+
this.fail(message ?? `${stringify(actual)} is not a number!`);
|
|
25
25
|
}
|
|
26
26
|
},
|
|
27
27
|
isEqual(actual, expected, message) {
|
|
28
28
|
if (actual !== expected) {
|
|
29
|
-
this.fail(message
|
|
29
|
+
this.fail(message ??
|
|
30
|
+
`${stringify(actual)} does not equal ${stringify(expected)}`);
|
|
30
31
|
}
|
|
31
32
|
},
|
|
32
33
|
isNotEqual(actual, expected, message) {
|
|
33
34
|
if (actual === expected) {
|
|
34
|
-
this.fail(message
|
|
35
|
+
this.fail(message ??
|
|
36
|
+
`${stringify(actual)} should not equal ${stringify(expected)}`);
|
|
35
37
|
}
|
|
36
38
|
},
|
|
37
39
|
isEqualDeep(actual, expected, message, shouldAppendDelta = true) {
|
|
38
40
|
if (!(0, deep_equal_1.default)(actual, expected, { strict: true })) {
|
|
39
41
|
const result = (0, variable_diff_1.default)(actual, expected);
|
|
40
|
-
this.fail(`${message
|
|
42
|
+
this.fail(`${message ??
|
|
43
|
+
`Deep equal failed.\n\nActual would need the following changes to match expected:`}${shouldAppendDelta ? `\n\n${result.text}` : ``}`);
|
|
41
44
|
}
|
|
42
45
|
},
|
|
43
46
|
isAbove(actual, floor, message) {
|
|
44
47
|
if (typeof actual !== 'number') {
|
|
45
|
-
this.fail(message
|
|
48
|
+
this.fail(message ?? `${stringify(actual)} is not a number!`);
|
|
46
49
|
}
|
|
47
50
|
if (actual <= floor) {
|
|
48
|
-
this.fail(message
|
|
51
|
+
this.fail(message ??
|
|
52
|
+
`${stringify(actual)} is not above ${stringify(floor)}`);
|
|
49
53
|
}
|
|
50
54
|
},
|
|
51
55
|
isBelow(actual, ceiling, message) {
|
|
52
56
|
if (typeof actual !== 'number') {
|
|
53
|
-
this.fail(message
|
|
57
|
+
this.fail(message ?? `${stringify(actual)} is not a number!`);
|
|
54
58
|
}
|
|
55
59
|
if (actual >= ceiling) {
|
|
56
|
-
this.fail(message
|
|
60
|
+
this.fail(message ??
|
|
61
|
+
`${stringify(actual)} is not below ${stringify(ceiling)}`);
|
|
57
62
|
}
|
|
58
63
|
},
|
|
59
64
|
isUndefined(actual, message) {
|
|
60
65
|
if (typeof actual !== 'undefined') {
|
|
61
|
-
this.fail(message
|
|
66
|
+
this.fail(message ?? `${stringify(actual)} is not undefined`);
|
|
62
67
|
}
|
|
63
68
|
},
|
|
64
69
|
isTruthy(actual, message) {
|
|
@@ -66,17 +71,17 @@ const assert = {
|
|
|
66
71
|
actual === null ||
|
|
67
72
|
typeof actual === 'undefined' ||
|
|
68
73
|
actual === 0) {
|
|
69
|
-
this.fail(message
|
|
74
|
+
this.fail(message ?? `${stringify(actual)} is not truthy`);
|
|
70
75
|
}
|
|
71
76
|
},
|
|
72
77
|
isFalsy(actual, message) {
|
|
73
78
|
if (actual) {
|
|
74
|
-
this.fail(message
|
|
79
|
+
this.fail(message ?? `${stringify(actual)} is not falsy`);
|
|
75
80
|
}
|
|
76
81
|
},
|
|
77
82
|
isNull(actual, message) {
|
|
78
83
|
if (actual !== null) {
|
|
79
|
-
this.fail(message
|
|
84
|
+
this.fail(message ?? `${stringify(actual)} is not null`);
|
|
80
85
|
}
|
|
81
86
|
},
|
|
82
87
|
isString(actual, message) {
|
|
@@ -95,20 +100,22 @@ const assert = {
|
|
|
95
100
|
},
|
|
96
101
|
isObject(actual, message) {
|
|
97
102
|
if (!(0, isObjectLike_1.default)(actual)) {
|
|
98
|
-
throw this.fail(message
|
|
103
|
+
throw this.fail(message ?? `${stringify(actual)} is not an object`);
|
|
99
104
|
}
|
|
100
105
|
},
|
|
101
106
|
isArray(actual, message) {
|
|
102
107
|
if (!Array.isArray(actual)) {
|
|
103
|
-
throw this.fail(message
|
|
108
|
+
throw this.fail(message ?? `${stringify(actual)} is not an array`);
|
|
104
109
|
}
|
|
105
110
|
},
|
|
106
111
|
isLength(actual, expected, message) {
|
|
107
112
|
if (!actual) {
|
|
108
|
-
throw this.fail(message
|
|
113
|
+
throw this.fail(message ??
|
|
114
|
+
`Expected array of length ${expected}, but got ${stringify(actual)}`);
|
|
109
115
|
}
|
|
110
116
|
//@ts-ignore
|
|
111
|
-
this.isEqual(actual.length, expected, message
|
|
117
|
+
this.isEqual(actual.length, expected, message ??
|
|
118
|
+
`Expected length of ${stringify(expected)}, but got a length of ${stringify(actual.length)}`);
|
|
112
119
|
},
|
|
113
120
|
doesNotInclude(haystack, needle, message) {
|
|
114
121
|
let doesInclude = false;
|
|
@@ -120,11 +127,13 @@ const assert = {
|
|
|
120
127
|
doesInclude = false;
|
|
121
128
|
}
|
|
122
129
|
if (doesInclude) {
|
|
123
|
-
this.fail(message
|
|
130
|
+
this.fail(message ??
|
|
131
|
+
`${stringify(haystack)} should not include ${stringify(needle)}, but it does`);
|
|
124
132
|
}
|
|
125
133
|
},
|
|
126
134
|
doesInclude(haystack, needle, message) {
|
|
127
|
-
let msg = message
|
|
135
|
+
let msg = message ??
|
|
136
|
+
`Could not find ${stringify(needle)} in ${stringify(haystack)}`;
|
|
128
137
|
const isNeedleString = typeof needle === 'string';
|
|
129
138
|
const isNeedleRegex = needle instanceof RegExp;
|
|
130
139
|
if (typeof haystack === 'string' &&
|
|
@@ -16,10 +16,9 @@ exports.CIRCULAR_PLACEHOLDER = '_____________circular_____________';
|
|
|
16
16
|
exports.NULL_PLACEHOLDER = '_____________null_____________';
|
|
17
17
|
const assertUtil = {
|
|
18
18
|
fail(message, stack) {
|
|
19
|
-
throw new AssertionError_1.default(message
|
|
19
|
+
throw new AssertionError_1.default(message ?? 'Fail!', stack);
|
|
20
20
|
},
|
|
21
21
|
stringify(object) {
|
|
22
|
-
var _a;
|
|
23
22
|
let stringified;
|
|
24
23
|
if (Array.isArray(object)) {
|
|
25
24
|
stringified = `[\n${object.map((o) => this.stringify(o).split('\n').join('\n\t'))}\n]`;
|
|
@@ -29,7 +28,7 @@ const assertUtil = {
|
|
|
29
28
|
stringified = chalk_1.default.bgBlack.white(` ${object} `);
|
|
30
29
|
}
|
|
31
30
|
else if (object instanceof Error) {
|
|
32
|
-
stringified = `${
|
|
31
|
+
stringified = `${object.stack ?? object.message}`;
|
|
33
32
|
}
|
|
34
33
|
else if (object instanceof RegExp) {
|
|
35
34
|
stringified = `${object.toString()}`;
|
|
@@ -112,18 +111,19 @@ const assertUtil = {
|
|
|
112
111
|
},
|
|
113
112
|
assertTypeof(actual, type, message) {
|
|
114
113
|
if (typeof actual !== type) {
|
|
115
|
-
this.fail(message
|
|
114
|
+
this.fail(message ?? `${JSON.stringify(actual)} is not a ${type}`);
|
|
116
115
|
}
|
|
117
116
|
},
|
|
118
117
|
checkDoesThrowError(matcher, err, msg) {
|
|
119
|
-
|
|
120
|
-
const message = (_b = (_a = err.stack) !== null && _a !== void 0 ? _a : err.message) !== null && _b !== void 0 ? _b : '**MISSING ERROR MESSAGE**';
|
|
118
|
+
const message = err.stack ?? err.message ?? '**MISSING ERROR MESSAGE**';
|
|
121
119
|
if (typeof matcher === 'string' && message.search(matcher) === -1) {
|
|
122
|
-
this.fail(msg
|
|
120
|
+
this.fail(msg ??
|
|
121
|
+
`Expected thrown error whose message contains: \n\n${chalk_1.default.bold(matcher)}\n\nbut got back:\n\n\`${chalk_1.default.bold(message)}\`.`, '\n\nStack: ' + err.stack);
|
|
123
122
|
}
|
|
124
123
|
else if (matcher instanceof RegExp &&
|
|
125
124
|
message.search(matcher) === -1) {
|
|
126
|
-
this.fail(msg
|
|
125
|
+
this.fail(msg ??
|
|
126
|
+
`Expected thrown error whose message matches the regex: \n\n${chalk_1.default.bold(matcher)}\n\nbut got back:\n\n\`${chalk_1.default.bold(message)}\`.`, '\n\nStack: ' + err.stack);
|
|
127
127
|
}
|
|
128
128
|
},
|
|
129
129
|
partialContains(object, subObject) {
|
|
@@ -162,9 +162,8 @@ const assertUtil = {
|
|
|
162
162
|
return { needleHasArrayNotation, path, expected };
|
|
163
163
|
},
|
|
164
164
|
splitPathBasedOnArrayNotation(path, haystack) {
|
|
165
|
-
var _a;
|
|
166
165
|
const pathParts = path.split('[].');
|
|
167
|
-
const pathToFirstArray =
|
|
166
|
+
const pathToFirstArray = pathParts.shift() ?? '';
|
|
168
167
|
const pathAfterFirstArray = pathParts.join('[].');
|
|
169
168
|
const actualBeforeArray = this.valueAtPath(haystack, pathToFirstArray);
|
|
170
169
|
return { actualBeforeArray, pathAfterFirstArray };
|
package/build/lib/decorators.js
CHANGED
|
@@ -32,7 +32,7 @@ function test(description, ...args) {
|
|
|
32
32
|
hookupTestClass(target);
|
|
33
33
|
const bound = descriptor.value.bind(target);
|
|
34
34
|
// Make sure each test gets the spruce
|
|
35
|
-
it(description
|
|
35
|
+
it(description ?? propertyKey, async () => {
|
|
36
36
|
//@ts-ignore
|
|
37
37
|
global.activeTest = {
|
|
38
38
|
file: target.name,
|
|
@@ -51,7 +51,7 @@ test.only = (description, ...args) => {
|
|
|
51
51
|
hookupTestClass(target);
|
|
52
52
|
const bound = descriptor.value.bind(target);
|
|
53
53
|
// Make sure each test gets the spruce
|
|
54
|
-
it.only(description
|
|
54
|
+
it.only(description ?? propertyKey, async () => {
|
|
55
55
|
return bound(...args);
|
|
56
56
|
});
|
|
57
57
|
};
|
|
@@ -64,7 +64,7 @@ test.todo = (description, ..._args) => {
|
|
|
64
64
|
// Lets attach before/after
|
|
65
65
|
hookupTestClass(target);
|
|
66
66
|
// Make sure each test gets the spruce
|
|
67
|
-
it.todo(description
|
|
67
|
+
it.todo(description ?? propertyKey);
|
|
68
68
|
};
|
|
69
69
|
};
|
|
70
70
|
/**
|
|
@@ -76,7 +76,7 @@ test.skip = (description, ...args) => {
|
|
|
76
76
|
hookupTestClass(target);
|
|
77
77
|
const bound = descriptor.value.bind(target);
|
|
78
78
|
// Make sure each test gets the spruce
|
|
79
|
-
it.skip(description
|
|
79
|
+
it.skip(description ?? propertyKey, async () => {
|
|
80
80
|
return bound(...args);
|
|
81
81
|
});
|
|
82
82
|
};
|