-
Notifications
You must be signed in to change notification settings - Fork 14
/
index.test.ts
115 lines (94 loc) · 3 KB
/
index.test.ts
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
import ForkTsCheckerNotifierWebpackPlugin from './index';
import { Issue } from 'fork-ts-checker-webpack-plugin/lib/issue';
const error: Issue = {
code: 'code',
severity: 'error',
message: 'broken things',
file: 'errorFile.ts',
location: {
start: {
line: 10,
column: 10,
},
end: {
line: 10,
column: 10,
},
},
};
const warning: Issue = {
code: 'code',
severity: 'warning',
message: 'worrying things',
file: 'warningFile.ts',
location: {
start: {
line: 10,
column: 10,
},
end: {
line: 10,
column: 10,
},
},
};
describe('buildNotification', () => {
test('first notification is skipped', () => {
const plugin = new ForkTsCheckerNotifierWebpackPlugin({
skipFirstNotification: true,
});
const returnValue = plugin.buildNotification([]);
expect(returnValue).toBe(undefined);
expect(plugin.isFirstBuild).toBe(false);
});
test('given warning and error should trigger error notification', () => {
const plugin = new ForkTsCheckerNotifierWebpackPlugin();
const returnValue = plugin.buildNotification([warning, error]);
if (returnValue === undefined) {
throw Error();
}
expect(returnValue.title).toBe(`Error in ${error.file}`);
expect(returnValue.message).toBe(error.message);
expect(returnValue.icon.endsWith('error.png')).toBe(true);
expect(plugin.lastBuildSucceeded).toBe(false);
});
test('given warning should trigger warning notification', () => {
const plugin = new ForkTsCheckerNotifierWebpackPlugin();
const returnValue = plugin.buildNotification([warning]);
if (returnValue === undefined) {
throw Error();
}
expect(returnValue.title).toBe(`Warning in ${warning.file}`);
expect(returnValue.message).toBe(warning.message);
expect(returnValue.icon.endsWith('warning.png')).toBe(true);
expect(plugin.lastBuildSucceeded).toBe(false);
});
test('given warning when excludeWarnings is true should return success', () => {
const plugin = new ForkTsCheckerNotifierWebpackPlugin({
excludeWarnings: true,
});
const returnValue = plugin.buildNotification([warning]);
if (returnValue === undefined) {
throw Error();
}
expect(returnValue.title).toBe('Type check succeeded');
expect(returnValue.message).toBe(
'No type errors! See warning(s) in console!',
);
expect(returnValue.icon.endsWith('built.png')).toBe(true);
expect(plugin.lastBuildSucceeded).toBe(true);
});
test('given no errors or warnings should return success', () => {
const plugin = new ForkTsCheckerNotifierWebpackPlugin({
excludeWarnings: true,
});
const returnValue = plugin.buildNotification([]);
if (returnValue === undefined) {
throw Error();
}
expect(returnValue.title).toBe('Type check succeeded');
expect(returnValue.message).toBe('No type errors!');
expect(returnValue.icon.endsWith('built.png')).toBe(true);
expect(plugin.lastBuildSucceeded).toBe(true);
});
});