Skip to content

Commit 65c9295

Browse files
committed
Added notify reporter test (for review)
1 parent 6ced621 commit 65c9295

File tree

2 files changed

+85
-0
lines changed

2 files changed

+85
-0
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`test always 1`] = `
4+
Array [
5+
Object {
6+
"icon": "SUCCESS_ICON",
7+
"message": "✅ 3 tests passed",
8+
"title": "100% Passed",
9+
},
10+
]
11+
`;
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
/**
2+
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*
7+
*/
8+
9+
'use strict';
10+
11+
import TestScheduler from '../test_scheduler';
12+
import NotifyReporter from '../reporters/notify_reporter';
13+
import type {TestSchedulerContext} from '../test_scheduler';
14+
15+
const SUCCESS_ICON_PATH = '/assets/jest_logo.png';
16+
const FAILURE_ICON_PATH = 'TODO';
17+
18+
jest.mock('../reporters/default_reporter');
19+
jest.mock('node-notifier', () => ({
20+
notify: jest.fn(),
21+
}));
22+
23+
const initialContext: TestSchedulerContext = {
24+
firstRun: true,
25+
previousSuccess: false,
26+
};
27+
28+
const aggregatedResultsSuccess: AggregatedResult = {
29+
numFailedTestSuites: 0,
30+
numFailedTests: 0,
31+
numPassedTestSuites: 1,
32+
numPassedTests: 3,
33+
numRuntimeErrorTestSuites: 0,
34+
numTotalTestSuites: 1,
35+
numTotalTests: 3,
36+
success: true,
37+
};
38+
39+
const iconDir = path => {
40+
if (path.endsWith(SUCCESS_ICON_PATH)) {
41+
return 'SUCCESS_ICON';
42+
} else if (path.endsWith(FAILURE_ICON_PATH)) {
43+
return 'FAILURE_ICON';
44+
} else {
45+
return 'ICON_NOT_FOUND';
46+
}
47+
};
48+
49+
test('.addReporter() .removeReporter()', () => {
50+
const scheduler = new TestScheduler({}, {}, initialContext);
51+
const reporter = new NotifyReporter();
52+
scheduler.addReporter(reporter);
53+
expect(scheduler._dispatcher._reporters).toContain(reporter);
54+
scheduler.removeReporter(NotifyReporter);
55+
expect(scheduler._dispatcher._reporters).not.toContain(reporter);
56+
});
57+
58+
test('test always', () => {
59+
const notify = require('node-notifier');
60+
61+
const reporter = new NotifyReporter(
62+
{notify: true, notifyMode: 'always'},
63+
{},
64+
initialContext,
65+
);
66+
reporter.onRunComplete(new Set(), aggregatedResultsSuccess);
67+
expect(
68+
notify.notify.mock.calls.map(([{icon, message, title}]) => ({
69+
icon: iconDir(icon),
70+
message,
71+
title,
72+
})),
73+
).toMatchSnapshot();
74+
});

0 commit comments

Comments
 (0)