assertron 11.2.0 → 11.2.1

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 (126) hide show
  1. package/cjs/assert-order/AssertOrder.d.ts.map +1 -1
  2. package/cjs/assert-order/AssertOrder.js +3 -1
  3. package/cjs/assert-order/AssertOrder.js.map +1 -1
  4. package/cjs/assert-order/InvalidOrder.d.ts.map +1 -1
  5. package/cjs/assert-order/InvalidOrder.js +4 -2
  6. package/cjs/assert-order/InvalidOrder.js.map +1 -1
  7. package/cjs/assert-order/StateMachine.d.ts.map +1 -1
  8. package/cjs/assert-order/StateMachine.js +17 -8
  9. package/cjs/assert-order/StateMachine.js.map +1 -1
  10. package/cjs/assert-order/types.d.ts.map +1 -1
  11. package/cjs/assertron/assertron.d.ts.map +1 -1
  12. package/cjs/assertron/assertron.js.map +1 -1
  13. package/cjs/assertron/falsy.d.ts.map +1 -1
  14. package/cjs/assertron/falsy.js.map +1 -1
  15. package/cjs/assertron/isInstanceof.d.ts.map +1 -1
  16. package/cjs/assertron/isInstanceof.js.map +1 -1
  17. package/cjs/assertron/pathEqual.js.map +1 -1
  18. package/cjs/assertron/rejects.d.ts.map +1 -1
  19. package/cjs/assertron/rejects.js +3 -1
  20. package/cjs/assertron/rejects.js.map +1 -1
  21. package/cjs/assertron/repeat.d.ts.map +1 -1
  22. package/cjs/assertron/repeat.js +3 -1
  23. package/cjs/assertron/repeat.js.map +1 -1
  24. package/cjs/assertron/resolves.d.ts.map +1 -1
  25. package/cjs/assertron/resolves.js +3 -1
  26. package/cjs/assertron/resolves.js.map +1 -1
  27. package/cjs/assertron/satisfies.d.ts.map +1 -1
  28. package/cjs/assertron/satisfies.js.map +1 -1
  29. package/cjs/assertron/throws.d.ts.map +1 -1
  30. package/cjs/assertron/throws.js +7 -3
  31. package/cjs/assertron/throws.js.map +1 -1
  32. package/cjs/assertron/truthy.d.ts.map +1 -1
  33. package/cjs/assertron/truthy.js.map +1 -1
  34. package/cjs/errors.d.ts.map +1 -1
  35. package/cjs/errors.js.map +1 -1
  36. package/cjs/package.json +1 -1
  37. package/cjs/types.d.ts.map +1 -1
  38. package/cjs/utils/index.js.map +1 -1
  39. package/cjs/utils/isErrorConstructor.js.map +1 -1
  40. package/cjs/utils/notEqualMessage.js.map +1 -1
  41. package/cjs/utils/notSatisfiedMessage.d.ts.map +1 -1
  42. package/cjs/utils/notSatisfiedMessage.js +8 -3
  43. package/cjs/utils/notSatisfiedMessage.js.map +1 -1
  44. package/cjs/utils/notThrownMessage.js.map +1 -1
  45. package/cjs/utils/promiseMessages.d.ts.map +1 -1
  46. package/cjs/utils/promiseMessages.js +8 -4
  47. package/cjs/utils/promiseMessages.js.map +1 -1
  48. package/cjs/utils/unexpectedErrorMessage.d.ts.map +1 -1
  49. package/cjs/utils/unexpectedErrorMessage.js +1 -2
  50. package/cjs/utils/unexpectedErrorMessage.js.map +1 -1
  51. package/esm/assert-order/AssertOrder.d.ts.map +1 -1
  52. package/esm/assert-order/AssertOrder.js +3 -1
  53. package/esm/assert-order/AssertOrder.js.map +1 -1
  54. package/esm/assert-order/InvalidOrder.d.ts.map +1 -1
  55. package/esm/assert-order/InvalidOrder.js +4 -2
  56. package/esm/assert-order/InvalidOrder.js.map +1 -1
  57. package/esm/assert-order/StateMachine.d.ts.map +1 -1
  58. package/esm/assert-order/StateMachine.js +17 -8
  59. package/esm/assert-order/StateMachine.js.map +1 -1
  60. package/esm/assert-order/types.d.ts.map +1 -1
  61. package/esm/assertron/assertron.d.ts.map +1 -1
  62. package/esm/assertron/assertron.js.map +1 -1
  63. package/esm/assertron/falsy.d.ts.map +1 -1
  64. package/esm/assertron/falsy.js.map +1 -1
  65. package/esm/assertron/isInstanceof.d.ts.map +1 -1
  66. package/esm/assertron/isInstanceof.js.map +1 -1
  67. package/esm/assertron/pathEqual.js.map +1 -1
  68. package/esm/assertron/rejects.d.ts.map +1 -1
  69. package/esm/assertron/rejects.js +3 -1
  70. package/esm/assertron/rejects.js.map +1 -1
  71. package/esm/assertron/repeat.d.ts.map +1 -1
  72. package/esm/assertron/repeat.js +3 -1
  73. package/esm/assertron/repeat.js.map +1 -1
  74. package/esm/assertron/resolves.d.ts.map +1 -1
  75. package/esm/assertron/resolves.js +3 -1
  76. package/esm/assertron/resolves.js.map +1 -1
  77. package/esm/assertron/satisfies.d.ts.map +1 -1
  78. package/esm/assertron/satisfies.js.map +1 -1
  79. package/esm/assertron/throws.d.ts.map +1 -1
  80. package/esm/assertron/throws.js +7 -3
  81. package/esm/assertron/throws.js.map +1 -1
  82. package/esm/assertron/truthy.d.ts.map +1 -1
  83. package/esm/assertron/truthy.js.map +1 -1
  84. package/esm/errors.d.ts.map +1 -1
  85. package/esm/errors.js.map +1 -1
  86. package/esm/types.d.ts.map +1 -1
  87. package/esm/utils/index.js.map +1 -1
  88. package/esm/utils/isErrorConstructor.js.map +1 -1
  89. package/esm/utils/notEqualMessage.js.map +1 -1
  90. package/esm/utils/notSatisfiedMessage.d.ts.map +1 -1
  91. package/esm/utils/notSatisfiedMessage.js +8 -3
  92. package/esm/utils/notSatisfiedMessage.js.map +1 -1
  93. package/esm/utils/notThrownMessage.js.map +1 -1
  94. package/esm/utils/promiseMessages.d.ts.map +1 -1
  95. package/esm/utils/promiseMessages.js +8 -4
  96. package/esm/utils/promiseMessages.js.map +1 -1
  97. package/esm/utils/unexpectedErrorMessage.d.ts.map +1 -1
  98. package/esm/utils/unexpectedErrorMessage.js +1 -2
  99. package/esm/utils/unexpectedErrorMessage.js.map +1 -1
  100. package/package.json +1 -1
  101. package/ts/assert-order/AssertOrder.ts +138 -143
  102. package/ts/assert-order/InvalidOrder.ts +22 -18
  103. package/ts/assert-order/StateMachine.ts +95 -88
  104. package/ts/assert-order/index.ts +0 -1
  105. package/ts/assert-order/internalInterfaces.ts +3 -3
  106. package/ts/assert-order/types.ts +5 -5
  107. package/ts/assertron/assertron.ts +38 -31
  108. package/ts/assertron/falsy.ts +1 -2
  109. package/ts/assertron/isInstanceof.ts +6 -3
  110. package/ts/assertron/pathEqual.ts +2 -2
  111. package/ts/assertron/rejects.ts +6 -4
  112. package/ts/assertron/repeat.ts +27 -21
  113. package/ts/assertron/resolves.ts +6 -4
  114. package/ts/assertron/satisfies.ts +27 -20
  115. package/ts/assertron/throws.ts +75 -54
  116. package/ts/assertron/truthy.ts +1 -4
  117. package/ts/errors.ts +7 -7
  118. package/ts/testUtils.ts +51 -54
  119. package/ts/types.ts +0 -1
  120. package/ts/utils/index.ts +1 -1
  121. package/ts/utils/isErrorConstructor.ts +1 -1
  122. package/ts/utils/notEqualMessage.ts +1 -1
  123. package/ts/utils/notSatisfiedMessage.ts +17 -13
  124. package/ts/utils/notThrownMessage.ts +1 -1
  125. package/ts/utils/promiseMessages.ts +12 -5
  126. package/ts/utils/unexpectedErrorMessage.ts +3 -2
@@ -5,147 +5,142 @@ import { StateMachine } from './StateMachine.js'
5
5
  // order.atMost(step, count) // exected to be executed at most `count` times
6
6
 
7
7
  export class AssertOrder {
8
- /**
9
- * Gets the current expecting step.
10
- */
11
- get currentStep() {
12
- return this.state.step
13
- }
14
-
15
- private state: StateMachine
16
- constructor(plan?: number) {
17
- this.state = new StateMachine(plan)
18
- }
19
-
20
- /**
21
- * Asserts the current step is `step`.
22
- * @param step expected step.
23
- */
24
- is(step: number) {
25
- this.assert('is', step)
26
- }
27
-
28
- /**
29
- * Asserts the current step is not `step`.
30
- * @param step not expected step.
31
- */
32
- not(step: number) {
33
- if (this.state.isValid(step)) {
34
- throw new InvalidOrder(this.state.get(), 'not', [step], { ssf: this.not })
35
- }
36
- }
37
-
38
- /**
39
- * Reset to specified step.
40
- */
41
- jump(step: number) {
42
- this.state.jump(step)
43
- }
44
-
45
- /**
46
- * Move to next step.
47
- */
48
- move() {
49
- this.state.move()
50
- }
51
-
52
- /**
53
- * Asserts the specified step will run once.
54
- */
55
- once(step: number) {
56
- this.assert('once', step)
57
- this.state.move()
58
- }
59
-
60
- on(step: number, assert: (step: number) => void) {
61
- this.state.on(step, () => {
62
- assert(step)
63
- })
64
- }
65
-
66
- atLeastOnce(step: number) {
67
- const nextStep = step + 1
68
- if (this.state.step === step) {
69
- this.state.move()
70
- return this.state.moveSubStep()
71
- }
72
- else if (this.state.step === nextStep && this.state.subStep > 0) {
73
- return this.state.moveSubStep()
74
- }
75
- else
76
- throw new InvalidOrder(this.state.get(), 'atLeastOnce', [step], { ssf: this.atLeastOnce })
77
- }
78
-
79
- any(steps: number[]) {
80
- const index = steps.indexOf(this.state.step)
81
- if (index === -1)
82
- throw new InvalidOrder(this.state.get(), 'any', [steps], { ssf: this.any })
83
-
84
- this.state.move()
85
- return steps[index]
86
- }
87
- onAny(steps: number[], ...asserts: Array<(...args: any[]) => any>) {
88
- steps.forEach(step => {
89
- this.state.on(step, () => {
90
- let firstError: any
91
- let hasPass = false
92
- asserts.forEach(assert => {
93
- try {
94
- assert(step)
95
- hasPass = true
96
- }
97
- catch (err) {
98
- if (!firstError) firstError = err
99
- }
100
- })
101
- if (!hasPass)
102
- throw firstError
103
- })
104
- })
105
- return
106
- }
107
- end(timeout: number): Promise<number>
108
- end(): number
109
- end(timeout?: number) {
110
- if (timeout) {
111
- return new Promise(r => {
112
- setTimeout(r, timeout)
113
- }).then(() => {
114
- return this.end()
115
- })
116
- }
117
-
118
- if (!this.state.isMaxStepDefined()) {
119
- this.state.stopAccepting()
120
- return this.state.getTimeTaken()
121
- }
122
-
123
- if (this.state.isAccepting()) {
124
- throw new InvalidOrder(this.state.get(), 'end', [], { ssf: this.end })
125
- }
126
- }
127
- exactly(step: number, times: number) {
128
- if (this.state.isNotValid(step))
129
- throw new InvalidOrder(this.state.get(), 'exactly', [step, times], { ssf: this.exactly })
130
-
131
- if (this.state.maxSubStep === undefined) {
132
- this.state.maxSubStep = times
133
- this.state.minSubStep = times
134
- }
135
-
136
- return this.state.moveSubStep()
137
- }
138
- wait(step: number): Promise<void>
139
- wait(step: number, callback: () => void): void
140
- wait(step: number, callback?: () => void) {
141
- if (callback)
142
- this.on(step, callback)
143
- else
144
- return new Promise<any>(a => { this.on(step, a) })
145
- }
146
- private assert(method: string, step: number) {
147
- if (this.state.isNotValid(step)) {
148
- throw new InvalidOrder(this.state.get(), method, [step], { ssf: (this as any)[method] })
149
- }
150
- }
8
+ /**
9
+ * Gets the current expecting step.
10
+ */
11
+ get currentStep() {
12
+ return this.state.step
13
+ }
14
+
15
+ private state: StateMachine
16
+ constructor(plan?: number) {
17
+ this.state = new StateMachine(plan)
18
+ }
19
+
20
+ /**
21
+ * Asserts the current step is `step`.
22
+ * @param step expected step.
23
+ */
24
+ is(step: number) {
25
+ this.assert('is', step)
26
+ }
27
+
28
+ /**
29
+ * Asserts the current step is not `step`.
30
+ * @param step not expected step.
31
+ */
32
+ not(step: number) {
33
+ if (this.state.isValid(step)) {
34
+ throw new InvalidOrder(this.state.get(), 'not', [step], { ssf: this.not })
35
+ }
36
+ }
37
+
38
+ /**
39
+ * Reset to specified step.
40
+ */
41
+ jump(step: number) {
42
+ this.state.jump(step)
43
+ }
44
+
45
+ /**
46
+ * Move to next step.
47
+ */
48
+ move() {
49
+ this.state.move()
50
+ }
51
+
52
+ /**
53
+ * Asserts the specified step will run once.
54
+ */
55
+ once(step: number) {
56
+ this.assert('once', step)
57
+ this.state.move()
58
+ }
59
+
60
+ on(step: number, assert: (step: number) => void) {
61
+ this.state.on(step, () => {
62
+ assert(step)
63
+ })
64
+ }
65
+
66
+ atLeastOnce(step: number) {
67
+ const nextStep = step + 1
68
+ if (this.state.step === step) {
69
+ this.state.move()
70
+ return this.state.moveSubStep()
71
+ } else if (this.state.step === nextStep && this.state.subStep > 0) {
72
+ return this.state.moveSubStep()
73
+ } else throw new InvalidOrder(this.state.get(), 'atLeastOnce', [step], { ssf: this.atLeastOnce })
74
+ }
75
+
76
+ any(steps: number[]) {
77
+ const index = steps.indexOf(this.state.step)
78
+ if (index === -1) throw new InvalidOrder(this.state.get(), 'any', [steps], { ssf: this.any })
79
+
80
+ this.state.move()
81
+ return steps[index]
82
+ }
83
+ onAny(steps: number[], ...asserts: Array<(...args: any[]) => any>) {
84
+ steps.forEach(step => {
85
+ this.state.on(step, () => {
86
+ let firstError: any
87
+ let hasPass = false
88
+ asserts.forEach(assert => {
89
+ try {
90
+ assert(step)
91
+ hasPass = true
92
+ } catch (err) {
93
+ if (!firstError) firstError = err
94
+ }
95
+ })
96
+ if (!hasPass) throw firstError
97
+ })
98
+ })
99
+ return
100
+ }
101
+ end(timeout: number): Promise<number>
102
+ end(): number
103
+ end(timeout?: number) {
104
+ if (timeout) {
105
+ return new Promise(r => {
106
+ setTimeout(r, timeout)
107
+ }).then(() => {
108
+ return this.end()
109
+ })
110
+ }
111
+
112
+ if (!this.state.isMaxStepDefined()) {
113
+ this.state.stopAccepting()
114
+ return this.state.getTimeTaken()
115
+ }
116
+
117
+ if (this.state.isAccepting()) {
118
+ throw new InvalidOrder(this.state.get(), 'end', [], { ssf: this.end })
119
+ }
120
+ }
121
+ exactly(step: number, times: number) {
122
+ if (this.state.isNotValid(step))
123
+ throw new InvalidOrder(this.state.get(), 'exactly', [step, times], { ssf: this.exactly })
124
+
125
+ if (this.state.maxSubStep === undefined) {
126
+ this.state.maxSubStep = times
127
+ this.state.minSubStep = times
128
+ }
129
+
130
+ return this.state.moveSubStep()
131
+ }
132
+ wait(step: number): Promise<void>
133
+ wait(step: number, callback: () => void): void
134
+ wait(step: number, callback?: () => void) {
135
+ if (callback) this.on(step, callback)
136
+ else
137
+ return new Promise<any>(a => {
138
+ this.on(step, a)
139
+ })
140
+ }
141
+ private assert(method: string, step: number) {
142
+ if (this.state.isNotValid(step)) {
143
+ throw new InvalidOrder(this.state.get(), method, [step], { ssf: (this as any)[method] })
144
+ }
145
+ }
151
146
  }
@@ -2,34 +2,38 @@ import { AssertionError } from '../errors.js'
2
2
  import type { State } from './types.js'
3
3
 
4
4
  export class InvalidOrder extends AssertionError {
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)
7
- }
5
+ constructor(
6
+ public state: State,
7
+ public method: string,
8
+ public args: any[],
9
+ options: AssertionError.Options
10
+ ) {
11
+ super(method === 'end' ? getEndMessage(state) : getExpectingMessage(state, method, args), options)
12
+ }
8
13
  }
9
14
 
10
15
  function getEndMessage(state: State) {
11
- return `Planned for ${state.maxStep} step but expecting step ${state.step} when 'end()' is called`
16
+ return `Planned for ${state.maxStep} step but expecting step ${state.step} when 'end()' is called`
12
17
  }
13
18
 
14
19
  function getExpectingMessage(state: State, method: string, args: any[]) {
15
- return `Expecting ${getExpectingCalls(state)}, but received '${method}(${getMethodArgs(args)})'`
20
+ return `Expecting ${getExpectingCalls(state)}, but received '${method}(${getMethodArgs(args)})'`
16
21
  }
17
22
 
18
23
  function getExpectingCalls(state: State) {
19
- let message: string
20
- if (state.subStep === 0) {
21
- const methods = ['is', 'once', 'any']
22
- message = methods.map(
23
- m => `'${m}(${['any'].indexOf(m) === -1 ? state.step : `[${state.step}]`})'`
24
- ).join(', ')
25
- }
26
- else {
27
- const methods = ['exactly']
28
- message = methods.map(m => `'${m}(${state.step}, ${state.maxSubStep})'`).join(', ')
29
- }
30
- return message
24
+ let message: string
25
+ if (state.subStep === 0) {
26
+ const methods = ['is', 'once', 'any']
27
+ message = methods
28
+ .map(m => `'${m}(${['any'].indexOf(m) === -1 ? state.step : `[${state.step}]`})'`)
29
+ .join(', ')
30
+ } else {
31
+ const methods = ['exactly']
32
+ message = methods.map(m => `'${m}(${state.step}, ${state.maxSubStep})'`).join(', ')
33
+ }
34
+ return message
31
35
  }
32
36
 
33
37
  function getMethodArgs(args: any[]) {
34
- return args.map(a => Array.isArray(a) ? `[${a.join(', ')}]` : a).join(', ')
38
+ return args.map(a => (Array.isArray(a) ? `[${a.join(', ')}]` : a)).join(', ')
35
39
  }
@@ -1,96 +1,103 @@
1
1
  import * as perf from 'perf_hooks'
2
2
  import type { State } from './types.js'
3
3
 
4
- let timeTracker: { start(): void, taken(): number }
5
- // istanbul ignore else
6
- if (process && typeof process.hrtime === 'function') {
7
- let tick: [number, number]
8
- timeTracker = {
9
- start() { tick = process.hrtime() },
10
- taken() {
11
- const [second, nanoSecond] = process.hrtime(tick)
12
- return second * 1000 + nanoSecond / 1e6
13
- }
14
- }
15
- }
16
- else if (perf.performance && typeof perf.performance.now === 'function') {
17
- const now = perf.performance.now
18
- let tick: number
19
- timeTracker = {
20
- start() { tick = now() },
21
- taken() { return now() - tick }
22
- }
23
- }
24
- else {
25
- let tick: number
26
- timeTracker = {
27
- start() { tick = new Date().valueOf() },
28
- taken() { return new Date().valueOf() - tick }
29
- }
4
+ let timeTracker: { start(): void; taken(): number }
5
+
6
+ if (global['process'] && typeof global['process'].hrtime === 'function') {
7
+ let tick: [number, number]
8
+ timeTracker = {
9
+ start() {
10
+ tick = global['process'].hrtime()
11
+ },
12
+ taken() {
13
+ const [second, nanoSecond] = global['process'].hrtime(tick)
14
+ return second * 1000 + nanoSecond / 1e6
15
+ }
16
+ }
17
+ } else if (perf.performance && typeof perf.performance.now === 'function') {
18
+ const now = perf.performance.now
19
+ let tick: number
20
+ timeTracker = {
21
+ start() {
22
+ tick = now()
23
+ },
24
+ taken() {
25
+ return now() - tick
26
+ }
27
+ }
28
+ } else {
29
+ let tick: number
30
+ timeTracker = {
31
+ start() {
32
+ tick = new Date().valueOf()
33
+ },
34
+ taken() {
35
+ return new Date().valueOf() - tick
36
+ }
37
+ }
30
38
  }
31
39
 
32
40
  export class StateMachine {
33
- listeners: Record<number, Array<() => void>> = {}
34
- step = 1
35
- maxStep?: number
41
+ listeners: Record<number, Array<() => void>> = {}
42
+ step = 1
43
+ maxStep?: number
36
44
 
37
- subStep = 0
38
- minSubStep?: number
39
- maxSubStep?: number
40
- constructor(maxStep?: number) {
41
- this.maxStep = maxStep
42
- timeTracker.start()
43
- }
44
- jump(step: number) {
45
- this.step = step
46
- this.subStep = 0
47
- return this.step
48
- }
49
- move() {
50
- const listeners = this.listeners[this.step]
51
- this.step = this.step + 1
52
- this.subStep = 0
53
- if (listeners) {
54
- listeners.forEach(l => l())
55
- }
56
- return this.step
57
- }
58
- moveSubStep() {
59
- const subStep = ++this.subStep
60
- if (this.maxSubStep === this.subStep)
61
- this.move()
62
- return subStep
63
- }
64
- get(): State {
65
- const { step, subStep, maxStep, minSubStep, maxSubStep } = this
66
- return {
67
- step,
68
- maxStep,
69
- subStep,
70
- minSubStep,
71
- maxSubStep
72
- }
73
- }
74
- on(step: number, listener: () => void) {
75
- this.listeners[step] = [listener]
76
- }
77
- isNotValid(step: number) {
78
- return step !== this.step || (this.maxStep !== undefined && this.maxStep < step)
79
- }
80
- isValid(step: number) {
81
- return step === this.step
82
- }
83
- isMaxStepDefined() {
84
- return this.maxStep !== undefined
85
- }
86
- stopAccepting() {
87
- this.maxStep = this.step - 1
88
- }
89
- isAccepting() {
90
- // istanbul ignore next
91
- return this.maxStep ? this.maxStep >= this.step : true
92
- }
93
- getTimeTaken() {
94
- return timeTracker.taken()
95
- }
45
+ subStep = 0
46
+ minSubStep?: number
47
+ maxSubStep?: number
48
+ constructor(maxStep?: number) {
49
+ this.maxStep = maxStep
50
+ timeTracker.start()
51
+ }
52
+ jump(step: number) {
53
+ this.step = step
54
+ this.subStep = 0
55
+ return this.step
56
+ }
57
+ move() {
58
+ const listeners = this.listeners[this.step]
59
+ this.step = this.step + 1
60
+ this.subStep = 0
61
+ if (listeners) {
62
+ listeners.forEach(l => l())
63
+ }
64
+ return this.step
65
+ }
66
+ moveSubStep() {
67
+ const subStep = ++this.subStep
68
+ if (this.maxSubStep === this.subStep) this.move()
69
+ return subStep
70
+ }
71
+ get(): State {
72
+ const { step, subStep, maxStep, minSubStep, maxSubStep } = this
73
+ return {
74
+ step,
75
+ maxStep,
76
+ subStep,
77
+ minSubStep,
78
+ maxSubStep
79
+ }
80
+ }
81
+ on(step: number, listener: () => void) {
82
+ this.listeners[step] = [listener]
83
+ }
84
+ isNotValid(step: number) {
85
+ return step !== this.step || (this.maxStep !== undefined && this.maxStep < step)
86
+ }
87
+ isValid(step: number) {
88
+ return step === this.step
89
+ }
90
+ isMaxStepDefined() {
91
+ return this.maxStep !== undefined
92
+ }
93
+ stopAccepting() {
94
+ this.maxStep = this.step - 1
95
+ }
96
+ isAccepting() {
97
+ // istanbul ignore next
98
+ return this.maxStep ? this.maxStep >= this.step : true
99
+ }
100
+ getTimeTaken() {
101
+ return timeTracker.taken()
102
+ }
96
103
  }
@@ -1,4 +1,3 @@
1
1
  export * from './AssertOrder.js'
2
2
  export * from './InvalidOrder.js'
3
3
  export * from './types.js'
4
-
@@ -1,5 +1,5 @@
1
1
  export interface Steps {
2
- once?: number[],
3
- some?: number[],
4
- all?: number[],
2
+ once?: number[]
3
+ some?: number[]
4
+ all?: number[]
5
5
  }
@@ -1,7 +1,7 @@
1
1
  export interface State {
2
- step: number,
3
- maxStep?: number,
4
- subStep: number,
5
- minSubStep?: number,
6
- maxSubStep?: number,
2
+ step: number
3
+ maxStep?: number
4
+ subStep: number
5
+ minSubStep?: number
6
+ maxSubStep?: number
7
7
  }
@@ -13,38 +13,45 @@ import { throws } from './throws.js'
13
13
  import { truthy } from './truthy.js'
14
14
 
15
15
  export type Assertron = {
16
- false(value: unknown): asserts value is false,
17
- falsy(value: any): asserts value is false | 0 | '' | null | undefined,
18
- isInstanceof<T extends AnyConstructor>(value: unknown, type: T): asserts value is InstanceType<T>,
19
- pathEqual(actual: string, expected: string): void,
20
- rejects<R = any>(promise: Promise<any>): Promise<R>,
21
- repeat<R>(fn: () => R | (() => Promise<R>), times: number): ReturnType<typeof fn> extends Promise<R> ? Promise<R> : R,
22
- resolves(promise: Promise<any>): Promise<void>,
23
- satisfies<Actual, Expected extends Actual>(actual: Actual, expected: SatisfyExpectation<Expected>): void,
24
- throws<E extends Error>(value: PromiseLike<any>, error?: ErrorValidator | ErrorConstructor<E>): Promise<E>,
25
- throws<E extends Error>(value: (...args: any[]) => never, error?: ErrorValidator | ErrorConstructor<E>): E,
26
- throws<E extends Error, R = any>(value: (...args: any[]) => R, error?: ErrorValidator | ErrorConstructor<E>): R extends Promise<any> ? Promise<E> : E,
27
- throws<T, R = any>(value: (...args: any[]) => R, validator?: ErrorValidator): R extends Promise<any> ? Promise<T> : T,
28
- true(value: any): asserts value is true,
29
- truthy(value: unknown): void
16
+ false(value: unknown): asserts value is false
17
+ falsy(value: any): asserts value is false | 0 | '' | null | undefined
18
+ isInstanceof<T extends AnyConstructor>(value: unknown, type: T): asserts value is InstanceType<T>
19
+ pathEqual(actual: string, expected: string): void
20
+ rejects<R = any>(promise: Promise<any>): Promise<R>
21
+ repeat<R>(
22
+ fn: () => R | (() => Promise<R>),
23
+ times: number
24
+ ): ReturnType<typeof fn> extends Promise<R> ? Promise<R> : R
25
+ resolves(promise: Promise<any>): Promise<void>
26
+ satisfies<Actual, Expected extends Actual>(actual: Actual, expected: SatisfyExpectation<Expected>): void
27
+ throws<E extends Error>(value: PromiseLike<any>, error?: ErrorValidator | ErrorConstructor<E>): Promise<E>
28
+ throws<E extends Error>(value: (...args: any[]) => never, error?: ErrorValidator | ErrorConstructor<E>): E
29
+ throws<E extends Error, R = any>(
30
+ value: (...args: any[]) => R,
31
+ error?: ErrorValidator | ErrorConstructor<E>
32
+ ): R extends Promise<any> ? Promise<E> : E
33
+ throws<T, R = any>(
34
+ value: (...args: any[]) => R,
35
+ validator?: ErrorValidator
36
+ ): R extends Promise<any> ? Promise<T> : T
37
+ true(value: any): asserts value is true
38
+ truthy(value: unknown): void
30
39
  }
31
40
 
32
41
  export const assertron: Assertron = {
33
- false(value: any) {
34
- if (value !== false)
35
- throw new AssertionError(notEqualMessage(value, false), { ssf: assertron.false })
36
- },
37
- falsy,
38
- isInstanceof,
39
- pathEqual,
40
- rejects,
41
- repeat,
42
- resolves,
43
- satisfies,
44
- throws,
45
- true(value: any) {
46
- if (value !== true)
47
- throw new AssertionError(notEqualMessage(value, true), { ssf: assertron.true })
48
- },
49
- truthy
42
+ false(value: any) {
43
+ if (value !== false) throw new AssertionError(notEqualMessage(value, false), { ssf: assertron.false })
44
+ },
45
+ falsy,
46
+ isInstanceof,
47
+ pathEqual,
48
+ rejects,
49
+ repeat,
50
+ resolves,
51
+ satisfies,
52
+ throws,
53
+ true(value: any) {
54
+ if (value !== true) throw new AssertionError(notEqualMessage(value, true), { ssf: assertron.true })
55
+ },
56
+ truthy
50
57
  }
@@ -1,6 +1,5 @@
1
1
  import { AssertionError } from '../errors.js'
2
2
 
3
3
  export function falsy(value: any) {
4
- if (value)
5
- throw new AssertionError(`Expected value to be falsy, but received ${value}`, { ssf: falsy })
4
+ if (value) throw new AssertionError(`Expected value to be falsy, but received ${value}`, { ssf: falsy })
6
5
  }