@sprucelabs/test-utils 5.1.429 → 5.1.431

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.
@@ -6,12 +6,12 @@ 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 = message;
12
11
  this.stack =
13
12
  this.message +
14
- StackCleaner_1.default.clean(`${((_a = stack !== null && stack !== void 0 ? stack : this.stack) !== null && _a !== void 0 ? _a : '').replace(message, '')}`);
13
+ '\n' +
14
+ StackCleaner_1.default.clean(`${(stack ?? this.stack ?? '').replace(message, '')}`);
15
15
  }
16
16
  }
17
17
  exports.default = AssertionError;
@@ -244,6 +244,6 @@ const assert = {
244
244
  exports.default = assert;
245
245
  function buildErrorMessage(defaultMessage, customMessage) {
246
246
  return customMessage
247
- ? `${customMessage}\n${defaultMessage}\n`
248
- : defaultMessage + '\n';
247
+ ? `${customMessage}\n${defaultMessage}`
248
+ : defaultMessage;
249
249
  }
@@ -17,10 +17,9 @@ 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 !== null && message !== void 0 ? message : 'Fail!', stack);
20
+ throw new AssertionError_1.default(message ?? 'Fail!', stack);
21
21
  },
22
22
  stringify(object) {
23
- var _a;
24
23
  let stringified;
25
24
  if (Array.isArray(object)) {
26
25
  stringified = `[\n${object.map((o) => this.stringify(o).split('\n').join('\n\t'))}\n]`;
@@ -30,7 +29,7 @@ const assertUtil = {
30
29
  stringified = chalk_1.default.bgBlack.white(` ${object} `);
31
30
  }
32
31
  else if (object instanceof Error) {
33
- stringified = `${(_a = object.stack) !== null && _a !== void 0 ? _a : object.message}`;
32
+ stringified = `${object.stack ?? object.message}`;
34
33
  }
35
34
  else if (object instanceof RegExp) {
36
35
  stringified = `${object.toString()}`;
@@ -113,23 +112,24 @@ const assertUtil = {
113
112
  },
114
113
  assertTypeof(actual, type, message) {
115
114
  if (typeof actual !== type) {
116
- this.fail(message !== null && message !== void 0 ? message : `${JSON.stringify(actual)} is not a ${type}`);
115
+ this.fail(message ?? `${JSON.stringify(actual)} is not a ${type}`);
117
116
  }
118
117
  },
119
118
  assertErrorIncludes(matcher, err, msg) {
120
- var _a;
121
- const originalErrorMessage = (_a = err.message) !== null && _a !== void 0 ? _a : '';
119
+ const originalErrorMessage = err.message ?? '';
122
120
  const errorMessage = originalErrorMessage.toLowerCase();
123
121
  const needle = typeof matcher === 'string' ? matcher.toLowerCase() : matcher;
124
122
  if (typeof needle === 'string' &&
125
123
  errorMessage.search(needle) === -1 &&
126
124
  !errorMessage.includes(needle)) {
127
- 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(originalErrorMessage)}\`.`, '\n\nStack: ' + err.stack);
125
+ this.fail(msg ??
126
+ `Expected thrown error whose message contains: \n\n${chalk_1.default.bold(matcher)}\n\nbut got back:\n\n\`${chalk_1.default.bold(originalErrorMessage)}\`.`, '\n\nStack: ' + err.stack);
128
127
  }
129
128
  else if (needle instanceof RegExp &&
130
129
  errorMessage.search(needle) === -1 &&
131
130
  originalErrorMessage.search(needle) === -1) {
132
- 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(originalErrorMessage)}\`.`, '\n\nStack: ' + err.stack);
131
+ this.fail(msg ??
132
+ `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(originalErrorMessage)}\`.`, '\n\nStack: ' + err.stack);
133
133
  }
134
134
  },
135
135
  partialContains(object, subObject) {
@@ -168,9 +168,8 @@ const assertUtil = {
168
168
  return { needleHasArrayNotation, path, expected };
169
169
  },
170
170
  splitPathBasedOnArrayNotation(path, haystack) {
171
- var _a;
172
171
  const pathParts = path.split('[].');
173
- const pathToFirstArray = (_a = pathParts.shift()) !== null && _a !== void 0 ? _a : '';
172
+ const pathToFirstArray = pathParts.shift() ?? '';
174
173
  const pathAfterFirstArray = pathParts.join('[].');
175
174
  const actualBeforeArray = this.valueAtPath(haystack, pathToFirstArray);
176
175
  return { actualBeforeArray, pathAfterFirstArray };
@@ -33,7 +33,7 @@ function test(description, ...args) {
33
33
  hookupTestClass(target);
34
34
  const bound = descriptor.value.bind(target);
35
35
  // Make sure each test gets the spruce
36
- it(description !== null && description !== void 0 ? description : propertyKey, async () => {
36
+ it(description ?? propertyKey, async () => {
37
37
  //@ts-ignore
38
38
  global.activeTest = {
39
39
  file: target.name,
@@ -50,7 +50,7 @@ test.only = (description, ...args) => {
50
50
  hookupTestClass(target);
51
51
  const bound = descriptor.value.bind(target);
52
52
  // Make sure each test gets the spruce
53
- it.only(description !== null && description !== void 0 ? description : propertyKey, async () => {
53
+ it.only(description ?? propertyKey, async () => {
54
54
  return bound(...args);
55
55
  });
56
56
  };
@@ -61,7 +61,7 @@ test.todo = (description, ..._args) => {
61
61
  // Lets attach before/after
62
62
  hookupTestClass(target);
63
63
  // Make sure each test gets the spruce
64
- it.todo(description !== null && description !== void 0 ? description : propertyKey);
64
+ it.todo(description ?? propertyKey);
65
65
  };
66
66
  };
67
67
  /** Skip decorator */
@@ -71,7 +71,7 @@ test.skip = (description, ...args) => {
71
71
  hookupTestClass(target);
72
72
  const bound = descriptor.value.bind(target);
73
73
  // Make sure each test gets the spruce
74
- it.skip(description !== null && description !== void 0 ? description : propertyKey, async () => {
74
+ it.skip(description ?? propertyKey, async () => {
75
75
  return bound(...args);
76
76
  });
77
77
  };
@@ -6,6 +6,7 @@ export default class AssertionError extends Error {
6
6
  this.message = message;
7
7
  this.stack =
8
8
  this.message +
9
+ '\n' +
9
10
  StackCleaner.clean(`${((_a = stack !== null && stack !== void 0 ? stack : this.stack) !== null && _a !== void 0 ? _a : '').replace(message, '')}`);
10
11
  }
11
12
  }
@@ -239,6 +239,6 @@ const assert = {
239
239
  export default assert;
240
240
  function buildErrorMessage(defaultMessage, customMessage) {
241
241
  return customMessage
242
- ? `${customMessage}\n${defaultMessage}\n`
243
- : defaultMessage + '\n';
242
+ ? `${customMessage}\n${defaultMessage}`
243
+ : defaultMessage;
244
244
  }
@@ -33,11 +33,10 @@ function removeProps(obj, keys) {
33
33
  }
34
34
  const errorAssert = {
35
35
  assertError(error, expectedCode, expectedPartialOptions) {
36
- var _a, _b;
37
36
  const spruceErr = error;
38
37
  if (!(spruceErr instanceof error_1.default)) {
39
38
  if (spruceErr instanceof Error || spruceErr.message) {
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 : '');
39
+ assert_utility_1.default.fail(`Did not receive a SpruceError, got:\n\nMessage: ${spruceErr.message ?? '***missing***'}`, spruceErr.stack ?? '');
41
40
  }
42
41
  else {
43
42
  assert_utility_1.default.fail(`Did not receive a SpruceError, got: \n\n${assert_utility_1.default.stringify(error)}`);
@@ -50,7 +49,7 @@ const errorAssert = {
50
49
  }
51
50
  else {
52
51
  const { code, friendlyMessage, ...options } = spruceErr.options;
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);
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);
54
53
  }
55
54
  },
56
55
  stripFriendlyMessageFromOptions(options) {
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "5.1.429",
6
+ "version": "5.1.431",
7
7
  "files": [
8
8
  "build"
9
9
  ],
@@ -60,7 +60,7 @@
60
60
  "watch.tsc": "tsc -w"
61
61
  },
62
62
  "dependencies": {
63
- "@sprucelabs/error": "^6.0.477",
63
+ "@sprucelabs/error": "^6.0.478",
64
64
  "deep-equal": "^2.2.3",
65
65
  "just-clone": "^6.2.0",
66
66
  "lodash": "^4.17.21",
@@ -68,15 +68,15 @@
68
68
  "variable-diff": "^2.0.2"
69
69
  },
70
70
  "devDependencies": {
71
- "@sprucelabs/esm-postbuild": "^6.0.460",
72
- "@sprucelabs/jest-json-reporter": "^8.0.476",
71
+ "@sprucelabs/esm-postbuild": "^6.0.461",
72
+ "@sprucelabs/jest-json-reporter": "^8.0.478",
73
73
  "@sprucelabs/jest-sheets-reporter": "^2.0.20",
74
74
  "@sprucelabs/semantic-release": "^5.0.2",
75
- "@sprucelabs/test": "^9.0.50",
75
+ "@sprucelabs/test": "^9.0.51",
76
76
  "@types/deep-equal": "^1.0.4",
77
77
  "@types/jest": "^29.5.13",
78
78
  "@types/lodash": "^4.17.10",
79
- "@types/node": "^22.7.5",
79
+ "@types/node": "^22.7.6",
80
80
  "chokidar-cli": "^3.0.0",
81
81
  "eslint": "^9.12.0",
82
82
  "eslint-config-spruce": "^11.2.26",