@sprucelabs/test-utils 5.1.1 → 5.1.3
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/assert/assert.utility.d.ts +1 -1
- package/build/decorators.d.ts +3 -3
- package/build/decorators.js +1 -1
- package/build/esm/AbstractSpruceTest.js +8 -27
- package/build/esm/assert/assert.js +11 -22
- package/build/esm/assert/assert.utility.d.ts +1 -1
- package/build/esm/assert/assert.utility.js +1 -1
- package/build/esm/decorators.d.ts +3 -3
- package/build/esm/decorators.js +8 -17
- package/build/esm/utilities/errorAssert.js +1 -12
- package/build/esm/utilities/errorAssert.utility.d.ts +1 -1
- package/build/utilities/errorAssert.utility.d.ts +1 -1
- package/build/utilities/generateId.utility.js +1 -1
- package/package.json +9 -20
|
@@ -9,7 +9,7 @@ declare const assertUtil: {
|
|
|
9
9
|
replacePlaceholders(str: string): string;
|
|
10
10
|
dropInPlaceholders(obj: Record<string, any>): any[] | Record<string, any>;
|
|
11
11
|
dropInPlaceholder(obj: Record<string, any>, checker: (obj: any, depth: number) => boolean, placeholder: string, depth?: number): any[] | Record<string, any>;
|
|
12
|
-
doHaystacksPassCheck(haystacks: any[], needle: any, check: ISpruceAssert[
|
|
12
|
+
doHaystacksPassCheck(haystacks: any[], needle: any, check: ISpruceAssert["doesInclude"]): boolean;
|
|
13
13
|
assertTypeof(actual: any, type: string, message: string | undefined): void;
|
|
14
14
|
checkDoesThrowError(matcher: string | RegExp | undefined, err: Error, msg?: string | undefined): void;
|
|
15
15
|
partialContains(object: any, subObject: any): boolean | undefined;
|
package/build/decorators.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/** Test decorator */
|
|
2
2
|
declare function test(description?: string, ...args: any[]): (target: any, propertyKey: string, descriptor: PropertyDescriptor) => void;
|
|
3
3
|
declare namespace test {
|
|
4
|
-
var only: (description?: string
|
|
5
|
-
var todo: (description?: string
|
|
6
|
-
var skip: (description?: string
|
|
4
|
+
var only: (description?: string, ...args: any[]) => (target: any, propertyKey: string, descriptor: PropertyDescriptor) => void;
|
|
5
|
+
var todo: (description?: string, ..._args: any[]) => (target: any, propertyKey: string) => void;
|
|
6
|
+
var skip: (description?: string, ...args: any[]) => (target: any, propertyKey: string, descriptor: PropertyDescriptor) => void;
|
|
7
7
|
}
|
|
8
8
|
export default test;
|
package/build/decorators.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.default = test;
|
|
3
4
|
if (typeof it === 'undefined') {
|
|
4
5
|
//@ts-ignore
|
|
5
6
|
global.it = () => { };
|
|
@@ -42,7 +43,6 @@ function test(description, ...args) {
|
|
|
42
43
|
});
|
|
43
44
|
};
|
|
44
45
|
}
|
|
45
|
-
exports.default = test;
|
|
46
46
|
/** Only decorator */
|
|
47
47
|
test.only = (description, ...args) => {
|
|
48
48
|
return function (target, propertyKey, descriptor) {
|
|
@@ -1,28 +1,11 @@
|
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
1
|
import path from 'path';
|
|
11
2
|
export default class AbstractSpruceTest {
|
|
12
|
-
static beforeAll() {
|
|
13
|
-
|
|
14
|
-
this.cwd = process.cwd();
|
|
15
|
-
});
|
|
16
|
-
}
|
|
17
|
-
static afterAll() {
|
|
18
|
-
return __awaiter(this, void 0, void 0, function* () { });
|
|
19
|
-
}
|
|
20
|
-
static beforeEach() {
|
|
21
|
-
return __awaiter(this, void 0, void 0, function* () { });
|
|
22
|
-
}
|
|
23
|
-
static afterEach() {
|
|
24
|
-
return __awaiter(this, void 0, void 0, function* () { });
|
|
3
|
+
static async beforeAll() {
|
|
4
|
+
this.cwd = process.cwd();
|
|
25
5
|
}
|
|
6
|
+
static async afterAll() { }
|
|
7
|
+
static async beforeEach() { }
|
|
8
|
+
static async afterEach() { }
|
|
26
9
|
static resolvePath(...filePath) {
|
|
27
10
|
const cwd = this.cwd;
|
|
28
11
|
let builtPath = path.join(...filePath);
|
|
@@ -37,11 +20,9 @@ export default class AbstractSpruceTest {
|
|
|
37
20
|
}
|
|
38
21
|
return builtPath;
|
|
39
22
|
}
|
|
40
|
-
static wait() {
|
|
41
|
-
return
|
|
42
|
-
|
|
43
|
-
setTimeout(() => resolve(true), ms);
|
|
44
|
-
});
|
|
23
|
+
static async wait(ms = 1000) {
|
|
24
|
+
return new Promise((resolve) => {
|
|
25
|
+
setTimeout(() => resolve(true), ms);
|
|
45
26
|
});
|
|
46
27
|
}
|
|
47
28
|
static log(...args) {
|
|
@@ -1,12 +1,3 @@
|
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
1
|
import chalk from 'chalk';
|
|
11
2
|
import deepEqual from 'deep-equal';
|
|
12
3
|
import escapeRegExp from 'lodash/escapeRegExp.js';
|
|
@@ -120,7 +111,7 @@ const assert = {
|
|
|
120
111
|
this.doesInclude(haystack, needle);
|
|
121
112
|
doesInclude = true;
|
|
122
113
|
}
|
|
123
|
-
catch
|
|
114
|
+
catch {
|
|
124
115
|
doesInclude = false;
|
|
125
116
|
}
|
|
126
117
|
if (doesInclude) {
|
|
@@ -154,7 +145,7 @@ const assert = {
|
|
|
154
145
|
this.isEqualDeep(haystack, needle);
|
|
155
146
|
return;
|
|
156
147
|
}
|
|
157
|
-
catch
|
|
148
|
+
catch { }
|
|
158
149
|
}
|
|
159
150
|
if (assertUtil.foundUsing3rdPartyIncludes(haystack, needle, isHaystackObject)) {
|
|
160
151
|
return;
|
|
@@ -218,17 +209,15 @@ const assert = {
|
|
|
218
209
|
}
|
|
219
210
|
this.fail(msg !== null && msg !== void 0 ? msg : 'Expected a thrown error, but never got one!');
|
|
220
211
|
},
|
|
221
|
-
doesThrowAsync(cb, matcher, msg) {
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
this.fail(msg !== null && msg !== void 0 ? msg : 'Expected a thrown error, but never got one!');
|
|
231
|
-
});
|
|
212
|
+
async doesThrowAsync(cb, matcher, msg) {
|
|
213
|
+
try {
|
|
214
|
+
await cb();
|
|
215
|
+
}
|
|
216
|
+
catch (err) {
|
|
217
|
+
assertUtil.checkDoesThrowError(matcher, err, msg);
|
|
218
|
+
return err;
|
|
219
|
+
}
|
|
220
|
+
this.fail(msg !== null && msg !== void 0 ? msg : 'Expected a thrown error, but never got one!');
|
|
232
221
|
},
|
|
233
222
|
fail: assertUtil.fail,
|
|
234
223
|
isInstanceOf(actual, Class) {
|
|
@@ -9,7 +9,7 @@ declare const assertUtil: {
|
|
|
9
9
|
replacePlaceholders(str: string): string;
|
|
10
10
|
dropInPlaceholders(obj: Record<string, any>): any[] | Record<string, any>;
|
|
11
11
|
dropInPlaceholder(obj: Record<string, any>, checker: (obj: any, depth: number) => boolean, placeholder: string, depth?: number): any[] | Record<string, any>;
|
|
12
|
-
doHaystacksPassCheck(haystacks: any[], needle: any, check: ISpruceAssert[
|
|
12
|
+
doHaystacksPassCheck(haystacks: any[], needle: any, check: ISpruceAssert["doesInclude"]): boolean;
|
|
13
13
|
assertTypeof(actual: any, type: string, message: string | undefined): void;
|
|
14
14
|
checkDoesThrowError(matcher: string | RegExp | undefined, err: Error, msg?: string | undefined): void;
|
|
15
15
|
partialContains(object: any, subObject: any): boolean | undefined;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/** Test decorator */
|
|
2
2
|
declare function test(description?: string, ...args: any[]): (target: any, propertyKey: string, descriptor: PropertyDescriptor) => void;
|
|
3
3
|
declare namespace test {
|
|
4
|
-
var only: (description?: string
|
|
5
|
-
var todo: (description?: string
|
|
6
|
-
var skip: (description?: string
|
|
4
|
+
var only: (description?: string, ...args: any[]) => (target: any, propertyKey: string, descriptor: PropertyDescriptor) => void;
|
|
5
|
+
var todo: (description?: string, ..._args: any[]) => (target: any, propertyKey: string) => void;
|
|
6
|
+
var skip: (description?: string, ...args: any[]) => (target: any, propertyKey: string, descriptor: PropertyDescriptor) => void;
|
|
7
7
|
}
|
|
8
8
|
export default test;
|
package/build/esm/decorators.js
CHANGED
|
@@ -1,12 +1,3 @@
|
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
1
|
if (typeof it === 'undefined') {
|
|
11
2
|
//@ts-ignore
|
|
12
3
|
global.it = () => { };
|
|
@@ -26,9 +17,9 @@ function hookupTestClass(target) {
|
|
|
26
17
|
// @ts-ignore
|
|
27
18
|
if (global[hook]) {
|
|
28
19
|
// @ts-ignore
|
|
29
|
-
global[hook](() =>
|
|
20
|
+
global[hook](async () => {
|
|
30
21
|
return target[hook]();
|
|
31
|
-
})
|
|
22
|
+
});
|
|
32
23
|
}
|
|
33
24
|
});
|
|
34
25
|
}
|
|
@@ -39,14 +30,14 @@ export default function test(description, ...args) {
|
|
|
39
30
|
hookupTestClass(target);
|
|
40
31
|
const bound = descriptor.value.bind(target);
|
|
41
32
|
// Make sure each test gets the spruce
|
|
42
|
-
it(description !== null && description !== void 0 ? description : propertyKey, () =>
|
|
33
|
+
it(description !== null && description !== void 0 ? description : propertyKey, async () => {
|
|
43
34
|
//@ts-ignore
|
|
44
35
|
global.activeTest = {
|
|
45
36
|
file: target.name,
|
|
46
37
|
test: propertyKey,
|
|
47
38
|
};
|
|
48
39
|
return bound(...args);
|
|
49
|
-
})
|
|
40
|
+
});
|
|
50
41
|
};
|
|
51
42
|
}
|
|
52
43
|
/** Only decorator */
|
|
@@ -56,9 +47,9 @@ test.only = (description, ...args) => {
|
|
|
56
47
|
hookupTestClass(target);
|
|
57
48
|
const bound = descriptor.value.bind(target);
|
|
58
49
|
// Make sure each test gets the spruce
|
|
59
|
-
it.only(description !== null && description !== void 0 ? description : propertyKey, () =>
|
|
50
|
+
it.only(description !== null && description !== void 0 ? description : propertyKey, async () => {
|
|
60
51
|
return bound(...args);
|
|
61
|
-
})
|
|
52
|
+
});
|
|
62
53
|
};
|
|
63
54
|
};
|
|
64
55
|
/** Todo decorator */
|
|
@@ -77,8 +68,8 @@ test.skip = (description, ...args) => {
|
|
|
77
68
|
hookupTestClass(target);
|
|
78
69
|
const bound = descriptor.value.bind(target);
|
|
79
70
|
// Make sure each test gets the spruce
|
|
80
|
-
it.skip(description !== null && description !== void 0 ? description : propertyKey, () =>
|
|
71
|
+
it.skip(description !== null && description !== void 0 ? description : propertyKey, async () => {
|
|
81
72
|
return bound(...args);
|
|
82
|
-
})
|
|
73
|
+
});
|
|
83
74
|
};
|
|
84
75
|
};
|
|
@@ -1,14 +1,3 @@
|
|
|
1
|
-
var __rest = (this && this.__rest) || function (s, e) {
|
|
2
|
-
var t = {};
|
|
3
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
4
|
-
t[p] = s[p];
|
|
5
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
6
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
7
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
8
|
-
t[p[i]] = s[p[i]];
|
|
9
|
-
}
|
|
10
|
-
return t;
|
|
11
|
-
};
|
|
12
1
|
import AbstractSpruceError from '@sprucelabs/error';
|
|
13
2
|
import cloneDeep from 'just-clone';
|
|
14
3
|
import assert from '../assert/assert.js';
|
|
@@ -55,7 +44,7 @@ const errorAssert = {
|
|
|
55
44
|
}
|
|
56
45
|
}
|
|
57
46
|
else {
|
|
58
|
-
const
|
|
47
|
+
const { code, friendlyMessage, ...options } = spruceErr.options;
|
|
59
48
|
assertUtil.fail(`Invalid error code. Expected:\n\n'${expectedCode}'\n\nbut got:\n\nCode: '${code}'\nMessage: '${friendlyMessage !== null && friendlyMessage !== void 0 ? friendlyMessage : spruceErr.message}'\nOptions:${assertUtil.stringify(options)}`, spruceErr.stack);
|
|
60
49
|
}
|
|
61
50
|
},
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* @deprecated errorAssertUtil -> errorAssert
|
|
3
3
|
*/
|
|
4
4
|
declare const errorAssertUtil: {
|
|
5
|
-
assertError(error: Error | import("@sprucelabs/error").default<any>, expectedCode: string, expectedPartialOptions?: Record<string, any>
|
|
5
|
+
assertError(error: Error | import("@sprucelabs/error").default<any>, expectedCode: string, expectedPartialOptions?: Record<string, any>): void;
|
|
6
6
|
stripFriendlyMessageFromOptions(options: Record<string, any> | Record<string, any>[]): Record<string, any> | Record<string, any>[];
|
|
7
7
|
};
|
|
8
8
|
export default errorAssertUtil;
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* @deprecated errorAssertUtil -> errorAssert
|
|
3
3
|
*/
|
|
4
4
|
declare const errorAssertUtil: {
|
|
5
|
-
assertError(error: Error | import("@sprucelabs/error").default<any>, expectedCode: string, expectedPartialOptions?: Record<string, any>
|
|
5
|
+
assertError(error: Error | import("@sprucelabs/error").default<any>, expectedCode: string, expectedPartialOptions?: Record<string, any>): void;
|
|
6
6
|
stripFriendlyMessageFromOptions(options: Record<string, any> | Record<string, any>[]): Record<string, any> | Record<string, any>[];
|
|
7
7
|
};
|
|
8
8
|
export default errorAssertUtil;
|
|
@@ -3,8 +3,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.default = generateId;
|
|
6
7
|
const crypto_1 = __importDefault(require("crypto"));
|
|
7
8
|
function generateId() {
|
|
8
9
|
return crypto_1.default.randomUUID().replace(/[^a-z0-9]/gi, '');
|
|
9
10
|
}
|
|
10
|
-
exports.default = generateId;
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"publishConfig": {
|
|
4
4
|
"access": "public"
|
|
5
5
|
},
|
|
6
|
-
"version": "5.1.
|
|
6
|
+
"version": "5.1.3",
|
|
7
7
|
"files": [
|
|
8
8
|
"build"
|
|
9
9
|
],
|
|
@@ -55,15 +55,12 @@
|
|
|
55
55
|
"resolve-paths.lint": "yarn run build.resolve-paths ; yarn run lint",
|
|
56
56
|
"test": "jest",
|
|
57
57
|
"update.dependencies": "yarn run clean.dependencies && yarn",
|
|
58
|
-
"upgrade.packages": "yarn-upgrade-all && rm -f yarn.lock ; yarn ; yarn fix.lint ; true",
|
|
59
|
-
"upgrade.packages.all": "yarn install && yarn upgrade.packages",
|
|
60
|
-
"upgrade.packages.test": "yarn upgrade.packages.all && yarn lint && yarn build.dev && yarn test",
|
|
61
58
|
"watch.build.dev": "tsc-watch --sourceMap --onCompilationComplete 'yarn run post.watch.build'",
|
|
62
59
|
"watch.rebuild": "yarn run clean.all && yarn install && yarn run watch.build.dev",
|
|
63
60
|
"watch.tsc": "tsc -w"
|
|
64
61
|
},
|
|
65
62
|
"dependencies": {
|
|
66
|
-
"@sprucelabs/error": "^6.0.
|
|
63
|
+
"@sprucelabs/error": "^6.0.70",
|
|
67
64
|
"deep-equal": "^2.2.3",
|
|
68
65
|
"just-clone": "^6.2.0",
|
|
69
66
|
"lodash": "^4.17.21",
|
|
@@ -71,25 +68,25 @@
|
|
|
71
68
|
"variable-diff": "^2.0.2"
|
|
72
69
|
},
|
|
73
70
|
"devDependencies": {
|
|
74
|
-
"@sprucelabs/esm-postbuild": "^6.0.
|
|
75
|
-
"@sprucelabs/jest-json-reporter": "^8.0.
|
|
71
|
+
"@sprucelabs/esm-postbuild": "^6.0.54",
|
|
72
|
+
"@sprucelabs/jest-json-reporter": "^8.0.73",
|
|
76
73
|
"@sprucelabs/jest-sheets-reporter": "^2.0.20",
|
|
77
|
-
"@sprucelabs/semantic-release": "^5.0.
|
|
78
|
-
"@sprucelabs/test": "^9.0.
|
|
74
|
+
"@sprucelabs/semantic-release": "^5.0.2",
|
|
75
|
+
"@sprucelabs/test": "^9.0.34",
|
|
79
76
|
"@types/deep-equal": "^1.0.4",
|
|
80
77
|
"@types/jest": "^29.5.12",
|
|
81
78
|
"@types/lodash": "^4.17.5",
|
|
82
|
-
"@types/node": "^20.14.
|
|
79
|
+
"@types/node": "^20.14.9",
|
|
83
80
|
"chokidar-cli": "^3.0.0",
|
|
84
81
|
"eslint": "^9.5.0",
|
|
85
|
-
"eslint-config-spruce": "^11.2.
|
|
82
|
+
"eslint-config-spruce": "^11.2.26",
|
|
86
83
|
"jest": "^29.7.0",
|
|
87
84
|
"jest-circus": "^29.7.0",
|
|
88
85
|
"prettier": "^3.3.2",
|
|
89
86
|
"ts-node": "^10.9.2",
|
|
90
87
|
"tsc-watch": "^6.2.0",
|
|
91
88
|
"tsconfig-paths": "^4.2.0",
|
|
92
|
-
"typescript": "^5.
|
|
89
|
+
"typescript": "^5.5.2"
|
|
93
90
|
},
|
|
94
91
|
"jest": {
|
|
95
92
|
"testEnvironment": "node",
|
|
@@ -106,13 +103,5 @@
|
|
|
106
103
|
"testMatch": [
|
|
107
104
|
"**/__tests__/**/*.test.js?(x)"
|
|
108
105
|
]
|
|
109
|
-
},
|
|
110
|
-
"yarn-upgrade-all": {
|
|
111
|
-
"ignore": [
|
|
112
|
-
"@sprucelabs/error",
|
|
113
|
-
"@sprucelabs/semantic-release",
|
|
114
|
-
"@sprucelabs/test",
|
|
115
|
-
"eslint-config-spruce"
|
|
116
|
-
]
|
|
117
106
|
}
|
|
118
107
|
}
|