Skip to content

Commit 1d6c541

Browse files
committed
Add tests for --unhandled-rejections
1 parent 6e13766 commit 1d6c541

File tree

3 files changed

+216
-0
lines changed

3 files changed

+216
-0
lines changed

test/register.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,30 @@ testEach(EVENTS, ({ title }, { eventName }) => {
2222
)
2323
})
2424

25+
test(`should work with --unhandled-rejections=none | ${title}`, async t => {
26+
t.snapshot(
27+
await normalizeCall(
28+
`node --unhandled-rejections=none ${LOADERS}/simple.js ${eventName}`,
29+
),
30+
)
31+
})
32+
33+
test(`should work with --unhandled-rejections=warn | ${title}`, async t => {
34+
t.snapshot(
35+
await normalizeCall(
36+
`node --unhandled-rejections=warn ${LOADERS}/simple.js ${eventName}`,
37+
),
38+
)
39+
})
40+
41+
test(`should work with --unhandled-rejections=strict | ${title}`, async t => {
42+
t.snapshot(
43+
await normalizeCall(
44+
`node --unhandled-rejections=strict ${LOADERS}/simple.js ${eventName}`,
45+
),
46+
)
47+
})
48+
2549
test(`should work using both the -r flag and init() | ${title}`, async t => {
2650
t.snapshot(await normalizeCall(`node ${LOADERS}/noop.js ${eventName}`))
2751
})

test/snapshots/register.js.md

Lines changed: 192 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,3 +173,195 @@ Generated by [AVA](https://ava.li).
173173
at STACK TRACE`,
174174
stdout: '',
175175
}
176+
177+
## should work with --unhandled-rejections=none | multipleResolves
178+
179+
> Snapshot 1
180+
181+
{
182+
exitCode: 0,
183+
stderr: '',
184+
stdout: `i multipleResolves (a promise was multiple times) ␊
185+
Initially resolved with: { success: true }␊
186+
Then rejected with: Error: message␊
187+
at STACK TRACE`,
188+
}
189+
190+
## should work with --unhandled-rejections=none | rejectionHandled
191+
192+
> Snapshot 1
193+
194+
{
195+
exitCode: 0,
196+
stderr: `× unhandledRejection (a promise was rejected but not handled) Error: message␊
197+
at STACK TRACE␊
198+
× rejectionHandled (a promise was rejected and handled too late) Error: message␊
199+
at STACK TRACE`,
200+
stdout: '',
201+
}
202+
203+
## should work with --unhandled-rejections=none | uncaughtException
204+
205+
> Snapshot 1
206+
207+
{
208+
exitCode: 1,
209+
stderr: `× uncaughtException (an exception was thrown but not caught) Error: message␊
210+
at STACK TRACE`,
211+
stdout: '',
212+
}
213+
214+
## should work with --unhandled-rejections=none | unhandledRejection
215+
216+
> Snapshot 1
217+
218+
{
219+
exitCode: 0,
220+
stderr: `× unhandledRejection (a promise was rejected but not handled) Error: message␊
221+
at STACK TRACE`,
222+
stdout: '',
223+
}
224+
225+
## should work with --unhandled-rejections=none | warning
226+
227+
> Snapshot 1
228+
229+
{
230+
exitCode: 0,
231+
stderr: `‼ warning (WarningType) message␊
232+
[500] Detail␊
233+
at STACK TRACE`,
234+
stdout: '',
235+
}
236+
237+
## should work with --unhandled-rejections=strict | multipleResolves
238+
239+
> Snapshot 1
240+
241+
{
242+
exitCode: 0,
243+
stderr: '',
244+
stdout: `i multipleResolves (a promise was multiple times) ␊
245+
Initially resolved with: { success: true }␊
246+
Then rejected with: Error: message␊
247+
at STACK TRACE`,
248+
}
249+
250+
## should work with --unhandled-rejections=strict | rejectionHandled
251+
252+
> Snapshot 1
253+
254+
{
255+
exitCode: 1,
256+
stderr: `× uncaughtException (an exception was thrown but not caught) Error: message␊
257+
at STACK TRACE␊
258+
× unhandledRejection (a promise was rejected but not handled) Error: message␊
259+
at STACK TRACE␊
260+
× rejectionHandled (a promise was rejected and handled too late) Error: message␊
261+
at STACK TRACE`,
262+
stdout: '',
263+
}
264+
265+
## should work with --unhandled-rejections=strict | uncaughtException
266+
267+
> Snapshot 1
268+
269+
{
270+
exitCode: 1,
271+
stderr: `× uncaughtException (an exception was thrown but not caught) Error: message␊
272+
at STACK TRACE`,
273+
stdout: '',
274+
}
275+
276+
## should work with --unhandled-rejections=strict | unhandledRejection
277+
278+
> Snapshot 1
279+
280+
{
281+
exitCode: 1,
282+
stderr: `× uncaughtException (an exception was thrown but not caught) Error: message␊
283+
at STACK TRACE␊
284+
× unhandledRejection (a promise was rejected but not handled) Error: message␊
285+
at STACK TRACE`,
286+
stdout: '',
287+
}
288+
289+
## should work with --unhandled-rejections=strict | warning
290+
291+
> Snapshot 1
292+
293+
{
294+
exitCode: 0,
295+
stderr: `‼ warning (WarningType) message␊
296+
[500] Detail␊
297+
at STACK TRACE`,
298+
stdout: '',
299+
}
300+
301+
## should work with --unhandled-rejections=warn | multipleResolves
302+
303+
> Snapshot 1
304+
305+
{
306+
exitCode: 0,
307+
stderr: '',
308+
stdout: `i multipleResolves (a promise was multiple times) ␊
309+
Initially resolved with: { success: true }␊
310+
Then rejected with: Error: message␊
311+
at STACK TRACE`,
312+
}
313+
314+
## should work with --unhandled-rejections=warn | rejectionHandled
315+
316+
> Snapshot 1
317+
318+
{
319+
exitCode: 0,
320+
stderr: `× unhandledRejection (a promise was rejected but not handled) Error: message␊
321+
at STACK TRACE␊
322+
‼ warning (UnhandledPromiseRejectionWarning) Error: message␊
323+
at STACK TRACE␊
324+
‼ warning (UnhandledPromiseRejectionWarning) Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)␊
325+
at STACK TRACE␊
326+
× rejectionHandled (a promise was rejected and handled too late) Error: message␊
327+
at STACK TRACE`,
328+
stdout: '',
329+
}
330+
331+
## should work with --unhandled-rejections=warn | uncaughtException
332+
333+
> Snapshot 1
334+
335+
{
336+
exitCode: 1,
337+
stderr: `× uncaughtException (an exception was thrown but not caught) Error: message␊
338+
at STACK TRACE`,
339+
stdout: '',
340+
}
341+
342+
## should work with --unhandled-rejections=warn | unhandledRejection
343+
344+
> Snapshot 1
345+
346+
{
347+
exitCode: 0,
348+
stderr: `× unhandledRejection (a promise was rejected but not handled) Error: message␊
349+
at STACK TRACE␊
350+
‼ warning (UnhandledPromiseRejectionWarning) Error: message␊
351+
at STACK TRACE␊
352+
‼ warning (UnhandledPromiseRejectionWarning) Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)␊
353+
at STACK TRACE`,
354+
stdout: '',
355+
}
356+
357+
## should work with --unhandled-rejections=warn | warning
358+
359+
> Snapshot 1
360+
361+
{
362+
exitCode: 0,
363+
stderr: `‼ warning (WarningType) message␊
364+
[500] Detail␊
365+
at STACK TRACE`,
366+
stdout: '',
367+
}

test/snapshots/register.js.snap

576 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)