@sprucelabs/test 9.0.5 → 9.0.7

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;
@@ -21,49 +21,44 @@ const assert = {
21
21
  isExactType,
22
22
  isNumber(actual, message) {
23
23
  if (typeof actual !== 'number') {
24
- this.fail(message ?? `${stringify(actual)} is not a number!`);
24
+ this.fail(message !== null && message !== void 0 ? 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 ??
30
- `${stringify(actual)} does not equal ${stringify(expected)}`);
29
+ this.fail(message !== null && message !== void 0 ? message : `${stringify(actual)} does not equal ${stringify(expected)}`);
31
30
  }
32
31
  },
33
32
  isNotEqual(actual, expected, message) {
34
33
  if (actual === expected) {
35
- this.fail(message ??
36
- `${stringify(actual)} should not equal ${stringify(expected)}`);
34
+ this.fail(message !== null && message !== void 0 ? message : `${stringify(actual)} should not equal ${stringify(expected)}`);
37
35
  }
38
36
  },
39
37
  isEqualDeep(actual, expected, message, shouldAppendDelta = true) {
40
38
  if (!(0, deep_equal_1.default)(actual, expected, { strict: true })) {
41
39
  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}` : ``}`);
40
+ 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}` : ``}`);
44
41
  }
45
42
  },
46
43
  isAbove(actual, floor, message) {
47
44
  if (typeof actual !== 'number') {
48
- this.fail(message ?? `${stringify(actual)} is not a number!`);
45
+ this.fail(message !== null && message !== void 0 ? message : `${stringify(actual)} is not a number!`);
49
46
  }
50
47
  if (actual <= floor) {
51
- this.fail(message ??
52
- `${stringify(actual)} is not above ${stringify(floor)}`);
48
+ this.fail(message !== null && message !== void 0 ? message : `${stringify(actual)} is not above ${stringify(floor)}`);
53
49
  }
54
50
  },
55
51
  isBelow(actual, ceiling, message) {
56
52
  if (typeof actual !== 'number') {
57
- this.fail(message ?? `${stringify(actual)} is not a number!`);
53
+ this.fail(message !== null && message !== void 0 ? message : `${stringify(actual)} is not a number!`);
58
54
  }
59
55
  if (actual >= ceiling) {
60
- this.fail(message ??
61
- `${stringify(actual)} is not below ${stringify(ceiling)}`);
56
+ this.fail(message !== null && message !== void 0 ? message : `${stringify(actual)} is not below ${stringify(ceiling)}`);
62
57
  }
63
58
  },
64
59
  isUndefined(actual, message) {
65
60
  if (typeof actual !== 'undefined') {
66
- this.fail(message ?? `${stringify(actual)} is not undefined`);
61
+ this.fail(message !== null && message !== void 0 ? message : `${stringify(actual)} is not undefined`);
67
62
  }
68
63
  },
69
64
  isTruthy(actual, message) {
@@ -71,17 +66,17 @@ const assert = {
71
66
  actual === null ||
72
67
  typeof actual === 'undefined' ||
73
68
  actual === 0) {
74
- this.fail(message ?? `${stringify(actual)} is not truthy`);
69
+ this.fail(message !== null && message !== void 0 ? message : `${stringify(actual)} is not truthy`);
75
70
  }
76
71
  },
77
72
  isFalsy(actual, message) {
78
73
  if (actual) {
79
- this.fail(message ?? `${stringify(actual)} is not falsy`);
74
+ this.fail(message !== null && message !== void 0 ? message : `${stringify(actual)} is not falsy`);
80
75
  }
81
76
  },
82
77
  isNull(actual, message) {
83
78
  if (actual !== null) {
84
- this.fail(message ?? `${stringify(actual)} is not null`);
79
+ this.fail(message !== null && message !== void 0 ? message : `${stringify(actual)} is not null`);
85
80
  }
86
81
  },
87
82
  isString(actual, message) {
@@ -100,22 +95,20 @@ const assert = {
100
95
  },
101
96
  isObject(actual, message) {
102
97
  if (!(0, isObjectLike_1.default)(actual)) {
103
- 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`);
104
99
  }
105
100
  },
106
101
  isArray(actual, message) {
107
102
  if (!Array.isArray(actual)) {
108
- 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`);
109
104
  }
110
105
  },
111
106
  isLength(actual, expected, message) {
112
107
  if (!actual) {
113
- throw this.fail(message ??
114
- `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)}`);
115
109
  }
116
110
  //@ts-ignore
117
- this.isEqual(actual.length, expected, message ??
118
- `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)}`);
119
112
  },
120
113
  doesNotInclude(haystack, needle, message) {
121
114
  let doesInclude = false;
@@ -127,13 +120,11 @@ const assert = {
127
120
  doesInclude = false;
128
121
  }
129
122
  if (doesInclude) {
130
- this.fail(message ??
131
- `${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`);
132
124
  }
133
125
  },
134
126
  doesInclude(haystack, needle, message) {
135
- let msg = message ??
136
- `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)}`;
137
128
  const isNeedleString = typeof needle === 'string';
138
129
  const isNeedleRegex = needle instanceof RegExp;
139
130
  if (typeof haystack === 'string' &&
@@ -16,9 +16,10 @@ 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 ?? 'Fail!', stack);
19
+ throw new AssertionError_1.default(message !== null && message !== void 0 ? message : 'Fail!', stack);
20
20
  },
21
21
  stringify(object) {
22
+ var _a;
22
23
  let stringified;
23
24
  if (Array.isArray(object)) {
24
25
  stringified = `[\n${object.map((o) => this.stringify(o).split('\n').join('\n\t'))}\n]`;
@@ -28,7 +29,7 @@ const assertUtil = {
28
29
  stringified = chalk_1.default.bgBlack.white(` ${object} `);
29
30
  }
30
31
  else if (object instanceof Error) {
31
- stringified = `${object.stack ?? object.message}`;
32
+ stringified = `${(_a = object.stack) !== null && _a !== void 0 ? _a : object.message}`;
32
33
  }
33
34
  else if (object instanceof RegExp) {
34
35
  stringified = `${object.toString()}`;
@@ -111,19 +112,18 @@ const assertUtil = {
111
112
  },
112
113
  assertTypeof(actual, type, message) {
113
114
  if (typeof actual !== type) {
114
- this.fail(message ?? `${JSON.stringify(actual)} is not a ${type}`);
115
+ this.fail(message !== null && message !== void 0 ? message : `${JSON.stringify(actual)} is not a ${type}`);
115
116
  }
116
117
  },
117
118
  checkDoesThrowError(matcher, err, msg) {
118
- const message = err.stack ?? err.message ?? '**MISSING ERROR MESSAGE**';
119
+ var _a, _b;
120
+ const message = (_b = (_a = err.stack) !== null && _a !== void 0 ? _a : err.message) !== null && _b !== void 0 ? _b : '**MISSING ERROR MESSAGE**';
119
121
  if (typeof matcher === 'string' && message.search(matcher) === -1) {
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
+ 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);
122
123
  }
123
124
  else if (matcher instanceof RegExp &&
124
125
  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);
126
+ 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);
127
127
  }
128
128
  },
129
129
  partialContains(object, subObject) {
@@ -162,8 +162,9 @@ const assertUtil = {
162
162
  return { needleHasArrayNotation, path, expected };
163
163
  },
164
164
  splitPathBasedOnArrayNotation(path, haystack) {
165
+ var _a;
165
166
  const pathParts = path.split('[].');
166
- const pathToFirstArray = pathParts.shift() ?? '';
167
+ const pathToFirstArray = (_a = pathParts.shift()) !== null && _a !== void 0 ? _a : '';
167
168
  const pathAfterFirstArray = pathParts.join('[].');
168
169
  const actualBeforeArray = this.valueAtPath(haystack, pathToFirstArray);
169
170
  return { actualBeforeArray, pathAfterFirstArray };
@@ -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 ?? propertyKey, async () => {
35
+ it(description !== null && description !== void 0 ? description : propertyKey, async () => {
36
36
  //@ts-ignore
37
37
  global.activeTest = {
38
38
  file: target.name,
@@ -52,7 +52,7 @@ test.only = (description, ...args) => {
52
52
  hookupTestClass(target);
53
53
  const bound = descriptor.value.bind(target);
54
54
  // Make sure each test gets the spruce
55
- it.only(description ?? propertyKey, async () => {
55
+ it.only(description !== null && description !== void 0 ? description : propertyKey, async () => {
56
56
  return bound(...args);
57
57
  });
58
58
  };
@@ -65,7 +65,7 @@ test.todo = (description, ..._args) => {
65
65
  // Lets attach before/after
66
66
  hookupTestClass(target);
67
67
  // Make sure each test gets the spruce
68
- it.todo(description ?? propertyKey);
68
+ it.todo(description !== null && description !== void 0 ? description : propertyKey);
69
69
  };
70
70
  };
71
71
  /**
@@ -77,7 +77,7 @@ test.skip = (description, ...args) => {
77
77
  hookupTestClass(target);
78
78
  const bound = descriptor.value.bind(target);
79
79
  // Make sure each test gets the spruce
80
- it.skip(description ?? propertyKey, async () => {
80
+ it.skip(description !== null && description !== void 0 ? description : propertyKey, async () => {
81
81
  return bound(...args);
82
82
  });
83
83
  };
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "9.0.5",
6
+ "version": "9.0.7",
7
7
  "skill": {
8
8
  "namespace": "spruce-test",
9
9
  "upgradeIgnoreList": [
@@ -84,8 +84,8 @@
84
84
  "@types/deep-equal": "^1.0.4",
85
85
  "@types/jest": "^29.5.12",
86
86
  "@types/lodash": "^4.17.0",
87
- "eslint": "^9.1.0",
88
- "eslint-config-spruce": "^11.2.11",
87
+ "eslint": "^9.1.1",
88
+ "eslint-config-spruce": "^11.2.12",
89
89
  "prettier": "^3.2.5",
90
90
  "tsc-watch": "^6.2.0",
91
91
  "tsconfig-paths": "^4.2.0",