assertron 7.1.3 → 9.0.2

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.
Files changed (143) hide show
  1. package/LICENSE +2 -2
  2. package/README.md +11 -29
  3. package/package.json +48 -34
  4. package/src/assert-order/AssertOrder.spec.ts +10 -11
  5. package/src/assert-order/AssertOrder.ts +7 -7
  6. package/src/assert-order/InvalidOrder.ts +6 -8
  7. package/src/assert-order/StateMachine.ts +4 -4
  8. package/src/assert-order/index.ts +3 -1
  9. package/src/assert-order/{interfaces.ts → types.ts} +0 -0
  10. package/src/assertron/assertron.spec.ts +2 -3
  11. package/src/assertron/assertron.ts +13 -14
  12. package/src/assertron/falsy.spec.ts +2 -3
  13. package/src/assertron/falsy.ts +2 -6
  14. package/src/assertron/pathEqual.spec.ts +2 -3
  15. package/src/assertron/pathEqual.ts +4 -7
  16. package/src/assertron/rejects.spec.ts +7 -8
  17. package/src/assertron/rejects.ts +3 -9
  18. package/src/assertron/repeat.spec.ts +7 -9
  19. package/src/assertron/repeat.ts +4 -9
  20. package/src/assertron/resolves.spec.ts +3 -4
  21. package/src/assertron/resolves.ts +3 -10
  22. package/src/assertron/satisfies.spec.ts +53 -21
  23. package/src/assertron/satisfies.ts +23 -10
  24. package/src/assertron/throws.spec.ts +46 -35
  25. package/src/assertron/throws.ts +29 -53
  26. package/src/assertron/truthy.spec.ts +2 -3
  27. package/src/assertron/truthy.ts +2 -3
  28. package/src/errors.ts +22 -0
  29. package/src/index.ts +2 -1
  30. package/src/testUtils.ts +16 -13
  31. package/src/{errors/interfaces.ts → types.ts} +0 -0
  32. package/src/utils/index.ts +12 -0
  33. package/src/{errors/util.ts → utils/isErrorConstructor.ts} +1 -1
  34. package/src/utils/notEqualMessage.ts +4 -0
  35. package/src/{errors → utils}/notSatisfiedMessage.spec.ts +0 -0
  36. package/src/{errors/NotSatisfied.ts → utils/notSatisfiedMessage.ts} +0 -0
  37. package/src/{errors → utils}/notThrownMessage.ts +0 -0
  38. package/src/utils/promiseMessages.ts +12 -0
  39. package/src/{errors → utils}/unexpectedErrorMessage.ts +4 -3
  40. package/lib/assert-order/AssertOrder.d.ts +0 -41
  41. package/lib/assert-order/AssertOrder.d.ts.map +0 -1
  42. package/lib/assert-order/AssertOrder.js +0 -147
  43. package/lib/assert-order/InvalidOrder.d.ts +0 -6
  44. package/lib/assert-order/InvalidOrder.d.ts.map +0 -1
  45. package/lib/assert-order/InvalidOrder.js +0 -43
  46. package/lib/assert-order/StateMachine.d.ts +0 -22
  47. package/lib/assert-order/StateMachine.d.ts.map +0 -1
  48. package/lib/assert-order/StateMachine.js +0 -109
  49. package/lib/assert-order/index.d.ts +0 -3
  50. package/lib/assert-order/index.d.ts.map +0 -1
  51. package/lib/assert-order/index.js +0 -5
  52. package/lib/assert-order/interfaces.d.ts +0 -8
  53. package/lib/assert-order/interfaces.d.ts.map +0 -1
  54. package/lib/assert-order/interfaces.js +0 -3
  55. package/lib/assertron/assertron.d.ts +0 -21
  56. package/lib/assertron/assertron.d.ts.map +0 -1
  57. package/lib/assertron/assertron.js +0 -31
  58. package/lib/assertron/falsy.d.ts +0 -2
  59. package/lib/assertron/falsy.d.ts.map +0 -1
  60. package/lib/assertron/falsy.js +0 -10
  61. package/lib/assertron/index.d.ts +0 -2
  62. package/lib/assertron/index.d.ts.map +0 -1
  63. package/lib/assertron/index.js +0 -5
  64. package/lib/assertron/pathEqual.d.ts +0 -2
  65. package/lib/assertron/pathEqual.d.ts.map +0 -1
  66. package/lib/assertron/pathEqual.js +0 -12
  67. package/lib/assertron/rejects.d.ts +0 -2
  68. package/lib/assertron/rejects.d.ts.map +0 -1
  69. package/lib/assertron/rejects.js +0 -13
  70. package/lib/assertron/repeat.d.ts +0 -12
  71. package/lib/assertron/repeat.d.ts.map +0 -1
  72. package/lib/assertron/repeat.js +0 -43
  73. package/lib/assertron/resolves.d.ts +0 -2
  74. package/lib/assertron/resolves.d.ts.map +0 -1
  75. package/lib/assertron/resolves.js +0 -16
  76. package/lib/assertron/satisfies.d.ts +0 -6
  77. package/lib/assertron/satisfies.d.ts.map +0 -1
  78. package/lib/assertron/satisfies.js +0 -18
  79. package/lib/assertron/throws.d.ts +0 -6
  80. package/lib/assertron/throws.d.ts.map +0 -1
  81. package/lib/assertron/throws.js +0 -59
  82. package/lib/assertron/truthy.d.ts +0 -2
  83. package/lib/assertron/truthy.d.ts.map +0 -1
  84. package/lib/assertron/truthy.js +0 -10
  85. package/lib/errors/NotSatisfied.d.ts +0 -3
  86. package/lib/errors/NotSatisfied.d.ts.map +0 -1
  87. package/lib/errors/NotSatisfied.js +0 -27
  88. package/lib/errors/index.d.ts +0 -8
  89. package/lib/errors/index.d.ts.map +0 -1
  90. package/lib/errors/index.js +0 -10
  91. package/lib/errors/interfaces.d.ts +0 -3
  92. package/lib/errors/interfaces.d.ts.map +0 -1
  93. package/lib/errors/interfaces.js +0 -3
  94. package/lib/errors/notEqualMessage.d.ts +0 -2
  95. package/lib/errors/notEqualMessage.d.ts.map +0 -1
  96. package/lib/errors/notEqualMessage.js +0 -7
  97. package/lib/errors/notRejectedMessage.d.ts +0 -2
  98. package/lib/errors/notRejectedMessage.d.ts.map +0 -1
  99. package/lib/errors/notRejectedMessage.js +0 -7
  100. package/lib/errors/notThrownMessage.d.ts +0 -2
  101. package/lib/errors/notThrownMessage.d.ts.map +0 -1
  102. package/lib/errors/notThrownMessage.js +0 -8
  103. package/lib/errors/returnNotRejectedMessage.d.ts +0 -2
  104. package/lib/errors/returnNotRejectedMessage.d.ts.map +0 -1
  105. package/lib/errors/returnNotRejectedMessage.js +0 -7
  106. package/lib/errors/unexpectedErrorMessage.d.ts +0 -3
  107. package/lib/errors/unexpectedErrorMessage.d.ts.map +0 -1
  108. package/lib/errors/unexpectedErrorMessage.js +0 -9
  109. package/lib/errors/util.d.ts +0 -3
  110. package/lib/errors/util.d.ts.map +0 -1
  111. package/lib/errors/util.js +0 -7
  112. package/lib/index.d.ts +0 -5
  113. package/lib/index.d.ts.map +0 -1
  114. package/lib/index.js +0 -8
  115. package/libm/assert-order/AssertOrder.js +0 -132
  116. package/libm/assert-order/InvalidOrder.js +0 -31
  117. package/libm/assert-order/StateMachine.js +0 -102
  118. package/libm/assert-order/index.js +0 -2
  119. package/libm/assert-order/interfaces.js +0 -1
  120. package/libm/assertron/assertron.js +0 -28
  121. package/libm/assertron/falsy.js +0 -6
  122. package/libm/assertron/index.js +0 -2
  123. package/libm/assertron/pathEqual.js +0 -8
  124. package/libm/assertron/rejects.js +0 -9
  125. package/libm/assertron/repeat.js +0 -35
  126. package/libm/assertron/resolves.js +0 -12
  127. package/libm/assertron/satisfies.js +0 -14
  128. package/libm/assertron/throws.js +0 -55
  129. package/libm/assertron/truthy.js +0 -6
  130. package/libm/errors/NotSatisfied.js +0 -23
  131. package/libm/errors/index.js +0 -7
  132. package/libm/errors/interfaces.js +0 -1
  133. package/libm/errors/notEqualMessage.js +0 -4
  134. package/libm/errors/notRejectedMessage.js +0 -4
  135. package/libm/errors/notThrownMessage.js +0 -5
  136. package/libm/errors/returnNotRejectedMessage.js +0 -4
  137. package/libm/errors/unexpectedErrorMessage.js +0 -6
  138. package/libm/errors/util.js +0 -4
  139. package/libm/index.js +0 -5
  140. package/src/errors/index.ts +0 -7
  141. package/src/errors/notEqualMessage.ts +0 -3
  142. package/src/errors/notRejectedMessage.ts +0 -3
  143. package/src/errors/returnNotRejectedMessage.ts +0 -3
package/LICENSE CHANGED
@@ -14,8 +14,8 @@ all copies or substantial portions of the Software.
14
14
 
15
15
  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
16
  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES, OR OTHER
19
19
  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
20
  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
21
  THE SOFTWARE.
package/README.md CHANGED
@@ -9,7 +9,6 @@
9
9
  [![Codecov][codecov-image]][codecov-url]
10
10
  [![Coverage Status][coveralls-image]][coveralls-url]
11
11
 
12
- [![Greenkeeper][greenkeeper-image]][greenkeeper-url]
13
12
  [![Semantic Release][semantic-release-image]][semantic-release-url]
14
13
 
15
14
  [![Visual Studio Code][vscode-image]][vscode-url]
@@ -26,7 +25,7 @@ Asserts the provided value is false.
26
25
 
27
26
  ### assertron.falsy(value)
28
27
 
29
- Asserts the provides value is falsy.
28
+ Asserts the provided value is falsy.
30
29
 
31
30
  ### assertron.pathEqual(actual, expected)
32
31
 
@@ -50,7 +49,7 @@ Asserts the promise resolves.
50
49
  `assertron.satisfies()` checks if `actual` meets the requirements specified by `expected`.
51
50
  Each property in `expected` can be a value, a `RegExp`, or a predicate function.
52
51
  It uses `satisfier` internally to check for validity.
53
- Check out [`sateisfier`](https://github.com/unional/satisfier) for more detail.
52
+ Check out [`satisfier`](https://github.com/unional/satisfier) for more detail.
54
53
 
55
54
  ```ts
56
55
  import a from 'assertron' // assertron is also exported as default.
@@ -69,7 +68,7 @@ a.satisfies({ a: 1 }, { a: () => false })
69
68
 
70
69
  ### assertron.throws(...)
71
70
 
72
- Asserts the promise, function, or async function throws (or reject) an error.
71
+ Asserts the promise, function, or async function throws (or rejects) an error.
73
72
 
74
73
  ```ts
75
74
  import { assertron } from 'assertron'
@@ -93,7 +92,7 @@ Asserts the provided value is truthy.
93
92
 
94
93
  ## AssertOrder
95
94
 
96
- Assert code are executed in expected order.
95
+ Assert the code is executed in the expected order.
97
96
 
98
97
  ### order.once(step: number)
99
98
 
@@ -129,7 +128,7 @@ boo()
129
128
 
130
129
  ### order.atLeastOnce(step: number)
131
130
 
132
- Assert step `step` have executed at least once.
131
+ Assert the `step` executed at least once.
133
132
 
134
133
  ```ts
135
134
  import { AssertOrder } from 'assertron'
@@ -178,14 +177,11 @@ There are other methods available. Use TypeScript to discover them!
178
177
  ## Contribute
179
178
 
180
179
  ```sh
181
- # right after fork
182
- npm install
180
+ yarn
183
181
 
184
- # begin making changes
182
+ # start making changes
185
183
  git checkout -b <branch>
186
- npm run watch
187
-
188
- # edit `webpack.config.dev.js` to exclude dependencies for the global build.
184
+ yarn watch
189
185
 
190
186
  # after making change(s)
191
187
  git commit -m "<commit message>"
@@ -199,23 +195,11 @@ git push
199
195
  There are a few useful commands you can use during development.
200
196
 
201
197
  ```sh
202
- # Run tests (and lint) automatically whenever you save a file.
203
- npm run watch
204
-
205
- # Run tests with coverage stats (but won't fail you if coverage does not meet criteria)
206
- npm run test
207
-
208
- # Manually verify the project.
209
- # This will be ran during 'npm preversion' so you normally don't need to run this yourself.
210
- npm run verify
198
+ yarn test
211
199
 
212
- # Build the project.
213
- # You normally don't need to do this.
214
- npm run build
200
+ yarn watch
215
201
 
216
- # Run tslint
217
- # You normally don't need to do this as `npm run watch` and `npm version` will automatically run lint for you.
218
- npm run lint
202
+ yarn verify
219
203
  ```
220
204
 
221
205
  [npm-image]: https://img.shields.io/npm/v/assertron.svg?style=flat
@@ -230,8 +214,6 @@ npm run lint
230
214
  [coveralls-image]: https://coveralls.io/repos/github/unional/assertron/badge.svg
231
215
  [coveralls-url]: https://coveralls.io/github/unional/assertron
232
216
 
233
- [greenkeeper-image]: https://badges.greenkeeper.io/unional/assertron.svg
234
- [greenkeeper-url]: https://greenkeeper.io/
235
217
  [semantic-release-image]: https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg
236
218
  [semantic-release-url]: https://github.com/semantic-release/semantic-release
237
219
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "assertron",
3
- "version": "7.1.3",
3
+ "version": "9.0.2",
4
4
  "description": "A supplementary assertion library",
5
5
  "homepage": "https://github.com/unional/assertron",
6
6
  "bugs": {
@@ -16,31 +16,29 @@
16
16
  "email": "homawong@gmail.com"
17
17
  },
18
18
  "sideEffects": false,
19
- "main": "lib/index.js",
20
- "module": "libm/index.js",
21
- "jsnext:main": "libm/index.js",
19
+ "main": "cjs/index.js",
20
+ "module": "esm/index.js",
21
+ "jsnext:main": "esm/index.js",
22
22
  "browser": {
23
23
  "perf_hooks": false
24
24
  },
25
- "typings": "lib/index.d.ts",
25
+ "typings": "cjs/index.d.ts",
26
26
  "files": [
27
- "lib",
28
- "libm",
27
+ "cjs",
28
+ "esm",
29
29
  "src"
30
30
  ],
31
31
  "scripts": {
32
- "build": "yarn build:libm && yarn build:lib",
33
- "build:lib": "tsc -p tsconfig.lib.json",
34
- "build:libm": "tsc -p tsconfig.libm.json",
32
+ "build": "yarn build:esm && yarn build:cjs",
33
+ "build:cjs": "tsc -p tsconfig.cjs.json",
34
+ "build:esm": "tsc -p tsconfig.esm.json",
35
35
  "build:watch": "tsc --watch",
36
- "clean": "rimraf .nyc_output .ts coverage lib libm",
37
- "codacy": "cat coverage/lcov.info | codacy-coverage",
36
+ "clean": "rimraf .nyc_output .ts coverage cjs esm lib libm",
38
37
  "coverage": "jest --coverage",
39
38
  "depcheck": "yarn dependency-check",
40
- "dependency-check": "dependency-check . --unused --no-dev -i global-store -i @types/node -i standard-log-color && dependency-check . --missing --no-dev",
39
+ "dependency-check": "dependency-check . --unused --no-dev -i type-plus -i global-store -i @types/node -i standard-log-color && dependency-check . --missing --no-dev",
41
40
  "lint": "eslint --ext=js,ts .",
42
41
  "nuke": "yarn clean && rimraf node_modules",
43
- "semantic-release": "semantic-release",
44
42
  "test": "jest",
45
43
  "test:watch": "jest --watch",
46
44
  "verify": "yarn lint && yarn build && yarn dependency-check && yarn coverage",
@@ -52,28 +50,44 @@
52
50
  }
53
51
  },
54
52
  "dependencies": {
55
- "assertion-error": "^1.1.0",
56
53
  "is-node": "^1.0.2",
57
- "is-promise": "^2.1.0",
58
- "path-equal": "^1.1.1",
59
- "satisfier": "^5.1.0",
60
- "tersify": "^3.7.0",
61
- "tslib": "^1.11.1"
54
+ "is-promise": "^4.0.0",
55
+ "iso-error": "^4.1.0",
56
+ "path-equal": "^1.1.3",
57
+ "satisfier": "^5.1.1",
58
+ "tersify": "^3.7.11",
59
+ "tslib": "^2.3.1",
60
+ "type-plus": "^4.0.0"
62
61
  },
63
62
  "devDependencies": {
64
- "@babel/core": "^7.8.6",
65
- "@babel/plugin-proposal-nullish-coalescing-operator": "^7.8.3",
66
- "@babel/plugin-proposal-optional-chaining": "^7.8.3",
67
- "@babel/preset-env": "^7.8.6",
68
- "@babel/preset-typescript": "^7.8.3",
69
- "@commitlint/cli": "^8.3.5",
70
- "@commitlint/config-conventional": "^8.3.4",
71
- "@types/lodash": "^4.14.149",
72
- "@unional/devpkg-node": "^1.5.0",
73
- "codacy-coverage": "^3.4.0",
74
- "commitlint-circle": "^1.0.0",
75
- "husky": "^4.2.3",
76
- "lodash": "^4.17.15",
77
- "semantic-release": "^17.0.4"
63
+ "@babel/core": "^7.16.5",
64
+ "@babel/plugin-proposal-nullish-coalescing-operator": "^7.16.5",
65
+ "@babel/plugin-proposal-optional-chaining": "^7.16.5",
66
+ "@babel/preset-env": "^7.16.5",
67
+ "@babel/preset-typescript": "^7.16.5",
68
+ "@commitlint/cli": "^16.0.0",
69
+ "@commitlint/config-conventional": "^16.0.0",
70
+ "@types/jest": "^27.0.3",
71
+ "@types/lodash": "^4.14.178",
72
+ "@types/node": "^17.0.4",
73
+ "@typescript-eslint/eslint-plugin": "^5.8.0",
74
+ "@typescript-eslint/parser": "^5.8.0",
75
+ "babel-jest": "^27.4.5",
76
+ "dependency-check": "^4.1.0",
77
+ "eslint": "^8.5.0",
78
+ "eslint-plugin-harmony": "^6.0.0",
79
+ "husky": "^7.0.4",
80
+ "jest": "^27.4.5",
81
+ "jest-junit": "^13.0.0",
82
+ "jest-progress-tracker": "^3.0.1",
83
+ "jest-validate": "^27.4.2",
84
+ "jest-watch-repeat": "^2.0.0",
85
+ "jest-watch-suspend": "^1.1.2",
86
+ "jest-watch-toggle-config": "^2.0.1",
87
+ "jest-watch-typeahead": "^1.0.0",
88
+ "node-supported-releases": "^0.0.0",
89
+ "rimraf": "^3.0.2",
90
+ "typescript": "^4.5.4",
91
+ "update-notifier": "^5.1.0"
78
92
  }
79
93
  }
@@ -1,6 +1,5 @@
1
1
  import t from 'assert';
2
- import AssertionError from 'assertion-error';
3
- import a, { AssertOrder, State } from '..';
2
+ import a, { AssertOrder, InvalidOrder, State } from '..';
4
3
 
5
4
  test('is() expecting 1', () => {
6
5
  const order = new AssertOrder()
@@ -255,7 +254,7 @@ test(`onAny() throws if all assert functions throws`, () => {
255
254
  test('AssertOrder(0) accepts no step >= 1', () => {
256
255
  const order = new AssertOrder(0)
257
256
 
258
- const err = a.throws(() => order.once(1)) as AssertionError<{ state: any }>
257
+ const err = a.throws(() => order.once(1), InvalidOrder)
259
258
 
260
259
  t.strictEqual(err.state.maxStep, 0)
261
260
  })
@@ -265,7 +264,7 @@ test('AssertOrder(1) accepts step 1 but not 2', () => {
265
264
 
266
265
  order.once(1)
267
266
 
268
- const err = a.throws(() => order.once(2)) as AssertionError<{ state: any }>
267
+ const err = a.throws(() => order.once(2), InvalidOrder)
269
268
 
270
269
  t.strictEqual(err.state.maxStep, 1)
271
270
  })
@@ -286,7 +285,7 @@ test('end() would mark to not accepting more steps if plan is not defined', () =
286
285
  let order = new AssertOrder()
287
286
  order.end()
288
287
 
289
- let err = a.throws(() => order.once(1)) as AssertionError<{ state: any }>
288
+ let err = a.throws(() => order.once(1), InvalidOrder)
290
289
 
291
290
  t.strictEqual(err.state.maxStep, 0)
292
291
 
@@ -294,7 +293,7 @@ test('end() would mark to not accepting more steps if plan is not defined', () =
294
293
  order.once(1)
295
294
  order.end()
296
295
 
297
- err = a.throws(() => order.once(2)) as AssertionError<{ state: any }>
296
+ err = a.throws(() => order.once(2), InvalidOrder)
298
297
 
299
298
  t.strictEqual(err.state.maxStep, 1)
300
299
  })
@@ -310,7 +309,7 @@ test('end() throws if planned step not met', () => {
310
309
  const order = new AssertOrder(2)
311
310
  order.once(1)
312
311
 
313
- const err = a.throws(() => order.end()) as AssertionError<{ state: any }>
312
+ const err = a.throws(() => order.end(), InvalidOrder)
314
313
 
315
314
  t.strictEqual(err.state.maxStep, 2)
316
315
  })
@@ -331,7 +330,7 @@ test('end(n) waits n milliseconds and fail when step not met', async () => {
331
330
  setTimeout(() => {
332
331
  order.once(1)
333
332
  }, 10)
334
- const err = await a.throws(order.end(1)) as AssertionError<{ state: any }>
333
+ const err = await a.throws(order.end(1), InvalidOrder)
335
334
 
336
335
  t.strictEqual(err.state.maxStep, 1)
337
336
  })
@@ -421,7 +420,7 @@ test('wait(step, callback) will execute the async callback but not wait for it a
421
420
  const o2 = new AssertOrder(1)
422
421
 
423
422
  order.wait(1, () => {
424
- return new Promise(a => {
423
+ return new Promise<void>(a => {
425
424
  setImmediate(() => {
426
425
  o2.once(1)
427
426
  a()
@@ -434,8 +433,8 @@ test('wait(step, callback) will execute the async callback but not wait for it a
434
433
  return o2.end(100)
435
434
  })
436
435
 
437
- async function assertOrderThrows(fn, state: Partial<State>, method, ...args) {
438
- const err = await a.throws(fn) as AssertionError<{ state: any, method: string, args: any[] }>
436
+ async function assertOrderThrows(fn: () => any, state: Partial<State>, method: string, ...args: any[]) {
437
+ const err = await a.throws(fn, InvalidOrder)
439
438
  t.strictEqual(err.method, method)
440
439
  t.deepStrictEqual(err.args, args)
441
440
  if (state.step) {
@@ -31,7 +31,7 @@ export class AssertOrder {
31
31
  */
32
32
  not(step: number) {
33
33
  if (this.state.isValid(step)) {
34
- throw new InvalidOrder(this.state.get(), 'not', this.not, step)
34
+ throw new InvalidOrder(this.state.get(), 'not', [step], { ssf: this.not })
35
35
  }
36
36
  }
37
37
 
@@ -73,18 +73,18 @@ export class AssertOrder {
73
73
  return this.state.moveSubStep()
74
74
  }
75
75
  else
76
- throw new InvalidOrder(this.state.get(), 'atLeastOnce', this.atLeastOnce, step)
76
+ throw new InvalidOrder(this.state.get(), 'atLeastOnce', [step], { ssf: this.atLeastOnce })
77
77
  }
78
78
 
79
79
  any(steps: number[]) {
80
80
  const index = steps.indexOf(this.state.step)
81
81
  if (index === -1)
82
- throw new InvalidOrder(this.state.get(), 'any', this.any, steps)
82
+ throw new InvalidOrder(this.state.get(), 'any', [steps], { ssf: this.any })
83
83
 
84
84
  this.state.move()
85
85
  return steps[index]
86
86
  }
87
- onAny(steps: number[], ...asserts: Function[]) {
87
+ onAny(steps: number[], ...asserts: Array<(...args: any[]) => any>) {
88
88
  steps.forEach(step => {
89
89
  this.state.on(step, () => {
90
90
  let firstError: any
@@ -121,12 +121,12 @@ export class AssertOrder {
121
121
  }
122
122
 
123
123
  if (this.state.isAccepting()) {
124
- throw new InvalidOrder(this.state.get(), 'end', this.end)
124
+ throw new InvalidOrder(this.state.get(), 'end', [], { ssf: this.end })
125
125
  }
126
126
  }
127
127
  exactly(step: number, times: number) {
128
128
  if (this.state.isNotValid(step))
129
- throw new InvalidOrder(this.state.get(), 'exactly', this.exactly, step, times)
129
+ throw new InvalidOrder(this.state.get(), 'exactly', [step, times], { ssf: this.exactly })
130
130
 
131
131
  if (this.state.maxSubStep === undefined) {
132
132
  this.state.maxSubStep = times
@@ -145,7 +145,7 @@ export class AssertOrder {
145
145
  }
146
146
  private assert(method: string, step: number) {
147
147
  if (this.state.isNotValid(step)) {
148
- throw new InvalidOrder(this.state.get(), method, (this as any)[method], step)
148
+ throw new InvalidOrder(this.state.get(), method, [step], { ssf: (this as any)[method] })
149
149
  }
150
150
  }
151
151
  }
@@ -1,10 +1,9 @@
1
- import AssertionError from 'assertion-error';
2
- import { State } from './interfaces';
1
+ import { AssertionError } from '../errors'
2
+ import { State } from './types'
3
3
 
4
4
  export class InvalidOrder extends AssertionError {
5
- constructor(state: State, method: string, ssf: Function, ...args: any[]) {
6
- const message = method === 'end' ? getEndMessage(state) : getExpectingMessage(state, method, args)
7
- super(message, { method, state, args }, ssf)
5
+ constructor(public state: State, public method: string, public args: any[], options: AssertionError.Options) {
6
+ super(method === 'end' ? getEndMessage(state) : getExpectingMessage(state, method, args), options)
8
7
  }
9
8
  }
10
9
 
@@ -20,9 +19,8 @@ function getExpectingCalls(state: State) {
20
19
  let message: string
21
20
  if (state.subStep === 0) {
22
21
  const methods = ['is', 'once', 'any']
23
- message = methods.map(m => ['any'].indexOf(m) === -1 ?
24
- `'${m}(${state.step})'` :
25
- `'${m}([${state.step}])'`
22
+ message = methods.map(
23
+ m => `'${m}(${['any'].indexOf(m) === -1 ? state.step : `[${state.step}]`})'`
26
24
  ).join(', ')
27
25
  }
28
26
  else {
@@ -1,11 +1,10 @@
1
1
  import isNode from 'is-node'
2
- import { State } from './interfaces'
2
+ import { State } from './types'
3
3
 
4
4
  // istanbul ignore next
5
5
  function nodeVersionIsOrAbove(major: number, minor = 0, patch = 0) {
6
- // without this, systemjs will complain `process is not defined`
7
- if (!global.process)
8
- return false
6
+ // without this, systemJS will complain `process is not defined`
7
+ if (!global.process) return false
9
8
  const versionString = process.version.startsWith('v') ? process.version.slice(1) : process.version
10
9
  const [actualMajor, actualMinor, actualPatch] = versionString.split('.').map(s => parseInt(s, 10))
11
10
  const checking = major * 1000 * 1000 + minor * 1000 + patch
@@ -14,6 +13,7 @@ function nodeVersionIsOrAbove(major: number, minor = 0, patch = 0) {
14
13
  }
15
14
 
16
15
  // istanbul ignore next
16
+ // eslint-disable-next-line @typescript-eslint/no-var-requires
17
17
  const performance = isNode && nodeVersionIsOrAbove(8, 5) ? require('perf_hooks').performance : undefined
18
18
 
19
19
  let timeTracker: { start(): void, taken(): number }
@@ -1,2 +1,4 @@
1
1
  export * from './AssertOrder'
2
- export * from './interfaces'
2
+ export * from './InvalidOrder'
3
+ export * from './types'
4
+
File without changes
@@ -1,6 +1,5 @@
1
- import AssertionError from 'assertion-error';
2
- import a from '..';
3
- import { assertThrows, noStackTraceFor } from '../testUtils';
1
+ import a, { AssertionError } from '..'
2
+ import { assertThrows, noStackTraceFor } from '../testUtils'
4
3
 
5
4
  describe('false()', () => {
6
5
  test('non-false statement throws', () => {
@@ -1,20 +1,18 @@
1
- import AssertionError from 'assertion-error';
2
- import { falsy } from './falsy';
3
- import { pathEqual } from './pathEqual';
4
- import { rejects } from './rejects';
5
- import { repeat } from './repeat';
6
- import { resolves } from './resolves';
7
- import { satisfies } from './satisfies';
8
- import { throws } from './throws';
9
- import { truthy } from './truthy';
1
+ import { AssertionError } from '../errors'
2
+ import { notEqualMessage } from '../utils'
3
+ import { falsy } from './falsy'
4
+ import { pathEqual } from './pathEqual'
5
+ import { rejects } from './rejects'
6
+ import { repeat } from './repeat'
7
+ import { resolves } from './resolves'
8
+ import { satisfies } from './satisfies'
9
+ import { throws } from './throws'
10
+ import { truthy } from './truthy'
10
11
 
11
12
  export const assertron = {
12
13
  false(value: any) {
13
14
  if (value !== false)
14
- throw new AssertionError(
15
- `Expected value to equal false, but received ${value}`,
16
- { value },
17
- assertron.false)
15
+ throw new AssertionError(notEqualMessage(value, false), { ssf: assertron.false })
18
16
  },
19
17
  falsy,
20
18
  pathEqual,
@@ -24,7 +22,8 @@ export const assertron = {
24
22
  satisfies,
25
23
  throws,
26
24
  true(value: any) {
27
- if (value !== true) throw new AssertionError(`Expected value to equal true, but received ${value}`, { value }, assertron.true)
25
+ if (value !== true)
26
+ throw new AssertionError(notEqualMessage(value, true), { ssf: assertron.true })
28
27
  },
29
28
  truthy
30
29
  }
@@ -1,6 +1,5 @@
1
- import a from '..';
2
- import AssertionError from 'assertion-error'
3
- import { assertThrows, noStackTraceFor } from '../testUtils';
1
+ import a, { AssertionError } from '..'
2
+ import { assertThrows, noStackTraceFor } from '../testUtils'
4
3
 
5
4
  test('non-false statement throws', () => {
6
5
  assertThrows(() => a.falsy(true), AssertionError)
@@ -1,10 +1,6 @@
1
- import AssertionError from 'assertion-error'
1
+ import { AssertionError } from '../errors'
2
2
 
3
3
  export function falsy(value: any) {
4
4
  if (value)
5
- throw new AssertionError(
6
- `Expected value to be falsy, but received ${value}`,
7
- { value },
8
- falsy
9
- )
5
+ throw new AssertionError(`Expected value to be falsy, but received ${value}`, { ssf: falsy })
10
6
  }
@@ -1,6 +1,5 @@
1
- import AssertionError from 'assertion-error';
2
- import assertron from '..';
3
- import { assertThrows, noStackTraceFor } from '../testUtils';
1
+ import assertron, { AssertionError } from '..'
2
+ import { assertThrows, noStackTraceFor } from '../testUtils'
4
3
 
5
4
  test('path with same style passes', () => {
6
5
  assertron.pathEqual('a', 'a')
@@ -1,11 +1,8 @@
1
- import AssertionError from 'assertion-error';
2
- import { pathEqual as isPathEqual } from 'path-equal';
3
- import { notEqualMessage } from '../errors';
1
+ import { pathEqual as isPathEqual } from 'path-equal'
2
+ import { AssertionError } from '../errors'
3
+ import { notEqualMessage } from '../utils'
4
4
 
5
5
  export function pathEqual(actual: string, expected: string) {
6
6
  if (!isPathEqual(actual, expected))
7
- throw new AssertionError(
8
- notEqualMessage(actual, expected),
9
- { actual, expected },
10
- pathEqual)
7
+ throw new AssertionError(notEqualMessage(actual, expected), { ssf: pathEqual })
11
8
  }
@@ -1,7 +1,6 @@
1
- import t from 'assert';
2
- import AssertionError from 'assertion-error';
3
- import a from '..';
4
- import { assertAsyncThrows, noStackTraceFor } from '../testUtils';
1
+ import t from 'assert'
2
+ import a from '..'
3
+ import { assertAsyncThrows, noStackTraceFor } from '../testUtils'
5
4
 
6
5
  test('pass on rejected promise', async () => {
7
6
  await a.rejects(Promise.reject(1))
@@ -12,22 +11,22 @@ test('throws on resolved string promise', async () => {
12
11
  t.strictEqual(err.message, `Expected promise to reject, but it resolves with 'abc'`)
13
12
  })
14
13
 
15
- test('throws on resovled boolean promise', async () => {
14
+ test('throws on resolved boolean promise', async () => {
16
15
  const err = await a.throws(a.rejects(Promise.resolve(true)))
17
16
  t.strictEqual(err.message, `Expected promise to reject, but it resolves with true`)
18
17
  })
19
18
 
20
- test('throws on resovled object promise', async () => {
19
+ test('throws on resolved object promise', async () => {
21
20
  const err = await a.throws(a.rejects(Promise.resolve(2)))
22
21
  t.strictEqual(err.message, `Expected promise to reject, but it resolves with 2`)
23
22
  })
24
23
 
25
- test('throws on resovled object promise', async () => {
24
+ test('throws on resolved object promise', async () => {
26
25
  const err = await a.throws(a.rejects(Promise.resolve({ a: 1 })))
27
26
  t.strictEqual(err.message, `Expected promise to reject, but it resolves with { a: 1 }`)
28
27
  })
29
28
 
30
29
  test('does not contain internal stack trace', async () => {
31
- const err = await assertAsyncThrows(() => a.rejects(Promise.resolve({ a: 1 })), AssertionError)
30
+ const err = await assertAsyncThrows(() => a.rejects(Promise.resolve({ a: 1 })))
32
31
  noStackTraceFor('rejects.ts', err)
33
32
  })
@@ -1,15 +1,9 @@
1
- import { tersify } from 'tersify';
2
- import AssertionError from 'assertion-error';
1
+ import { AssertionError } from '../errors'
2
+ import { notRejectedMessage } from '../utils'
3
3
 
4
4
  export function rejects(promise: Promise<any>) {
5
5
  return promise.then(
6
- value => {
7
- throw new AssertionError(
8
- `Expected promise to reject, but it resolves with ${typeof value === 'string' ?
9
- `'${value}'` : tersify(value, { maxLength: Infinity })}`,
10
- { value },
11
- rejects)
12
- },
6
+ value => { throw new AssertionError(notRejectedMessage(value), { ssf: rejects }) },
13
7
  () => { }
14
8
  )
15
9
  }
@@ -1,5 +1,4 @@
1
- import a from '..'
2
- import { FailOnOccurance } from './repeat';
1
+ import a, { FailOnOccurrence } from '..'
3
2
 
4
3
  test('repeat function n times', () => {
5
4
  let count = 0
@@ -26,24 +25,23 @@ test('repeat async function n times sequentially', async () => {
26
25
  test('error is captured as inner error and indicate which call failed', () => {
27
26
  let count = 0
28
27
  const err = a.throws(() => a.repeat(() => {
29
- ++count
30
- if (count === 5) throw new Error('failed')
31
- }, 10), FailOnOccurance)
28
+ if (++count === 5) throw new Error('failed')
29
+ }, 10), FailOnOccurrence)
32
30
 
33
- expect(err.occurance).toBe(5)
31
+ expect(err.occurrence).toBe(5)
34
32
  expect(err.error.message).toBe('failed')
35
33
  })
36
34
 
37
35
  test('rejected error is captured as inner error and indicate which call failed', async () => {
38
36
  let count = 0
39
- const err = await a.throws(a.repeat(() => new Promise((a, r) => {
37
+ const err = await a.throws(a.repeat(() => new Promise<void>((a, r) => {
40
38
  setTimeout(() => {
41
39
  ++count
42
40
  if (count === 5) r(new Error('failed'))
43
41
  else a()
44
42
  }, Math.random() * 10)
45
- }), 10), FailOnOccurance)
43
+ }), 10), FailOnOccurrence)
46
44
 
47
- expect(err.occurance).toBe(5)
45
+ expect(err.occurrence).toBe(5)
48
46
  expect(err.error.message).toBe('failed')
49
47
  })