@@ -7,91 +7,138 @@ const ok = chalk.bold(`${chalk.green('✔')} found 0 problems, 0 warnings`);
7
7
8
8
test ( 'does nothing without arguments' , t => {
9
9
const actual = format ( ) ;
10
- t . deepEqual ( actual , [ ok ] ) ;
10
+ t . deepEqual ( actual , ok ) ;
11
+ } ) ;
12
+
13
+ test ( 'does nothing without report results' , t => {
14
+ const actual = format ( { results : [ ] } ) ;
15
+ t . deepEqual ( actual , ok ) ;
11
16
} ) ;
12
17
13
18
test ( 'does nothing without .errors and .warnings' , t => {
14
- const actual = format ( { } ) ;
15
- t . deepEqual ( actual , [ ok ] ) ;
19
+ const actual = format ( { results : [ { } ] } ) ;
20
+ t . deepEqual ( actual , ok ) ;
16
21
} ) ;
17
22
18
23
test ( 'returns empty summary of problems for empty .errors and .warnings' , t => {
19
- const [ msg ] = format ( {
20
- errors : [ ] ,
21
- warnings : [ ]
24
+ const actual = format ( {
25
+ results : [
26
+ {
27
+ errors : [ ] ,
28
+ warnings : [ ]
29
+ }
30
+ ]
22
31
} ) ;
23
32
24
- t . true ( msg . includes ( '0 problems, 0 warnings' ) ) ;
33
+ t . true ( actual . includes ( '0 problems, 0 warnings' ) ) ;
25
34
} ) ;
26
35
27
36
test ( 'returns a correct of empty .errors and .warnings' , t => {
28
- const [ err , prob , msg ] = format ( {
29
- errors : [
37
+ const actualError = format ( {
38
+ results : [
30
39
{
31
- level : 2 ,
32
- name : 'error-name' ,
33
- message : 'There was an error'
40
+ errors : [
41
+ {
42
+ level : 2 ,
43
+ name : 'error-name' ,
44
+ message : 'There was an error'
45
+ }
46
+ ]
34
47
}
35
- ] ,
36
- warnings : [
48
+ ]
49
+ } ) ;
50
+
51
+ const actualWarning = format ( {
52
+ results : [
37
53
{
38
- level : 1 ,
39
- name : 'warning-name' ,
40
- message : 'There was a problem'
54
+ warnings : [
55
+ {
56
+ level : 1 ,
57
+ name : 'warning-name' ,
58
+ message : 'There was a problem'
59
+ }
60
+ ]
41
61
}
42
62
]
43
63
} ) ;
44
64
45
- t . true ( includes ( err , 'There was an error' ) ) ;
46
- t . true ( includes ( prob , 'There was a problem' ) ) ;
47
- t . true ( includes ( msg , '1 problems, 1 warnings' ) ) ;
65
+ t . true ( includes ( actualError , 'There was an error' ) ) ;
66
+ t . true ( includes ( actualError , '1 problems, 0 warnings' ) ) ;
67
+ t . true ( includes ( actualWarning , 'There was a problem' ) ) ;
68
+ t . true ( includes ( actualWarning , '0 problems, 1 warnings' ) ) ;
48
69
} ) ;
49
70
50
71
test ( 'uses appropriate signs by default' , t => {
51
- const [ err , warn ] = format ( {
52
- errors : [
72
+ const actualError = format ( {
73
+ results : [
53
74
{
54
- level : 2 ,
55
- name : 'error-name' ,
56
- message : 'There was an error'
75
+ errors : [
76
+ {
77
+ level : 2 ,
78
+ name : 'error-name' ,
79
+ message : 'There was an error'
80
+ }
81
+ ]
57
82
}
58
- ] ,
59
- warnings : [
83
+ ]
84
+ } ) ;
85
+
86
+ const actualWarning = format ( {
87
+ results : [
60
88
{
61
- level : 1 ,
62
- name : 'warning-name' ,
63
- message : 'There was a problem'
89
+ warnings : [
90
+ {
91
+ level : 1 ,
92
+ name : 'warning-name' ,
93
+ message : 'There was a problem'
94
+ }
95
+ ]
64
96
}
65
97
]
66
98
} ) ;
67
99
68
- t . true ( includes ( err , '✖' ) ) ;
69
- t . true ( includes ( warn , '⚠' ) ) ;
100
+ t . true ( includes ( actualError , '✖' ) ) ;
101
+ t . true ( includes ( actualWarning , '⚠' ) ) ;
70
102
} ) ;
71
103
72
104
test ( 'uses signs as configured' , t => {
73
- const [ err , warn ] = format (
105
+ const options = { signs : [ 'HNT' , 'WRN' , 'ERR' ] } ;
106
+ const actualError = format (
74
107
{
75
- errors : [
108
+ results : [
76
109
{
77
- level : 2 ,
78
- name : 'error-name' ,
79
- message : 'There was an error'
110
+ errors : [
111
+ {
112
+ level : 2 ,
113
+ name : 'error-name' ,
114
+ message : 'There was an error'
115
+ }
116
+ ]
80
117
}
81
- ] ,
82
- warnings : [
118
+ ]
119
+ } ,
120
+ { } ,
121
+ options
122
+ ) ;
123
+
124
+ const actualWarning = format (
125
+ {
126
+ results : [
83
127
{
84
- level : 1 ,
85
- name : 'warning-name' ,
86
- message : 'There was a problem'
128
+ warnings : [
129
+ {
130
+ level : 1 ,
131
+ name : 'warning-name' ,
132
+ message : 'There was a problem'
133
+ }
134
+ ]
87
135
}
88
136
]
89
137
} ,
90
- {
91
- signs : [ 'HNT' , 'WRN' , 'ERR' ]
92
- }
138
+ { } ,
139
+ options
93
140
) ;
94
141
95
- t . true ( includes ( err , 'ERR' ) ) ;
96
- t . true ( includes ( warn , 'WRN' ) ) ;
142
+ t . true ( includes ( actualError , 'ERR' ) ) ;
143
+ t . true ( includes ( actualWarning , 'WRN' ) ) ;
97
144
} ) ;
0 commit comments