Skip to content

Commit eb43932

Browse files
committed
Move warnings tests
1 parent 1d6c541 commit eb43932

File tree

4 files changed

+274
-34
lines changed

4 files changed

+274
-34
lines changed

test/register.js

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -14,38 +14,6 @@ testEach(EVENTS, ({ title }, { eventName }) => {
1414
t.snapshot(await normalizeCall(`node ${LOADERS}/register.js ${eventName}`))
1515
})
1616

17-
test(`should work with --no-warnings | ${title}`, async t => {
18-
t.snapshot(
19-
await normalizeCall(
20-
`node --no-warnings ${LOADERS}/simple.js ${eventName}`,
21-
),
22-
)
23-
})
24-
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-
4917
test(`should work using both the -r flag and init() | ${title}`, async t => {
5018
t.snapshot(await normalizeCall(`node ${LOADERS}/noop.js ${eventName}`))
5119
})

test/snapshots/warnings.js.md

Lines changed: 252 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,255 @@ Generated by [AVA](https://ava.li).
1616
> Snapshot 1
1717
1818
'(node:PID) WarningType: message'
19+
20+
## should work with warnings-related CLI flags | multipleResolves "--no-warnings"
21+
22+
> Snapshot 1
23+
24+
{
25+
exitCode: 0,
26+
stderr: '',
27+
stdout: `i multipleResolves (a promise was multiple times) ␊
28+
Initially resolved with: { success: true }␊
29+
Then rejected with: Error: message␊
30+
at STACK TRACE`,
31+
}
32+
33+
## should work with warnings-related CLI flags | multipleResolves "--unhandled-rejections=none"
34+
35+
> Snapshot 1
36+
37+
{
38+
exitCode: 0,
39+
stderr: '',
40+
stdout: `i multipleResolves (a promise was multiple times) ␊
41+
Initially resolved with: { success: true }␊
42+
Then rejected with: Error: message␊
43+
at STACK TRACE`,
44+
}
45+
46+
## should work with warnings-related CLI flags | multipleResolves "--unhandled-rejections=strict"
47+
48+
> Snapshot 1
49+
50+
{
51+
exitCode: 0,
52+
stderr: '',
53+
stdout: `i multipleResolves (a promise was multiple times) ␊
54+
Initially resolved with: { success: true }␊
55+
Then rejected with: Error: message␊
56+
at STACK TRACE`,
57+
}
58+
59+
## should work with warnings-related CLI flags | multipleResolves "--unhandled-rejections=warn"
60+
61+
> Snapshot 1
62+
63+
{
64+
exitCode: 0,
65+
stderr: '',
66+
stdout: `i multipleResolves (a promise was multiple times) ␊
67+
Initially resolved with: { success: true }␊
68+
Then rejected with: Error: message␊
69+
at STACK TRACE`,
70+
}
71+
72+
## should work with warnings-related CLI flags | rejectionHandled "--no-warnings"
73+
74+
> Snapshot 1
75+
76+
{
77+
exitCode: 0,
78+
stderr: `× unhandledRejection (a promise was rejected but not handled) Error: message␊
79+
at STACK TRACE␊
80+
× rejectionHandled (a promise was rejected and handled too late) Error: message␊
81+
at STACK TRACE`,
82+
stdout: '',
83+
}
84+
85+
## should work with warnings-related CLI flags | rejectionHandled "--unhandled-rejections=none"
86+
87+
> Snapshot 1
88+
89+
{
90+
exitCode: 0,
91+
stderr: `× unhandledRejection (a promise was rejected but not handled) Error: message␊
92+
at STACK TRACE␊
93+
× rejectionHandled (a promise was rejected and handled too late) Error: message␊
94+
at STACK TRACE`,
95+
stdout: '',
96+
}
97+
98+
## should work with warnings-related CLI flags | rejectionHandled "--unhandled-rejections=strict"
99+
100+
> Snapshot 1
101+
102+
{
103+
exitCode: 1,
104+
stderr: `× uncaughtException (an exception was thrown but not caught) Error: message␊
105+
at STACK TRACE␊
106+
× unhandledRejection (a promise was rejected but not handled) Error: message␊
107+
at STACK TRACE␊
108+
× rejectionHandled (a promise was rejected and handled too late) Error: message␊
109+
at STACK TRACE`,
110+
stdout: '',
111+
}
112+
113+
## should work with warnings-related CLI flags | rejectionHandled "--unhandled-rejections=warn"
114+
115+
> Snapshot 1
116+
117+
{
118+
exitCode: 0,
119+
stderr: `× unhandledRejection (a promise was rejected but not handled) Error: message␊
120+
at STACK TRACE␊
121+
‼ warning (UnhandledPromiseRejectionWarning) Error: message␊
122+
at STACK TRACE␊
123+
‼ 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)␊
124+
at STACK TRACE␊
125+
× rejectionHandled (a promise was rejected and handled too late) Error: message␊
126+
at STACK TRACE`,
127+
stdout: '',
128+
}
129+
130+
## should work with warnings-related CLI flags | uncaughtException "--no-warnings"
131+
132+
> Snapshot 1
133+
134+
{
135+
exitCode: 1,
136+
stderr: `× uncaughtException (an exception was thrown but not caught) Error: message␊
137+
at STACK TRACE`,
138+
stdout: '',
139+
}
140+
141+
## should work with warnings-related CLI flags | uncaughtException "--unhandled-rejections=none"
142+
143+
> Snapshot 1
144+
145+
{
146+
exitCode: 1,
147+
stderr: `× uncaughtException (an exception was thrown but not caught) Error: message␊
148+
at STACK TRACE`,
149+
stdout: '',
150+
}
151+
152+
## should work with warnings-related CLI flags | uncaughtException "--unhandled-rejections=strict"
153+
154+
> Snapshot 1
155+
156+
{
157+
exitCode: 1,
158+
stderr: `× uncaughtException (an exception was thrown but not caught) Error: message␊
159+
at STACK TRACE`,
160+
stdout: '',
161+
}
162+
163+
## should work with warnings-related CLI flags | uncaughtException "--unhandled-rejections=warn"
164+
165+
> Snapshot 1
166+
167+
{
168+
exitCode: 1,
169+
stderr: `× uncaughtException (an exception was thrown but not caught) Error: message␊
170+
at STACK TRACE`,
171+
stdout: '',
172+
}
173+
174+
## should work with warnings-related CLI flags | unhandledRejection "--no-warnings"
175+
176+
> Snapshot 1
177+
178+
{
179+
exitCode: 0,
180+
stderr: `× unhandledRejection (a promise was rejected but not handled) Error: message␊
181+
at STACK TRACE`,
182+
stdout: '',
183+
}
184+
185+
## should work with warnings-related CLI flags | unhandledRejection "--unhandled-rejections=none"
186+
187+
> Snapshot 1
188+
189+
{
190+
exitCode: 0,
191+
stderr: `× unhandledRejection (a promise was rejected but not handled) Error: message␊
192+
at STACK TRACE`,
193+
stdout: '',
194+
}
195+
196+
## should work with warnings-related CLI flags | unhandledRejection "--unhandled-rejections=strict"
197+
198+
> Snapshot 1
199+
200+
{
201+
exitCode: 1,
202+
stderr: `× uncaughtException (an exception was thrown but not caught) Error: message␊
203+
at STACK TRACE␊
204+
× unhandledRejection (a promise was rejected but not handled) Error: message␊
205+
at STACK TRACE`,
206+
stdout: '',
207+
}
208+
209+
## should work with warnings-related CLI flags | unhandledRejection "--unhandled-rejections=warn"
210+
211+
> Snapshot 1
212+
213+
{
214+
exitCode: 0,
215+
stderr: `× unhandledRejection (a promise was rejected but not handled) Error: message␊
216+
at STACK TRACE␊
217+
‼ warning (UnhandledPromiseRejectionWarning) Error: message␊
218+
at STACK TRACE␊
219+
‼ 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)␊
220+
at STACK TRACE`,
221+
stdout: '',
222+
}
223+
224+
## should work with warnings-related CLI flags | warning "--no-warnings"
225+
226+
> Snapshot 1
227+
228+
{
229+
exitCode: 0,
230+
stderr: `‼ warning (WarningType) message␊
231+
[500] Detail␊
232+
at STACK TRACE`,
233+
stdout: '',
234+
}
235+
236+
## should work with warnings-related CLI flags | warning "--unhandled-rejections=none"
237+
238+
> Snapshot 1
239+
240+
{
241+
exitCode: 0,
242+
stderr: `‼ warning (WarningType) message␊
243+
[500] Detail␊
244+
at STACK TRACE`,
245+
stdout: '',
246+
}
247+
248+
## should work with warnings-related CLI flags | warning "--unhandled-rejections=strict"
249+
250+
> Snapshot 1
251+
252+
{
253+
exitCode: 0,
254+
stderr: `‼ warning (WarningType) message␊
255+
[500] Detail␊
256+
at STACK TRACE`,
257+
stdout: '',
258+
}
259+
260+
## should work with warnings-related CLI flags | warning "--unhandled-rejections=warn"
261+
262+
> Snapshot 1
263+
264+
{
265+
exitCode: 0,
266+
stderr: `‼ warning (WarningType) message␊
267+
[500] Detail␊
268+
at STACK TRACE`,
269+
stdout: '',
270+
}

test/snapshots/warnings.js.snap

1.04 KB
Binary file not shown.

test/warnings.js

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
import test from 'ava'
22
import sinon from 'sinon'
3+
import testEach from 'test-each'
34

4-
import { EVENTS_MAP } from './helpers/events/main.js'
5+
import { EVENTS, EVENTS_MAP } from './helpers/events/main.js'
56
import { startLogging } from './helpers/init.js'
6-
import { normalizeMessage } from './helpers/normalize.js'
7+
import { normalizeMessage, normalizeCall } from './helpers/normalize.js'
78
import { removeProcessListeners } from './helpers/remove.js'
89

10+
const LOADERS = `${__dirname}/helpers/loaders/`
11+
912
removeProcessListeners()
1013

1114
const {
@@ -53,3 +56,20 @@ test.serial(
5356
stub.restore()
5457
},
5558
)
59+
60+
testEach(
61+
EVENTS,
62+
[
63+
'--no-warnings',
64+
'--unhandled-rejections=none',
65+
'--unhandled-rejections=warn',
66+
'--unhandled-rejections=strict',
67+
],
68+
({ title }, { eventName }, flag) => {
69+
test(`should work with warnings-related CLI flags | ${title}`, async t => {
70+
t.snapshot(
71+
await normalizeCall(`node ${flag} ${LOADERS}/simple.js ${eventName}`),
72+
)
73+
})
74+
},
75+
)

0 commit comments

Comments
 (0)