@sprucelabs/test 8.0.51 → 9.0.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/build/esm/index.d.ts +4 -6
- package/build/esm/index.js +4 -6
- package/build/esm/{AssertionError.d.ts → lib/AssertionError.d.ts} +0 -3
- package/build/esm/{AssertionError.js → lib/AssertionError.js} +0 -3
- package/build/{StackCleaner.d.ts → esm/lib/StackCleaner.d.ts} +0 -3
- package/build/esm/{StackCleaner.js → lib/StackCleaner.js} +0 -3
- package/build/{assert.d.ts → esm/lib/assert.d.ts} +3 -3
- package/build/esm/{assert.js → lib/assert.js} +5 -6
- package/build/esm/{utilities → lib}/assert.utility.d.ts +1 -4
- package/build/esm/{utilities → lib}/assert.utility.js +11 -8
- package/build/esm/{decorators.d.ts → lib/decorators.d.ts} +3 -1
- package/build/esm/{decorators.js → lib/decorators.js} +6 -2
- package/build/index.d.ts +4 -6
- package/build/index.js +5 -9
- package/build/{AbstractSpruceTest.js → lib/AbstractSpruceTest.js} +1 -0
- package/build/{AssertionError.d.ts → lib/AssertionError.d.ts} +0 -3
- package/build/{AssertionError.js → lib/AssertionError.js} +1 -5
- package/build/{esm → lib}/StackCleaner.d.ts +0 -3
- package/build/{StackCleaner.js → lib/StackCleaner.js} +1 -4
- package/build/{esm → lib}/assert.d.ts +3 -3
- package/build/{assert.js → lib/assert.js} +34 -26
- package/build/{utilities → lib}/assert.utility.d.ts +1 -4
- package/build/{utilities → lib}/assert.utility.js +21 -19
- package/build/{decorators.d.ts → lib/decorators.d.ts} +3 -1
- package/build/{decorators.js → lib/decorators.js} +11 -5
- package/package.json +7 -7
- /package/build/{AbstractSpruceTest.d.ts → esm/lib/AbstractSpruceTest.d.ts} +0 -0
- /package/build/esm/{AbstractSpruceTest.js → lib/AbstractSpruceTest.js} +0 -0
- /package/build/{esm → lib}/AbstractSpruceTest.d.ts +0 -0
package/build/esm/index.d.ts
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
export { default } from './AbstractSpruceTest';
|
|
2
|
-
export { default as assert } from './assert';
|
|
3
|
-
export * from './assert';
|
|
4
|
-
export { default as test } from './decorators';
|
|
5
|
-
export { default as assertUtil } from './utilities/assert.utility';
|
|
6
|
-
export { default as StackCleaner } from './StackCleaner';
|
|
1
|
+
export { default } from './lib/AbstractSpruceTest';
|
|
2
|
+
export { default as assert } from './lib/assert';
|
|
3
|
+
export * from './lib/assert';
|
|
4
|
+
export { default as test } from './lib/decorators';
|
package/build/esm/index.js
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
export { default } from './AbstractSpruceTest.js';
|
|
2
|
-
export { default as assert } from './assert.js';
|
|
3
|
-
export * from './assert.js';
|
|
4
|
-
export { default as test } from './decorators.js';
|
|
5
|
-
export { default as assertUtil } from './utilities/assert.utility.js';
|
|
6
|
-
export { default as StackCleaner } from './StackCleaner.js';
|
|
1
|
+
export { default } from './lib/AbstractSpruceTest.js';
|
|
2
|
+
export { default as assert } from './lib/assert.js';
|
|
3
|
+
export * from './lib/assert.js';
|
|
4
|
+
export { default as test } from './lib/decorators.js';
|
|
@@ -41,7 +41,7 @@ export interface ISpruceAssert {
|
|
|
41
41
|
fail(message?: string): void;
|
|
42
42
|
}
|
|
43
43
|
/**
|
|
44
|
-
* @deprecated
|
|
44
|
+
* @deprecated - Remove and re-import from @sprucelabs/test-utils
|
|
45
45
|
*/
|
|
46
|
-
declare const
|
|
47
|
-
export default
|
|
46
|
+
declare const assert: ISpruceAssert;
|
|
47
|
+
export default assert;
|
|
@@ -13,13 +13,13 @@ import escapeRegExp from 'lodash/escapeRegExp.js';
|
|
|
13
13
|
import isObjectLike from 'lodash/isObjectLike.js';
|
|
14
14
|
import { expectType } from 'ts-expect';
|
|
15
15
|
import diff from 'variable-diff';
|
|
16
|
-
import assertUtil from './
|
|
16
|
+
import assertUtil from './assert.utility.js';
|
|
17
17
|
const stringify = assertUtil.stringify.bind(assertUtil);
|
|
18
18
|
function isExactType(_) { }
|
|
19
19
|
/**
|
|
20
|
-
* @deprecated
|
|
20
|
+
* @deprecated - Remove and re-import from @sprucelabs/test-utils
|
|
21
21
|
*/
|
|
22
|
-
const
|
|
22
|
+
const assert = {
|
|
23
23
|
areSameType() { },
|
|
24
24
|
isType: expectType,
|
|
25
25
|
isExactType,
|
|
@@ -40,7 +40,7 @@ const spruceAssert = {
|
|
|
40
40
|
},
|
|
41
41
|
isEqualDeep(actual, expected, message, shouldAppendDelta = true) {
|
|
42
42
|
if (!deepEqual(actual, expected, { strict: true })) {
|
|
43
|
-
|
|
43
|
+
const result = diff(actual, expected);
|
|
44
44
|
this.fail(`${message !== null && message !== void 0 ? message : `Deep equal failed.\n\nActual would need the following changes to match expected:`}${shouldAppendDelta ? `\n\n${result.text}` : ``}`);
|
|
45
45
|
}
|
|
46
46
|
},
|
|
@@ -153,7 +153,6 @@ const spruceAssert = {
|
|
|
153
153
|
//@ts-ignore
|
|
154
154
|
this.isEqualDeep(haystack, needle);
|
|
155
155
|
return;
|
|
156
|
-
// eslint-disable-next-line no-empty
|
|
157
156
|
}
|
|
158
157
|
catch (_a) { }
|
|
159
158
|
}
|
|
@@ -233,4 +232,4 @@ const spruceAssert = {
|
|
|
233
232
|
},
|
|
234
233
|
fail: assertUtil.fail,
|
|
235
234
|
};
|
|
236
|
-
export default
|
|
235
|
+
export default assert;
|
|
@@ -1,11 +1,8 @@
|
|
|
1
|
-
import { ISpruceAssert } from '
|
|
1
|
+
import { ISpruceAssert } from './assert';
|
|
2
2
|
export declare const UNDEFINED_PLACEHOLDER = "_____________undefined_____________";
|
|
3
3
|
export declare const FUNCTION_PLACEHOLDER = "_____________function_____________";
|
|
4
4
|
export declare const CIRCULAR_PLACEHOLDER = "_____________circular_____________";
|
|
5
5
|
export declare const NULL_PLACEHOLDER = "_____________null_____________";
|
|
6
|
-
/**
|
|
7
|
-
* @deprecated delete and re-import from @sprucelabs/test-utils
|
|
8
|
-
*/
|
|
9
6
|
declare const assertUtil: {
|
|
10
7
|
fail(message?: string, stack?: string): never;
|
|
11
8
|
stringify(object: any): string;
|
|
@@ -3,14 +3,11 @@ import get from 'lodash/get.js';
|
|
|
3
3
|
import includes from 'lodash/includes.js';
|
|
4
4
|
import isObject from 'lodash/isObject.js';
|
|
5
5
|
import isObjectLike from 'lodash/isObjectLike.js';
|
|
6
|
-
import AssertionError from '
|
|
6
|
+
import AssertionError from './AssertionError.js';
|
|
7
7
|
export const UNDEFINED_PLACEHOLDER = '_____________undefined_____________';
|
|
8
8
|
export const FUNCTION_PLACEHOLDER = '_____________function_____________';
|
|
9
9
|
export const CIRCULAR_PLACEHOLDER = '_____________circular_____________';
|
|
10
10
|
export const NULL_PLACEHOLDER = '_____________null_____________';
|
|
11
|
-
/**
|
|
12
|
-
* @deprecated delete and re-import from @sprucelabs/test-utils
|
|
13
|
-
*/
|
|
14
11
|
const assertUtil = {
|
|
15
12
|
fail(message, stack) {
|
|
16
13
|
throw new AssertionError(message !== null && message !== void 0 ? message : 'Fail!', stack);
|
|
@@ -56,7 +53,9 @@ const assertUtil = {
|
|
|
56
53
|
.replace(new RegExp(`"${NULL_PLACEHOLDER}"`, 'g'), chalk.italic('NULL'));
|
|
57
54
|
},
|
|
58
55
|
dropInPlaceholders(obj) {
|
|
59
|
-
const checkedObjects = [
|
|
56
|
+
const checkedObjects = [
|
|
57
|
+
{ obj, depth: 0 },
|
|
58
|
+
];
|
|
60
59
|
let updated = this.dropInPlaceholder(obj, (obj, depth) => {
|
|
61
60
|
if (isObject(obj) &&
|
|
62
61
|
checkedObjects.some((checked) => {
|
|
@@ -76,7 +75,9 @@ const assertUtil = {
|
|
|
76
75
|
if (!isObject(obj)) {
|
|
77
76
|
return obj;
|
|
78
77
|
}
|
|
79
|
-
const updated = Array.isArray(obj)
|
|
78
|
+
const updated = Array.isArray(obj)
|
|
79
|
+
? []
|
|
80
|
+
: {};
|
|
80
81
|
Object.keys(obj).forEach((key) => {
|
|
81
82
|
//@ts-ignore
|
|
82
83
|
updated[key] =
|
|
@@ -114,7 +115,8 @@ const assertUtil = {
|
|
|
114
115
|
if (typeof matcher === 'string' && message.search(matcher) === -1) {
|
|
115
116
|
this.fail(msg !== null && msg !== void 0 ? msg : `Expected thrown error whose message contains: \n\n${chalk.bold(matcher)}\n\nbut got back:\n\n\`${chalk.bold(message)}\`.`, '\n\nStack: ' + err.stack);
|
|
116
117
|
}
|
|
117
|
-
else if (matcher instanceof RegExp &&
|
|
118
|
+
else if (matcher instanceof RegExp &&
|
|
119
|
+
message.search(matcher) === -1) {
|
|
118
120
|
this.fail(msg !== null && msg !== void 0 ? msg : `Expected thrown error whose message matches the regex: \n\n${chalk.bold(matcher)}\n\nbut got back:\n\n\`${chalk.bold(message)}\`.`, '\n\nStack: ' + err.stack);
|
|
119
121
|
}
|
|
120
122
|
},
|
|
@@ -131,7 +133,8 @@ const assertUtil = {
|
|
|
131
133
|
if (!Object.prototype.hasOwnProperty.call(object, subProp)) {
|
|
132
134
|
return false;
|
|
133
135
|
}
|
|
134
|
-
if ((!isObjectLike(object[subProp]) ||
|
|
136
|
+
if ((!isObjectLike(object[subProp]) ||
|
|
137
|
+
!isObjectLike(subObject[subProp])) &&
|
|
135
138
|
object[subProp] !== subObject[subProp]) {
|
|
136
139
|
return false;
|
|
137
140
|
}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
/** Hooks up before, after, etc. */
|
|
2
|
+
export declare function hookupTestClass(target: any): void;
|
|
1
3
|
/**
|
|
2
|
-
* @deprecated
|
|
4
|
+
* @deprecated - Remove and re-import from @sprucelabs/test-utils
|
|
3
5
|
*/
|
|
4
6
|
declare function test(description?: string, ...args: any[]): (target: any, propertyKey: string, descriptor: PropertyDescriptor) => void;
|
|
5
7
|
declare namespace test {
|
|
@@ -8,7 +8,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
10
|
/** Hooks up before, after, etc. */
|
|
11
|
-
function hookupTestClass(target) {
|
|
11
|
+
export function hookupTestClass(target) {
|
|
12
12
|
if (target.__isTestingHookedUp) {
|
|
13
13
|
return;
|
|
14
14
|
}
|
|
@@ -29,7 +29,7 @@ function hookupTestClass(target) {
|
|
|
29
29
|
});
|
|
30
30
|
}
|
|
31
31
|
/**
|
|
32
|
-
* @deprecated
|
|
32
|
+
* @deprecated - Remove and re-import from @sprucelabs/test-utils
|
|
33
33
|
*/
|
|
34
34
|
export default function test(description, ...args) {
|
|
35
35
|
return function (target, propertyKey, descriptor) {
|
|
@@ -37,6 +37,7 @@ export default function test(description, ...args) {
|
|
|
37
37
|
hookupTestClass(target);
|
|
38
38
|
const bound = descriptor.value.bind(target);
|
|
39
39
|
// Make sure each test gets the spruce
|
|
40
|
+
// eslint-disable-next-line no-undef
|
|
40
41
|
it(description !== null && description !== void 0 ? description : propertyKey, () => __awaiter(this, void 0, void 0, function* () {
|
|
41
42
|
//@ts-ignore
|
|
42
43
|
global.activeTest = {
|
|
@@ -56,6 +57,7 @@ test.only = (description, ...args) => {
|
|
|
56
57
|
hookupTestClass(target);
|
|
57
58
|
const bound = descriptor.value.bind(target);
|
|
58
59
|
// Make sure each test gets the spruce
|
|
60
|
+
// eslint-disable-next-line no-undef
|
|
59
61
|
it.only(description !== null && description !== void 0 ? description : propertyKey, () => __awaiter(this, void 0, void 0, function* () {
|
|
60
62
|
return bound(...args);
|
|
61
63
|
}));
|
|
@@ -69,6 +71,7 @@ test.todo = (description, ..._args) => {
|
|
|
69
71
|
// Lets attach before/after
|
|
70
72
|
hookupTestClass(target);
|
|
71
73
|
// Make sure each test gets the spruce
|
|
74
|
+
// eslint-disable-next-line no-undef
|
|
72
75
|
it.todo(description !== null && description !== void 0 ? description : propertyKey);
|
|
73
76
|
};
|
|
74
77
|
};
|
|
@@ -81,6 +84,7 @@ test.skip = (description, ...args) => {
|
|
|
81
84
|
hookupTestClass(target);
|
|
82
85
|
const bound = descriptor.value.bind(target);
|
|
83
86
|
// Make sure each test gets the spruce
|
|
87
|
+
// eslint-disable-next-line no-undef
|
|
84
88
|
it.skip(description !== null && description !== void 0 ? description : propertyKey, () => __awaiter(this, void 0, void 0, function* () {
|
|
85
89
|
return bound(...args);
|
|
86
90
|
}));
|
package/build/index.d.ts
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
export { default } from './AbstractSpruceTest';
|
|
2
|
-
export { default as assert } from './assert';
|
|
3
|
-
export * from './assert';
|
|
4
|
-
export { default as test } from './decorators';
|
|
5
|
-
export { default as assertUtil } from './utilities/assert.utility';
|
|
6
|
-
export { default as StackCleaner } from './StackCleaner';
|
|
1
|
+
export { default } from './lib/AbstractSpruceTest';
|
|
2
|
+
export { default as assert } from './lib/assert';
|
|
3
|
+
export * from './lib/assert';
|
|
4
|
+
export { default as test } from './lib/decorators';
|
package/build/index.js
CHANGED
|
@@ -17,15 +17,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
17
17
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
18
18
|
};
|
|
19
19
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
-
exports.
|
|
21
|
-
var AbstractSpruceTest_1 = require("./AbstractSpruceTest");
|
|
20
|
+
exports.test = exports.assert = exports.default = void 0;
|
|
21
|
+
var AbstractSpruceTest_1 = require("./lib/AbstractSpruceTest");
|
|
22
22
|
Object.defineProperty(exports, "default", { enumerable: true, get: function () { return __importDefault(AbstractSpruceTest_1).default; } });
|
|
23
|
-
var assert_1 = require("./assert");
|
|
23
|
+
var assert_1 = require("./lib/assert");
|
|
24
24
|
Object.defineProperty(exports, "assert", { enumerable: true, get: function () { return __importDefault(assert_1).default; } });
|
|
25
|
-
__exportStar(require("./assert"), exports);
|
|
26
|
-
var decorators_1 = require("./decorators");
|
|
25
|
+
__exportStar(require("./lib/assert"), exports);
|
|
26
|
+
var decorators_1 = require("./lib/decorators");
|
|
27
27
|
Object.defineProperty(exports, "test", { enumerable: true, get: function () { return __importDefault(decorators_1).default; } });
|
|
28
|
-
var assert_utility_1 = require("./utilities/assert.utility");
|
|
29
|
-
Object.defineProperty(exports, "assertUtil", { enumerable: true, get: function () { return __importDefault(assert_utility_1).default; } });
|
|
30
|
-
var StackCleaner_1 = require("./StackCleaner");
|
|
31
|
-
Object.defineProperty(exports, "StackCleaner", { enumerable: true, get: function () { return __importDefault(StackCleaner_1).default; } });
|
|
@@ -5,6 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
const path_1 = __importDefault(require("path"));
|
|
7
7
|
class AbstractSpruceTest {
|
|
8
|
+
static cwd;
|
|
8
9
|
static async beforeAll() {
|
|
9
10
|
this.cwd = process.cwd();
|
|
10
11
|
}
|
|
@@ -4,15 +4,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
const StackCleaner_1 = __importDefault(require("./StackCleaner"));
|
|
7
|
-
/**
|
|
8
|
-
* @deprecated delete and re-import from @sprucelabs/test-utils
|
|
9
|
-
*/
|
|
10
7
|
class AssertionError extends Error {
|
|
11
8
|
constructor(message, stack) {
|
|
12
|
-
var _a;
|
|
13
9
|
super(message);
|
|
14
10
|
this.message = StackCleaner_1.default.clean(message ? `${message}\n` : '');
|
|
15
|
-
this.stack = StackCleaner_1.default.clean(`${this.message}${(
|
|
11
|
+
this.stack = StackCleaner_1.default.clean(`${this.message}${(stack ?? this.stack ?? '').replace(message, '')}`);
|
|
16
12
|
}
|
|
17
13
|
}
|
|
18
14
|
exports.default = AssertionError;
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
/**
|
|
4
|
-
* @deprecated delete and re-import from @sprucelabs/test-utils
|
|
5
|
-
*/
|
|
6
3
|
class StackCleaner {
|
|
4
|
+
static matchPattern = /spruce-test\/(?!src\/__tests__)|node_modules|internal\/process\/task_queues|@babel|regenerator-runtime\/runtime/gi;
|
|
7
5
|
static clean(stack) {
|
|
8
6
|
const lines = stack.split(/\r?\n/);
|
|
9
7
|
const filtered = lines.filter((line) => line.search(this.matchPattern) === -1);
|
|
@@ -11,5 +9,4 @@ class StackCleaner {
|
|
|
11
9
|
return newStack;
|
|
12
10
|
}
|
|
13
11
|
}
|
|
14
|
-
StackCleaner.matchPattern = /spruce-test\/(?!src\/__tests__)|node_modules|internal\/process\/task_queues|@babel|regenerator-runtime\/runtime/gi;
|
|
15
12
|
exports.default = StackCleaner;
|
|
@@ -41,7 +41,7 @@ export interface ISpruceAssert {
|
|
|
41
41
|
fail(message?: string): void;
|
|
42
42
|
}
|
|
43
43
|
/**
|
|
44
|
-
* @deprecated
|
|
44
|
+
* @deprecated - Remove and re-import from @sprucelabs/test-utils
|
|
45
45
|
*/
|
|
46
|
-
declare const
|
|
47
|
-
export default
|
|
46
|
+
declare const assert: ISpruceAssert;
|
|
47
|
+
export default assert;
|
|
@@ -9,56 +9,61 @@ const escapeRegExp_1 = __importDefault(require("lodash/escapeRegExp"));
|
|
|
9
9
|
const isObjectLike_1 = __importDefault(require("lodash/isObjectLike"));
|
|
10
10
|
const ts_expect_1 = require("ts-expect");
|
|
11
11
|
const variable_diff_1 = __importDefault(require("variable-diff"));
|
|
12
|
-
const assert_utility_1 = __importDefault(require("./
|
|
12
|
+
const assert_utility_1 = __importDefault(require("./assert.utility"));
|
|
13
13
|
const stringify = assert_utility_1.default.stringify.bind(assert_utility_1.default);
|
|
14
14
|
function isExactType(_) { }
|
|
15
15
|
/**
|
|
16
|
-
* @deprecated
|
|
16
|
+
* @deprecated - Remove and re-import from @sprucelabs/test-utils
|
|
17
17
|
*/
|
|
18
|
-
const
|
|
18
|
+
const assert = {
|
|
19
19
|
areSameType() { },
|
|
20
20
|
isType: ts_expect_1.expectType,
|
|
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
|
-
|
|
40
|
-
this.fail(`${message
|
|
41
|
+
const result = (0, variable_diff_1.default)(actual, expected);
|
|
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 spruceAssert = {
|
|
|
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 spruceAssert = {
|
|
|
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;
|
|
@@ -116,15 +123,17 @@ const spruceAssert = {
|
|
|
116
123
|
this.doesInclude(haystack, needle);
|
|
117
124
|
doesInclude = true;
|
|
118
125
|
}
|
|
119
|
-
catch
|
|
126
|
+
catch {
|
|
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' &&
|
|
@@ -149,9 +158,8 @@ const spruceAssert = {
|
|
|
149
158
|
//@ts-ignore
|
|
150
159
|
this.isEqualDeep(haystack, needle);
|
|
151
160
|
return;
|
|
152
|
-
// eslint-disable-next-line no-empty
|
|
153
161
|
}
|
|
154
|
-
catch
|
|
162
|
+
catch { }
|
|
155
163
|
}
|
|
156
164
|
if (assert_utility_1.default.foundUsing3rdPartyIncludes(haystack, needle, isHaystackObject)) {
|
|
157
165
|
return;
|
|
@@ -227,4 +235,4 @@ const spruceAssert = {
|
|
|
227
235
|
},
|
|
228
236
|
fail: assert_utility_1.default.fail,
|
|
229
237
|
};
|
|
230
|
-
exports.default =
|
|
238
|
+
exports.default = assert;
|
|
@@ -1,11 +1,8 @@
|
|
|
1
|
-
import { ISpruceAssert } from '
|
|
1
|
+
import { ISpruceAssert } from './assert';
|
|
2
2
|
export declare const UNDEFINED_PLACEHOLDER = "_____________undefined_____________";
|
|
3
3
|
export declare const FUNCTION_PLACEHOLDER = "_____________function_____________";
|
|
4
4
|
export declare const CIRCULAR_PLACEHOLDER = "_____________circular_____________";
|
|
5
5
|
export declare const NULL_PLACEHOLDER = "_____________null_____________";
|
|
6
|
-
/**
|
|
7
|
-
* @deprecated delete and re-import from @sprucelabs/test-utils
|
|
8
|
-
*/
|
|
9
6
|
declare const assertUtil: {
|
|
10
7
|
fail(message?: string, stack?: string): never;
|
|
11
8
|
stringify(object: any): string;
|
|
@@ -9,20 +9,16 @@ const get_1 = __importDefault(require("lodash/get"));
|
|
|
9
9
|
const includes_1 = __importDefault(require("lodash/includes"));
|
|
10
10
|
const isObject_1 = __importDefault(require("lodash/isObject"));
|
|
11
11
|
const isObjectLike_1 = __importDefault(require("lodash/isObjectLike"));
|
|
12
|
-
const AssertionError_1 = __importDefault(require("
|
|
12
|
+
const AssertionError_1 = __importDefault(require("./AssertionError"));
|
|
13
13
|
exports.UNDEFINED_PLACEHOLDER = '_____________undefined_____________';
|
|
14
14
|
exports.FUNCTION_PLACEHOLDER = '_____________function_____________';
|
|
15
15
|
exports.CIRCULAR_PLACEHOLDER = '_____________circular_____________';
|
|
16
16
|
exports.NULL_PLACEHOLDER = '_____________null_____________';
|
|
17
|
-
/**
|
|
18
|
-
* @deprecated delete and re-import from @sprucelabs/test-utils
|
|
19
|
-
*/
|
|
20
17
|
const assertUtil = {
|
|
21
18
|
fail(message, stack) {
|
|
22
|
-
throw new AssertionError_1.default(message
|
|
19
|
+
throw new AssertionError_1.default(message ?? 'Fail!', stack);
|
|
23
20
|
},
|
|
24
21
|
stringify(object) {
|
|
25
|
-
var _a;
|
|
26
22
|
let stringified;
|
|
27
23
|
if (Array.isArray(object)) {
|
|
28
24
|
stringified = `[\n${object.map((o) => this.stringify(o).split('\n').join('\n\t'))}\n]`;
|
|
@@ -32,7 +28,7 @@ const assertUtil = {
|
|
|
32
28
|
stringified = chalk_1.default.bgBlack.white(` ${object} `);
|
|
33
29
|
}
|
|
34
30
|
else if (object instanceof Error) {
|
|
35
|
-
stringified = `${
|
|
31
|
+
stringified = `${object.stack ?? object.message}`;
|
|
36
32
|
}
|
|
37
33
|
else if (object instanceof RegExp) {
|
|
38
34
|
stringified = `${object.toString()}`;
|
|
@@ -62,7 +58,9 @@ const assertUtil = {
|
|
|
62
58
|
.replace(new RegExp(`"${exports.NULL_PLACEHOLDER}"`, 'g'), chalk_1.default.italic('NULL'));
|
|
63
59
|
},
|
|
64
60
|
dropInPlaceholders(obj) {
|
|
65
|
-
const checkedObjects = [
|
|
61
|
+
const checkedObjects = [
|
|
62
|
+
{ obj, depth: 0 },
|
|
63
|
+
];
|
|
66
64
|
let updated = this.dropInPlaceholder(obj, (obj, depth) => {
|
|
67
65
|
if ((0, isObject_1.default)(obj) &&
|
|
68
66
|
checkedObjects.some((checked) => {
|
|
@@ -82,7 +80,9 @@ const assertUtil = {
|
|
|
82
80
|
if (!(0, isObject_1.default)(obj)) {
|
|
83
81
|
return obj;
|
|
84
82
|
}
|
|
85
|
-
const updated = Array.isArray(obj)
|
|
83
|
+
const updated = Array.isArray(obj)
|
|
84
|
+
? []
|
|
85
|
+
: {};
|
|
86
86
|
Object.keys(obj).forEach((key) => {
|
|
87
87
|
//@ts-ignore
|
|
88
88
|
updated[key] =
|
|
@@ -104,24 +104,26 @@ const assertUtil = {
|
|
|
104
104
|
check(haystack, needle);
|
|
105
105
|
return true;
|
|
106
106
|
}
|
|
107
|
-
catch
|
|
107
|
+
catch {
|
|
108
108
|
return false;
|
|
109
109
|
}
|
|
110
110
|
});
|
|
111
111
|
},
|
|
112
112
|
assertTypeof(actual, type, message) {
|
|
113
113
|
if (typeof actual !== type) {
|
|
114
|
-
this.fail(message
|
|
114
|
+
this.fail(message ?? `${JSON.stringify(actual)} is not a ${type}`);
|
|
115
115
|
}
|
|
116
116
|
},
|
|
117
117
|
checkDoesThrowError(matcher, err, msg) {
|
|
118
|
-
|
|
119
|
-
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**';
|
|
120
119
|
if (typeof matcher === 'string' && message.search(matcher) === -1) {
|
|
121
|
-
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);
|
|
122
122
|
}
|
|
123
|
-
else if (matcher instanceof RegExp &&
|
|
124
|
-
|
|
123
|
+
else if (matcher instanceof RegExp &&
|
|
124
|
+
message.search(matcher) === -1) {
|
|
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);
|
|
125
127
|
}
|
|
126
128
|
},
|
|
127
129
|
partialContains(object, subObject) {
|
|
@@ -137,7 +139,8 @@ const assertUtil = {
|
|
|
137
139
|
if (!Object.prototype.hasOwnProperty.call(object, subProp)) {
|
|
138
140
|
return false;
|
|
139
141
|
}
|
|
140
|
-
if ((!(0, isObjectLike_1.default)(object[subProp]) ||
|
|
142
|
+
if ((!(0, isObjectLike_1.default)(object[subProp]) ||
|
|
143
|
+
!(0, isObjectLike_1.default)(subObject[subProp])) &&
|
|
141
144
|
object[subProp] !== subObject[subProp]) {
|
|
142
145
|
return false;
|
|
143
146
|
}
|
|
@@ -159,9 +162,8 @@ const assertUtil = {
|
|
|
159
162
|
return { needleHasArrayNotation, path, expected };
|
|
160
163
|
},
|
|
161
164
|
splitPathBasedOnArrayNotation(path, haystack) {
|
|
162
|
-
var _a;
|
|
163
165
|
const pathParts = path.split('[].');
|
|
164
|
-
const pathToFirstArray =
|
|
166
|
+
const pathToFirstArray = pathParts.shift() ?? '';
|
|
165
167
|
const pathAfterFirstArray = pathParts.join('[].');
|
|
166
168
|
const actualBeforeArray = this.valueAtPath(haystack, pathToFirstArray);
|
|
167
169
|
return { actualBeforeArray, pathAfterFirstArray };
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
/** Hooks up before, after, etc. */
|
|
2
|
+
export declare function hookupTestClass(target: any): void;
|
|
1
3
|
/**
|
|
2
|
-
* @deprecated
|
|
4
|
+
* @deprecated - Remove and re-import from @sprucelabs/test-utils
|
|
3
5
|
*/
|
|
4
6
|
declare function test(description?: string, ...args: any[]): (target: any, propertyKey: string, descriptor: PropertyDescriptor) => void;
|
|
5
7
|
declare namespace test {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.hookupTestClass = void 0;
|
|
3
4
|
/** Hooks up before, after, etc. */
|
|
4
5
|
function hookupTestClass(target) {
|
|
5
6
|
if (target.__isTestingHookedUp) {
|
|
@@ -21,8 +22,9 @@ function hookupTestClass(target) {
|
|
|
21
22
|
}
|
|
22
23
|
});
|
|
23
24
|
}
|
|
25
|
+
exports.hookupTestClass = hookupTestClass;
|
|
24
26
|
/**
|
|
25
|
-
* @deprecated
|
|
27
|
+
* @deprecated - Remove and re-import from @sprucelabs/test-utils
|
|
26
28
|
*/
|
|
27
29
|
function test(description, ...args) {
|
|
28
30
|
return function (target, propertyKey, descriptor) {
|
|
@@ -30,7 +32,8 @@ function test(description, ...args) {
|
|
|
30
32
|
hookupTestClass(target);
|
|
31
33
|
const bound = descriptor.value.bind(target);
|
|
32
34
|
// Make sure each test gets the spruce
|
|
33
|
-
|
|
35
|
+
// eslint-disable-next-line no-undef
|
|
36
|
+
it(description ?? propertyKey, async () => {
|
|
34
37
|
//@ts-ignore
|
|
35
38
|
global.activeTest = {
|
|
36
39
|
file: target.name,
|
|
@@ -50,7 +53,8 @@ test.only = (description, ...args) => {
|
|
|
50
53
|
hookupTestClass(target);
|
|
51
54
|
const bound = descriptor.value.bind(target);
|
|
52
55
|
// Make sure each test gets the spruce
|
|
53
|
-
|
|
56
|
+
// eslint-disable-next-line no-undef
|
|
57
|
+
it.only(description ?? propertyKey, async () => {
|
|
54
58
|
return bound(...args);
|
|
55
59
|
});
|
|
56
60
|
};
|
|
@@ -63,7 +67,8 @@ test.todo = (description, ..._args) => {
|
|
|
63
67
|
// Lets attach before/after
|
|
64
68
|
hookupTestClass(target);
|
|
65
69
|
// Make sure each test gets the spruce
|
|
66
|
-
|
|
70
|
+
// eslint-disable-next-line no-undef
|
|
71
|
+
it.todo(description ?? propertyKey);
|
|
67
72
|
};
|
|
68
73
|
};
|
|
69
74
|
/**
|
|
@@ -75,7 +80,8 @@ test.skip = (description, ...args) => {
|
|
|
75
80
|
hookupTestClass(target);
|
|
76
81
|
const bound = descriptor.value.bind(target);
|
|
77
82
|
// Make sure each test gets the spruce
|
|
78
|
-
|
|
83
|
+
// eslint-disable-next-line no-undef
|
|
84
|
+
it.skip(description ?? propertyKey, async () => {
|
|
79
85
|
return bound(...args);
|
|
80
86
|
});
|
|
81
87
|
};
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"publishConfig": {
|
|
4
4
|
"access": "public"
|
|
5
5
|
},
|
|
6
|
-
"version": "
|
|
6
|
+
"version": "9.0.1",
|
|
7
7
|
"skill": {
|
|
8
8
|
"namespace": "spruce-test",
|
|
9
9
|
"upgradeIgnoreList": [
|
|
@@ -49,8 +49,8 @@
|
|
|
49
49
|
"clean.build": "rm -rf build/",
|
|
50
50
|
"clean.dependencies": "rm -rf node_modules/ package-lock.json yarn.lock",
|
|
51
51
|
"clean.dist": "rm -rf build/__tests__ build/esm/__tests__",
|
|
52
|
-
"fix.lint": "eslint --fix --cache
|
|
53
|
-
"lint": "eslint --cache
|
|
52
|
+
"fix.lint": "eslint --fix --cache",
|
|
53
|
+
"lint": "eslint --cache",
|
|
54
54
|
"lint.tsc": "tsc -p . --noEmit",
|
|
55
55
|
"local": "node --inspect=5200 ./build/index.js",
|
|
56
56
|
"post.watch.build": "true",
|
|
@@ -75,17 +75,17 @@
|
|
|
75
75
|
"lodash": "^4.17.21",
|
|
76
76
|
"ts-expect": "^1.3.0",
|
|
77
77
|
"ts-jest": "next",
|
|
78
|
-
"typescript": "5.4.
|
|
78
|
+
"typescript": "^5.4.5",
|
|
79
79
|
"variable-diff": "^2.0.2"
|
|
80
80
|
},
|
|
81
81
|
"devDependencies": {
|
|
82
82
|
"@sprucelabs/esm-postbuild": "^5.0.163",
|
|
83
|
-
"@sprucelabs/semantic-release": "^
|
|
83
|
+
"@sprucelabs/semantic-release": "^5.0.1",
|
|
84
84
|
"@types/deep-equal": "^1.0.4",
|
|
85
85
|
"@types/jest": "^29.5.12",
|
|
86
86
|
"@types/lodash": "^4.17.0",
|
|
87
|
-
"eslint": "^
|
|
88
|
-
"eslint-config-spruce": "^
|
|
87
|
+
"eslint": "^9.0.0",
|
|
88
|
+
"eslint-config-spruce": "^11.2.1",
|
|
89
89
|
"prettier": "^3.2.5",
|
|
90
90
|
"tsc-watch": "^6.2.0",
|
|
91
91
|
"tsconfig-paths": "^4.2.0",
|
|
File without changes
|
|
File without changes
|
|
File without changes
|