forked from jestjs/jest
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnotify_reporter.test.js
More file actions
119 lines (102 loc) · 2.88 KB
/
notify_reporter.test.js
File metadata and controls
119 lines (102 loc) · 2.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
/**
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
*/
'use strict';
import TestScheduler from '../test_scheduler';
import NotifyReporter from '../reporters/notify_reporter';
import type {TestSchedulerContext} from '../test_scheduler';
import type {AggregatedResult} from '../../../../types/TestResult';
jest.mock('../reporters/default_reporter');
jest.mock('node-notifier', () => ({
notify: jest.fn(),
}));
const initialContext: TestSchedulerContext = {
firstRun: true,
previousSuccess: false,
};
const aggregatedResultsSuccess: AggregatedResult = {
numFailedTestSuites: 0,
numFailedTests: 0,
numPassedTestSuites: 1,
numPassedTests: 3,
numRuntimeErrorTestSuites: 0,
numTotalTestSuites: 1,
numTotalTests: 3,
success: true,
};
const aggregatedResultsFailure: AggregatedResult = {
numFailedTestSuites: 1,
numFailedTests: 3,
numPassedTestSuites: 0,
numPassedTests: 9,
numRuntimeErrorTestSuites: 0,
numTotalTestSuites: 1,
numTotalTests: 3,
success: false,
};
// Simulated sequence of events for NotifyReporter
const notifyEvents = [
aggregatedResultsSuccess,
aggregatedResultsFailure,
aggregatedResultsSuccess,
aggregatedResultsSuccess,
aggregatedResultsFailure,
aggregatedResultsFailure,
];
test('.addReporter() .removeReporter()', () => {
const scheduler = new TestScheduler(
{},
{},
Object.assign({}, initialContext),
);
const reporter = new NotifyReporter();
scheduler.addReporter(reporter);
expect(scheduler._dispatcher._reporters).toContain(reporter);
scheduler.removeReporter(NotifyReporter);
expect(scheduler._dispatcher._reporters).not.toContain(reporter);
});
const testModes = (notifyMode: string, arl: Array<AggregatedResult>) => {
const notify = require('node-notifier');
let previousContext = initialContext;
arl.forEach((ar, i) => {
const newContext = Object.assign(previousContext, {
firstRun: i === 0,
previousSuccess: previousContext.previousSuccess,
});
const reporter = new NotifyReporter(
{notify: true, notifyMode},
{},
newContext,
);
previousContext = newContext;
reporter.onRunComplete(new Set(), ar);
});
expect(
notify.notify.mock.calls.map(([{message, title}]) => ({
message: message.replace('\u26D4\uFE0F ', '').replace('\u2705 ', ''),
title,
})),
).toMatchSnapshot();
};
test('test always', () => {
testModes('always', notifyEvents);
});
test('test success', () => {
testModes('success', notifyEvents);
});
test('test change', () => {
testModes('change', notifyEvents);
});
test('test success-change', () => {
testModes('success-change', notifyEvents);
});
test('test failure-change', () => {
testModes('failure-change', notifyEvents);
});
afterEach(() => {
jest.clearAllMocks();
});