@sprucelabs/test-utils 5.0.8 → 5.0.10

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.
@@ -5,7 +5,6 @@ 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;
9
8
  static async beforeAll() {
10
9
  this.cwd = process.cwd();
11
10
  }
@@ -6,9 +6,10 @@ 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;
9
10
  super(message);
10
11
  this.message = StackCleaner_1.default.clean(message ? `${message}\n` : '');
11
- this.stack = StackCleaner_1.default.clean(`${this.message}${(stack ?? this.stack ?? '').replace(message, '')}`);
12
+ this.stack = StackCleaner_1.default.clean(`${this.message}${((_a = stack !== null && stack !== void 0 ? stack : this.stack) !== null && _a !== void 0 ? _a : '').replace(message, '')}`);
12
13
  }
13
14
  }
14
15
  exports.default = AssertionError;
@@ -1,7 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  class StackCleaner {
4
- static matchPattern = /spruce-test\/(?!src\/__tests__)|node_modules|internal\/process\/task_queues|@babel|regenerator-runtime\/runtime/gi;
5
4
  static clean(stack) {
6
5
  const lines = stack.split(/\r?\n/);
7
6
  const filtered = lines.filter((line) => line.search(this.matchPattern) === -1);
@@ -9,4 +8,5 @@ class StackCleaner {
9
8
  return newStack;
10
9
  }
11
10
  }
11
+ StackCleaner.matchPattern = /spruce-test\/(?!src\/__tests__)|node_modules|internal\/process\/task_queues|@babel|regenerator-runtime\/runtime/gi;
12
12
  exports.default = StackCleaner;
@@ -18,53 +18,47 @@ const assert = {
18
18
  isExactType,
19
19
  isNumber(actual, message) {
20
20
  if (typeof actual !== 'number') {
21
- this.fail(message ?? `${stringify(actual)} is not a number!`);
21
+ this.fail(message !== null && message !== void 0 ? message : `${stringify(actual)} is not a number!`);
22
22
  }
23
23
  },
24
24
  isEqual(actual, expected, message) {
25
25
  if (actual !== expected) {
26
- this.fail(message ??
27
- `${stringify(actual)} does not equal ${stringify(expected)}`);
26
+ this.fail(message !== null && message !== void 0 ? message : `${stringify(actual)} does not equal ${stringify(expected)}`);
28
27
  }
29
28
  },
30
29
  isNotEqual(actual, expected, message) {
31
30
  if (actual === expected) {
32
- this.fail(message ??
33
- `${stringify(actual)} should not equal ${stringify(expected)}`);
31
+ this.fail(message !== null && message !== void 0 ? message : `${stringify(actual)} should not equal ${stringify(expected)}`);
34
32
  }
35
33
  },
36
34
  isEqualDeep(actual, expected, message, shouldAppendDelta = true) {
37
35
  if (!(0, deep_equal_1.default)(actual, expected, { strict: true })) {
38
36
  let result = (0, variable_diff_1.default)(actual, expected);
39
- this.fail(`${message ??
40
- `Deep equal failed.\n\nActual would need the following changes to match expected:`}${shouldAppendDelta ? `\n\n${result.text}` : ``}`);
37
+ 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}` : ``}`);
41
38
  }
42
39
  },
43
40
  isNotEqualDeep(actual, expected, message) {
44
- this.doesThrow(() => this.isEqualDeep(actual, expected), undefined, message ??
45
- `The objects you passed are deep equal! They should not be!`);
41
+ this.doesThrow(() => this.isEqualDeep(actual, expected), undefined, message !== null && message !== void 0 ? message : `The objects you passed are deep equal! They should not be!`);
46
42
  },
47
43
  isAbove(actual, floor, message) {
48
44
  if (typeof actual !== 'number') {
49
- this.fail(message ?? `${stringify(actual)} is not a number!`);
45
+ this.fail(message !== null && message !== void 0 ? message : `${stringify(actual)} is not a number!`);
50
46
  }
51
47
  if (actual <= floor) {
52
- this.fail(message ??
53
- `${stringify(actual)} is not above ${stringify(floor)}`);
48
+ this.fail(message !== null && message !== void 0 ? message : `${stringify(actual)} is not above ${stringify(floor)}`);
54
49
  }
55
50
  },
56
51
  isBelow(actual, ceiling, message) {
57
52
  if (typeof actual !== 'number') {
58
- this.fail(message ?? `${stringify(actual)} is not a number!`);
53
+ this.fail(message !== null && message !== void 0 ? message : `${stringify(actual)} is not a number!`);
59
54
  }
60
55
  if (actual >= ceiling) {
61
- this.fail(message ??
62
- `${stringify(actual)} is not below ${stringify(ceiling)}`);
56
+ this.fail(message !== null && message !== void 0 ? message : `${stringify(actual)} is not below ${stringify(ceiling)}`);
63
57
  }
64
58
  },
65
59
  isUndefined(actual, message) {
66
60
  if (typeof actual !== 'undefined') {
67
- this.fail(message ?? `${stringify(actual)} is not undefined`);
61
+ this.fail(message !== null && message !== void 0 ? message : `${stringify(actual)} is not undefined`);
68
62
  }
69
63
  },
70
64
  isTruthy(actual, message) {
@@ -72,17 +66,17 @@ const assert = {
72
66
  actual === null ||
73
67
  typeof actual === 'undefined' ||
74
68
  actual === 0) {
75
- this.fail(message ?? `${stringify(actual)} is not truthy`);
69
+ this.fail(message !== null && message !== void 0 ? message : `${stringify(actual)} is not truthy`);
76
70
  }
77
71
  },
78
72
  isFalsy(actual, message) {
79
73
  if (actual) {
80
- this.fail(message ?? `${stringify(actual)} is not falsy`);
74
+ this.fail(message !== null && message !== void 0 ? message : `${stringify(actual)} is not falsy`);
81
75
  }
82
76
  },
83
77
  isNull(actual, message) {
84
78
  if (actual !== null) {
85
- this.fail(message ?? `${stringify(actual)} is not null`);
79
+ this.fail(message !== null && message !== void 0 ? message : `${stringify(actual)} is not null`);
86
80
  }
87
81
  },
88
82
  isString(actual, message) {
@@ -101,22 +95,20 @@ const assert = {
101
95
  },
102
96
  isObject(actual, message) {
103
97
  if (!(0, isObjectLike_1.default)(actual)) {
104
- throw this.fail(message ?? `${stringify(actual)} is not an object`);
98
+ throw this.fail(message !== null && message !== void 0 ? message : `${stringify(actual)} is not an object`);
105
99
  }
106
100
  },
107
101
  isArray(actual, message) {
108
102
  if (!Array.isArray(actual)) {
109
- throw this.fail(message ?? `${stringify(actual)} is not an array`);
103
+ throw this.fail(message !== null && message !== void 0 ? message : `${stringify(actual)} is not an array`);
110
104
  }
111
105
  },
112
106
  isLength(actual, expected, message) {
113
107
  if (!actual) {
114
- throw this.fail(message ??
115
- `Expected array of length ${expected}, but got ${stringify(actual)}`);
108
+ throw this.fail(message !== null && message !== void 0 ? message : `Expected array of length ${expected}, but got ${stringify(actual)}`);
116
109
  }
117
110
  //@ts-ignore
118
- this.isEqual(actual.length, expected, message ??
119
- `Expected length of ${stringify(expected)}, but got a length of ${stringify(actual.length)}`);
111
+ this.isEqual(actual.length, expected, message !== null && message !== void 0 ? message : `Expected length of ${stringify(expected)}, but got a length of ${stringify(actual.length)}`);
120
112
  },
121
113
  doesNotInclude(haystack, needle, message) {
122
114
  let doesInclude = false;
@@ -128,13 +120,11 @@ const assert = {
128
120
  doesInclude = false;
129
121
  }
130
122
  if (doesInclude) {
131
- this.fail(message ??
132
- `${stringify(haystack)} should not include ${stringify(needle)}, but it does`);
123
+ this.fail(message !== null && message !== void 0 ? message : `${stringify(haystack)} should not include ${stringify(needle)}, but it does`);
133
124
  }
134
125
  },
135
126
  doesInclude(haystack, needle, message) {
136
- let msg = message ??
137
- `Could not find ${stringify(needle)} in ${stringify(haystack)}`;
127
+ let msg = message !== null && message !== void 0 ? message : `Could not find ${stringify(needle)} in ${stringify(haystack)}`;
138
128
  const isNeedleString = typeof needle === 'string';
139
129
  const isNeedleRegex = needle instanceof RegExp;
140
130
  if (typeof haystack === 'string' &&
@@ -222,7 +212,7 @@ const assert = {
222
212
  assert_utility_1.default.checkDoesThrowError(matcher, err, msg);
223
213
  return err;
224
214
  }
225
- this.fail(msg ?? 'Expected a thrown error, but never got one!');
215
+ this.fail(msg !== null && msg !== void 0 ? msg : 'Expected a thrown error, but never got one!');
226
216
  },
227
217
  async doesThrowAsync(cb, matcher, msg) {
228
218
  try {
@@ -232,7 +222,7 @@ const assert = {
232
222
  assert_utility_1.default.checkDoesThrowError(matcher, err, msg);
233
223
  return err;
234
224
  }
235
- this.fail(msg ?? 'Expected a thrown error, but never got one!');
225
+ this.fail(msg !== null && msg !== void 0 ? msg : 'Expected a thrown error, but never got one!');
236
226
  },
237
227
  fail: assert_utility_1.default.fail,
238
228
  isInstanceOf(actual, Class) {
@@ -17,9 +17,10 @@ exports.CIRCULAR_PLACEHOLDER = '_____________circular_____________';
17
17
  exports.NULL_PLACEHOLDER = '_____________null_____________';
18
18
  const assertUtil = {
19
19
  fail(message, stack) {
20
- throw new AssertionError_1.default(message ?? 'Fail!', stack);
20
+ throw new AssertionError_1.default(message !== null && message !== void 0 ? message : 'Fail!', stack);
21
21
  },
22
22
  stringify(object) {
23
+ var _a;
23
24
  let stringified;
24
25
  if (Array.isArray(object)) {
25
26
  stringified = `[\n${object.map((o) => this.stringify(o).split('\n').join('\n\t'))}\n]`;
@@ -29,7 +30,7 @@ const assertUtil = {
29
30
  stringified = chalk_1.default.bgBlack.white(` ${object} `);
30
31
  }
31
32
  else if (object instanceof Error) {
32
- stringified = `${object.stack ?? object.message}`;
33
+ stringified = `${(_a = object.stack) !== null && _a !== void 0 ? _a : object.message}`;
33
34
  }
34
35
  else if (object instanceof RegExp) {
35
36
  stringified = `${object.toString()}`;
@@ -112,19 +113,18 @@ const assertUtil = {
112
113
  },
113
114
  assertTypeof(actual, type, message) {
114
115
  if (typeof actual !== type) {
115
- this.fail(message ?? `${JSON.stringify(actual)} is not a ${type}`);
116
+ this.fail(message !== null && message !== void 0 ? message : `${JSON.stringify(actual)} is not a ${type}`);
116
117
  }
117
118
  },
118
119
  checkDoesThrowError(matcher, err, msg) {
119
- const message = err.stack ?? err.message ?? '**MISSING ERROR MESSAGE**';
120
+ var _a, _b;
121
+ const message = (_b = (_a = err.stack) !== null && _a !== void 0 ? _a : err.message) !== null && _b !== void 0 ? _b : '**MISSING ERROR MESSAGE**';
120
122
  if (typeof matcher === 'string' && message.search(matcher) === -1) {
121
- this.fail(msg ??
122
- `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
+ this.fail(msg !== null && msg !== void 0 ? msg : `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
124
  }
124
125
  else if (matcher instanceof RegExp &&
125
126
  message.search(matcher) === -1) {
126
- this.fail(msg ??
127
- `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
+ this.fail(msg !== null && msg !== void 0 ? msg : `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);
128
128
  }
129
129
  },
130
130
  partialContains(object, subObject) {
@@ -163,8 +163,9 @@ const assertUtil = {
163
163
  return { needleHasArrayNotation, path, expected };
164
164
  },
165
165
  splitPathBasedOnArrayNotation(path, haystack) {
166
+ var _a;
166
167
  const pathParts = path.split('[].');
167
- const pathToFirstArray = pathParts.shift() ?? '';
168
+ const pathToFirstArray = (_a = pathParts.shift()) !== null && _a !== void 0 ? _a : '';
168
169
  const pathAfterFirstArray = pathParts.join('[].');
169
170
  const actualBeforeArray = this.valueAtPath(haystack, pathToFirstArray);
170
171
  return { actualBeforeArray, pathAfterFirstArray };
@@ -28,7 +28,7 @@ function test(description, ...args) {
28
28
  hookupTestClass(target);
29
29
  const bound = descriptor.value.bind(target);
30
30
  // Make sure each test gets the spruce
31
- it(description ?? propertyKey, async () => {
31
+ it(description !== null && description !== void 0 ? description : propertyKey, async () => {
32
32
  //@ts-ignore
33
33
  global.activeTest = {
34
34
  file: target.name,
@@ -46,7 +46,7 @@ test.only = (description, ...args) => {
46
46
  hookupTestClass(target);
47
47
  const bound = descriptor.value.bind(target);
48
48
  // Make sure each test gets the spruce
49
- it.only(description ?? propertyKey, async () => {
49
+ it.only(description !== null && description !== void 0 ? description : propertyKey, async () => {
50
50
  return bound(...args);
51
51
  });
52
52
  };
@@ -57,7 +57,7 @@ test.todo = (description, ..._args) => {
57
57
  // Lets attach before/after
58
58
  hookupTestClass(target);
59
59
  // Make sure each test gets the spruce
60
- it.todo(description ?? propertyKey);
60
+ it.todo(description !== null && description !== void 0 ? description : propertyKey);
61
61
  };
62
62
  };
63
63
  /** Skip decorator */
@@ -67,7 +67,7 @@ test.skip = (description, ...args) => {
67
67
  hookupTestClass(target);
68
68
  const bound = descriptor.value.bind(target);
69
69
  // Make sure each test gets the spruce
70
- it.skip(description ?? propertyKey, async () => {
70
+ it.skip(description !== null && description !== void 0 ? description : propertyKey, async () => {
71
71
  return bound(...args);
72
72
  });
73
73
  };
@@ -33,10 +33,11 @@ function removeProps(obj, keys) {
33
33
  }
34
34
  const errorAssert = {
35
35
  assertError(error, expectedCode, expectedPartialOptions) {
36
+ var _a, _b;
36
37
  const spruceErr = error;
37
38
  if (!(spruceErr instanceof error_1.default)) {
38
39
  if (spruceErr instanceof Error || spruceErr.message) {
39
- assert_utility_1.default.fail(`Did not receive a SpruceError, got:\n\nMessage: ${spruceErr.message ?? '***missing***'}`, spruceErr.stack ?? '');
40
+ assert_utility_1.default.fail(`Did not receive a SpruceError, got:\n\nMessage: ${(_a = spruceErr.message) !== null && _a !== void 0 ? _a : '***missing***'}`, (_b = spruceErr.stack) !== null && _b !== void 0 ? _b : '');
40
41
  }
41
42
  else {
42
43
  assert_utility_1.default.fail(`Did not receive a SpruceError, got: \n\n${assert_utility_1.default.stringify(error)}`);
@@ -49,7 +50,7 @@ const errorAssert = {
49
50
  }
50
51
  else {
51
52
  const { code, friendlyMessage, ...options } = spruceErr.options;
52
- assert_utility_1.default.fail(`Invalid error code. Expected:\n\n'${expectedCode}'\n\nbut got:\n\nCode: '${code}'\nMessage: '${friendlyMessage ?? spruceErr.message}'\nOptions:${assert_utility_1.default.stringify(options)}`, spruceErr.stack);
53
+ assert_utility_1.default.fail(`Invalid error code. Expected:\n\n'${expectedCode}'\n\nbut got:\n\nCode: '${code}'\nMessage: '${friendlyMessage !== null && friendlyMessage !== void 0 ? friendlyMessage : spruceErr.message}'\nOptions:${assert_utility_1.default.stringify(options)}`, spruceErr.stack);
53
54
  }
54
55
  },
55
56
  stripFriendlyMessageFromOptions(options) {
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "5.0.8",
6
+ "version": "5.0.10",
7
7
  "files": [
8
8
  "build"
9
9
  ],
@@ -64,7 +64,7 @@
64
64
  "watch.tsc": "tsc -w"
65
65
  },
66
66
  "dependencies": {
67
- "@sprucelabs/error": "^6.0.7",
67
+ "@sprucelabs/error": "^6.0.8",
68
68
  "deep-equal": "^2.2.3",
69
69
  "just-clone": "^6.2.0",
70
70
  "lodash": "^4.17.21",
@@ -72,11 +72,11 @@
72
72
  "variable-diff": "^2.0.2"
73
73
  },
74
74
  "devDependencies": {
75
- "@sprucelabs/esm-postbuild": "^6.0.7",
76
- "@sprucelabs/jest-json-reporter": "^8.0.5",
75
+ "@sprucelabs/esm-postbuild": "^6.0.8",
76
+ "@sprucelabs/jest-json-reporter": "^8.0.7",
77
77
  "@sprucelabs/jest-sheets-reporter": "^2.0.20",
78
78
  "@sprucelabs/semantic-release": "^5.0.1",
79
- "@sprucelabs/test": "^9.0.6",
79
+ "@sprucelabs/test": "^9.0.7",
80
80
  "@types/deep-equal": "^1.0.4",
81
81
  "@types/jest": "^29.5.12",
82
82
  "@types/lodash": "^4.17.0",