Skip to content

Commit 5eaf7cb

Browse files
committed
Add unit tests for new default reporter
1 parent 51a2d18 commit 5eaf7cb

File tree

1 file changed

+203
-3
lines changed

1 file changed

+203
-3
lines changed

packages/jest-core/src/__tests__/TestScheduler.test.js

Lines changed: 203 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
CoverageReporter,
1111
DefaultReporter,
1212
GitHubActionsReporter,
13+
GithubActionsLogsReporter,
1314
NotifyReporter,
1415
SummaryReporter,
1516
VerboseReporter,
@@ -59,13 +60,203 @@ beforeEach(() => {
5960
spyShouldRunInBand.mockClear();
6061
});
6162

62-
describe('reporters', () => {
63+
describe('reporters with GITHUB_ACTIONS = true', () => {
6364
const CustomReporter = require('/custom-reporter.js');
6465

6566
afterEach(() => {
6667
jest.clearAllMocks();
6768
});
6869

70+
test('works with default value', async () => {
71+
await createTestScheduler(
72+
makeGlobalConfig({
73+
reporters: undefined,
74+
}),
75+
{},
76+
{},
77+
);
78+
79+
expect(DefaultReporter).toHaveBeenCalledTimes(0);
80+
expect(GithubActionsLogsReporter).toHaveBeenCalledTimes(1);
81+
expect(VerboseReporter).toHaveBeenCalledTimes(0);
82+
expect(GitHubActionsReporter).toHaveBeenCalledTimes(0);
83+
expect(NotifyReporter).toHaveBeenCalledTimes(0);
84+
expect(CoverageReporter).toHaveBeenCalledTimes(0);
85+
expect(SummaryReporter).toHaveBeenCalledTimes(1);
86+
});
87+
88+
test('does not enable any reporters, if empty list is passed', async () => {
89+
await createTestScheduler(
90+
makeGlobalConfig({
91+
reporters: [],
92+
}),
93+
{},
94+
{},
95+
);
96+
97+
expect(DefaultReporter).toHaveBeenCalledTimes(0);
98+
expect(GithubActionsLogsReporter).toHaveBeenCalledTimes(0);
99+
expect(VerboseReporter).toHaveBeenCalledTimes(0);
100+
expect(GitHubActionsReporter).toHaveBeenCalledTimes(0);
101+
expect(NotifyReporter).toHaveBeenCalledTimes(0);
102+
expect(CoverageReporter).toHaveBeenCalledTimes(0);
103+
expect(SummaryReporter).toHaveBeenCalledTimes(0);
104+
});
105+
106+
test('sets up default reporters', async () => {
107+
await createTestScheduler(
108+
makeGlobalConfig({
109+
reporters: [['default', {}]],
110+
}),
111+
{},
112+
{},
113+
);
114+
115+
expect(DefaultReporter).toHaveBeenCalledTimes(0);
116+
expect(GithubActionsLogsReporter).toHaveBeenCalledTimes(1);
117+
expect(VerboseReporter).toHaveBeenCalledTimes(0);
118+
expect(GitHubActionsReporter).toHaveBeenCalledTimes(0);
119+
expect(NotifyReporter).toHaveBeenCalledTimes(0);
120+
expect(CoverageReporter).toHaveBeenCalledTimes(0);
121+
expect(SummaryReporter).toHaveBeenCalledTimes(1);
122+
});
123+
124+
test('sets up verbose reporter', async () => {
125+
await createTestScheduler(
126+
makeGlobalConfig({
127+
reporters: [['default', {}]],
128+
verbose: true,
129+
}),
130+
{},
131+
{},
132+
);
133+
134+
expect(DefaultReporter).toHaveBeenCalledTimes(0);
135+
expect(GithubActionsLogsReporter).toHaveBeenCalledTimes(0);
136+
expect(VerboseReporter).toHaveBeenCalledTimes(1);
137+
expect(GitHubActionsReporter).toHaveBeenCalledTimes(0);
138+
expect(NotifyReporter).toHaveBeenCalledTimes(0);
139+
expect(CoverageReporter).toHaveBeenCalledTimes(0);
140+
expect(SummaryReporter).toHaveBeenCalledTimes(1);
141+
});
142+
143+
test('sets up github actions reporter', async () => {
144+
await createTestScheduler(
145+
makeGlobalConfig({
146+
reporters: [
147+
['default', {}],
148+
['github-actions', {}],
149+
],
150+
}),
151+
{},
152+
{},
153+
);
154+
155+
expect(DefaultReporter).toHaveBeenCalledTimes(0);
156+
expect(GithubActionsLogsReporter).toHaveBeenCalledTimes(1);
157+
expect(VerboseReporter).toHaveBeenCalledTimes(0);
158+
expect(GitHubActionsReporter).toHaveBeenCalledTimes(1);
159+
expect(NotifyReporter).toHaveBeenCalledTimes(0);
160+
expect(CoverageReporter).toHaveBeenCalledTimes(0);
161+
expect(SummaryReporter).toHaveBeenCalledTimes(1);
162+
});
163+
164+
test('sets up notify reporter', async () => {
165+
await createTestScheduler(
166+
makeGlobalConfig({
167+
notify: true,
168+
reporters: [['default', {}]],
169+
}),
170+
{},
171+
{},
172+
);
173+
174+
expect(DefaultReporter).toHaveBeenCalledTimes(0);
175+
expect(GithubActionsLogsReporter).toHaveBeenCalledTimes(1);
176+
expect(VerboseReporter).toHaveBeenCalledTimes(0);
177+
expect(GitHubActionsReporter).toHaveBeenCalledTimes(0);
178+
expect(NotifyReporter).toHaveBeenCalledTimes(1);
179+
expect(CoverageReporter).toHaveBeenCalledTimes(0);
180+
expect(SummaryReporter).toHaveBeenCalledTimes(1);
181+
});
182+
183+
test('sets up coverage reporter', async () => {
184+
await createTestScheduler(
185+
makeGlobalConfig({
186+
collectCoverage: true,
187+
reporters: [['default', {}]],
188+
}),
189+
{},
190+
{},
191+
);
192+
193+
expect(DefaultReporter).toHaveBeenCalledTimes(0);
194+
expect(GithubActionsLogsReporter).toHaveBeenCalledTimes(1);
195+
expect(VerboseReporter).toHaveBeenCalledTimes(0);
196+
expect(GitHubActionsReporter).toHaveBeenCalledTimes(0);
197+
expect(NotifyReporter).toHaveBeenCalledTimes(0);
198+
expect(CoverageReporter).toHaveBeenCalledTimes(1);
199+
expect(SummaryReporter).toHaveBeenCalledTimes(1);
200+
});
201+
202+
test('allows enabling summary reporter separately', async () => {
203+
await createTestScheduler(
204+
makeGlobalConfig({
205+
reporters: [['summary', {}]],
206+
}),
207+
{},
208+
{},
209+
);
210+
211+
expect(DefaultReporter).toHaveBeenCalledTimes(0);
212+
expect(GithubActionsLogsReporter).toHaveBeenCalledTimes(0);
213+
expect(VerboseReporter).toHaveBeenCalledTimes(0);
214+
expect(GitHubActionsReporter).toHaveBeenCalledTimes(0);
215+
expect(NotifyReporter).toHaveBeenCalledTimes(0);
216+
expect(CoverageReporter).toHaveBeenCalledTimes(0);
217+
expect(SummaryReporter).toHaveBeenCalledTimes(1);
218+
});
219+
220+
test('sets up custom reporter', async () => {
221+
await createTestScheduler(
222+
makeGlobalConfig({
223+
reporters: [
224+
['default', {}],
225+
['/custom-reporter.js', {}],
226+
],
227+
}),
228+
{},
229+
{},
230+
);
231+
232+
expect(DefaultReporter).toHaveBeenCalledTimes(0);
233+
expect(GithubActionsLogsReporter).toHaveBeenCalledTimes(1);
234+
expect(VerboseReporter).toHaveBeenCalledTimes(0);
235+
expect(GitHubActionsReporter).toHaveBeenCalledTimes(0);
236+
expect(NotifyReporter).toHaveBeenCalledTimes(0);
237+
expect(CoverageReporter).toHaveBeenCalledTimes(0);
238+
expect(SummaryReporter).toHaveBeenCalledTimes(1);
239+
expect(CustomReporter).toHaveBeenCalledTimes(1);
240+
});
241+
});
242+
243+
describe('reporters with GITHUB_ACTIONS = false', () => {
244+
const CustomReporter = require('/custom-reporter.js');
245+
246+
afterEach(() => {
247+
jest.clearAllMocks();
248+
});
249+
250+
beforeAll(() => {
251+
const ci = require('ci-info');
252+
ci.GITHUB_ACTIONS = false;
253+
});
254+
255+
afterAll(() => {
256+
const ci = require('ci-info');
257+
ci.GITHUB_ACTIONS = true;
258+
});
259+
69260
test('works with default value', async () => {
70261
await createTestScheduler(
71262
makeGlobalConfig({
@@ -76,6 +267,7 @@ describe('reporters', () => {
76267
);
77268

78269
expect(DefaultReporter).toHaveBeenCalledTimes(1);
270+
expect(GithubActionsLogsReporter).toHaveBeenCalledTimes(0);
79271
expect(VerboseReporter).toHaveBeenCalledTimes(0);
80272
expect(GitHubActionsReporter).toHaveBeenCalledTimes(0);
81273
expect(NotifyReporter).toHaveBeenCalledTimes(0);
@@ -93,6 +285,7 @@ describe('reporters', () => {
93285
);
94286

95287
expect(DefaultReporter).toHaveBeenCalledTimes(0);
288+
expect(GithubActionsLogsReporter).toHaveBeenCalledTimes(0);
96289
expect(VerboseReporter).toHaveBeenCalledTimes(0);
97290
expect(GitHubActionsReporter).toHaveBeenCalledTimes(0);
98291
expect(NotifyReporter).toHaveBeenCalledTimes(0);
@@ -110,6 +303,7 @@ describe('reporters', () => {
110303
);
111304

112305
expect(DefaultReporter).toHaveBeenCalledTimes(1);
306+
expect(GithubActionsLogsReporter).toHaveBeenCalledTimes(0);
113307
expect(VerboseReporter).toHaveBeenCalledTimes(0);
114308
expect(GitHubActionsReporter).toHaveBeenCalledTimes(0);
115309
expect(NotifyReporter).toHaveBeenCalledTimes(0);
@@ -128,14 +322,15 @@ describe('reporters', () => {
128322
);
129323

130324
expect(DefaultReporter).toHaveBeenCalledTimes(0);
325+
expect(GithubActionsLogsReporter).toHaveBeenCalledTimes(0);
131326
expect(VerboseReporter).toHaveBeenCalledTimes(1);
132327
expect(GitHubActionsReporter).toHaveBeenCalledTimes(0);
133328
expect(NotifyReporter).toHaveBeenCalledTimes(0);
134329
expect(CoverageReporter).toHaveBeenCalledTimes(0);
135330
expect(SummaryReporter).toHaveBeenCalledTimes(1);
136331
});
137332

138-
test('sets up github actions reporter', async () => {
333+
test('does not set up github actions reporter', async () => {
139334
await createTestScheduler(
140335
makeGlobalConfig({
141336
reporters: [
@@ -148,8 +343,9 @@ describe('reporters', () => {
148343
);
149344

150345
expect(DefaultReporter).toHaveBeenCalledTimes(1);
346+
expect(GithubActionsLogsReporter).toHaveBeenCalledTimes(0);
151347
expect(VerboseReporter).toHaveBeenCalledTimes(0);
152-
expect(GitHubActionsReporter).toHaveBeenCalledTimes(1);
348+
expect(GitHubActionsReporter).toHaveBeenCalledTimes(0);
153349
expect(NotifyReporter).toHaveBeenCalledTimes(0);
154350
expect(CoverageReporter).toHaveBeenCalledTimes(0);
155351
expect(SummaryReporter).toHaveBeenCalledTimes(1);
@@ -166,6 +362,7 @@ describe('reporters', () => {
166362
);
167363

168364
expect(DefaultReporter).toHaveBeenCalledTimes(1);
365+
expect(GithubActionsLogsReporter).toHaveBeenCalledTimes(0);
169366
expect(VerboseReporter).toHaveBeenCalledTimes(0);
170367
expect(GitHubActionsReporter).toHaveBeenCalledTimes(0);
171368
expect(NotifyReporter).toHaveBeenCalledTimes(1);
@@ -184,6 +381,7 @@ describe('reporters', () => {
184381
);
185382

186383
expect(DefaultReporter).toHaveBeenCalledTimes(1);
384+
expect(GithubActionsLogsReporter).toHaveBeenCalledTimes(0);
187385
expect(VerboseReporter).toHaveBeenCalledTimes(0);
188386
expect(GitHubActionsReporter).toHaveBeenCalledTimes(0);
189387
expect(NotifyReporter).toHaveBeenCalledTimes(0);
@@ -201,6 +399,7 @@ describe('reporters', () => {
201399
);
202400

203401
expect(DefaultReporter).toHaveBeenCalledTimes(0);
402+
expect(GithubActionsLogsReporter).toHaveBeenCalledTimes(0);
204403
expect(VerboseReporter).toHaveBeenCalledTimes(0);
205404
expect(GitHubActionsReporter).toHaveBeenCalledTimes(0);
206405
expect(NotifyReporter).toHaveBeenCalledTimes(0);
@@ -221,6 +420,7 @@ describe('reporters', () => {
221420
);
222421

223422
expect(DefaultReporter).toHaveBeenCalledTimes(1);
423+
expect(GithubActionsLogsReporter).toHaveBeenCalledTimes(0);
224424
expect(VerboseReporter).toHaveBeenCalledTimes(0);
225425
expect(GitHubActionsReporter).toHaveBeenCalledTimes(0);
226426
expect(NotifyReporter).toHaveBeenCalledTimes(0);

0 commit comments

Comments
 (0)