Skip to content

Commit 6266996

Browse files
committed
Add a test
1 parent f8aa526 commit 6266996

File tree

4 files changed

+44
-9
lines changed

4 files changed

+44
-9
lines changed

CHANGELOG.md

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ logProcessErrors({
3838
## Pretty-printing
3939

4040
Errors are not pretty-printed anymore. As a consequence, the `colors` option was
41-
removed. The [`onError` option](README.md#onerror) can be used instead to
41+
removed too. The [`onError` option](README.md#onerror) can be used instead to
4242
customize how the errors are printed.
4343

4444
## Filtering
@@ -49,7 +49,11 @@ be used for filtering.
4949
Before:
5050

5151
```js
52-
logProcessErrors({ warning: 'silent' })
52+
logProcessErrors({
53+
levels: {
54+
warning: 'silent',
55+
},
56+
})
5357
```
5458

5559
After:
@@ -79,6 +83,7 @@ After:
7983

8084
```js
8185
logProcessErrors({
86+
// Throw the `error` to make the unit test fail while letting other tests run
8287
onError(error) {
8388
throw error
8489
},
@@ -115,19 +120,19 @@ process. This created conflicts with this library. This has been fixed by making
115120
the [`exit` option](README.md#exit) default to `false` when process events
116121
listeners already exist.
117122

118-
## TypeScript
119-
120-
TypeScript types have been simplified.
121-
122123
## Bug fixes
123124

124125
- Fix support for `--unhandled-rejections=strict`
125126
- Do not crash when `error.stack` is `undefined` or `null`
126127
- Support cross-realm errors
127128

129+
## TypeScript
130+
131+
TypeScript types have been simplified.
132+
128133
## Internal
129134

130-
- Add 100% test coverage
135+
Added 100% test coverage.
131136

132137
# 9.4.0
133138

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ seconds.
9191

9292
### onError
9393

94-
_Type_: `(Error, string) => Promise<void> | void`\
94+
_Type_: `(error, event) => Promise<void> | void`\
9595
_Default_: `console.error(error)`
9696

9797
Function called once per process error. Duplicate process errors are ignored.

test/helpers/error.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,12 @@ export const getRandomMessageError = function () {
1414
export const getObjectError = function (eventName) {
1515
return eventName === 'warning' ? 'message' : { message: 'message' }
1616
}
17+
18+
export const getInvalidError = function () {
19+
// eslint-disable-next-line fp/no-mutating-assign
20+
return Object.assign(getError(), {
21+
name: undefined,
22+
message: undefined,
23+
stack: undefined,
24+
})
25+
}

test/repeat.js

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
import test from 'ava'
22
import { each } from 'test-each'
33

4-
import { getRandomMessageError, getObjectError } from './helpers/error.js'
4+
import {
5+
getRandomMessageError,
6+
getObjectError,
7+
getInvalidError,
8+
} from './helpers/error.js'
59
import {
610
EVENTS,
711
emitMany,
@@ -70,6 +74,23 @@ each(EVENTS, ({ title }, eventName) => {
7074
stopLogging()
7175
},
7276
)
77+
78+
test.serial(
79+
`should not repeat values that are invalid errors | ${title}`,
80+
async (t) => {
81+
if (eventName === 'rejectionHandled') {
82+
return t.pass()
83+
}
84+
85+
const { onError, stopLogging } = startLogging()
86+
87+
t.is(onError.callCount, 0)
88+
await emitManyValues(getInvalidError, eventName, 2)
89+
t.is(onError.callCount, getCallCount(eventName))
90+
91+
stopLogging()
92+
},
93+
)
7394
})
7495

7596
removeProcessListeners()

0 commit comments

Comments
 (0)