@@ -7,91 +7,138 @@ const ok = chalk.bold(`${chalk.green('✔')} found 0 problems, 0 warnings`);
77
88test ( 'does nothing without arguments' , t => {
99 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 ) ;
1116} ) ;
1217
1318test ( '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 ) ;
1621} ) ;
1722
1823test ( '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+ ]
2231 } ) ;
2332
24- t . true ( msg . includes ( '0 problems, 0 warnings' ) ) ;
33+ t . true ( actual . includes ( '0 problems, 0 warnings' ) ) ;
2534} ) ;
2635
2736test ( 'returns a correct of empty .errors and .warnings' , t => {
28- const [ err , prob , msg ] = format ( {
29- errors : [
37+ const actualError = format ( {
38+ results : [
3039 {
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+ ]
3447 }
35- ] ,
36- warnings : [
48+ ]
49+ } ) ;
50+
51+ const actualWarning = format ( {
52+ results : [
3753 {
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+ ]
4161 }
4262 ]
4363 } ) ;
4464
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' ) ) ;
4869} ) ;
4970
5071test ( 'uses appropriate signs by default' , t => {
51- const [ err , warn ] = format ( {
52- errors : [
72+ const actualError = format ( {
73+ results : [
5374 {
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+ ]
5782 }
58- ] ,
59- warnings : [
83+ ]
84+ } ) ;
85+
86+ const actualWarning = format ( {
87+ results : [
6088 {
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+ ]
6496 }
6597 ]
6698 } ) ;
6799
68- t . true ( includes ( err , '✖' ) ) ;
69- t . true ( includes ( warn , '⚠' ) ) ;
100+ t . true ( includes ( actualError , '✖' ) ) ;
101+ t . true ( includes ( actualWarning , '⚠' ) ) ;
70102} ) ;
71103
72104test ( 'uses signs as configured' , t => {
73- const [ err , warn ] = format (
105+ const options = { signs : [ 'HNT' , 'WRN' , 'ERR' ] } ;
106+ const actualError = format (
74107 {
75- errors : [
108+ results : [
76109 {
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+ ]
80117 }
81- ] ,
82- warnings : [
118+ ]
119+ } ,
120+ { } ,
121+ options
122+ ) ;
123+
124+ const actualWarning = format (
125+ {
126+ results : [
83127 {
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+ ]
87135 }
88136 ]
89137 } ,
90- {
91- signs : [ 'HNT' , 'WRN' , 'ERR' ]
92- }
138+ { } ,
139+ options
93140 ) ;
94141
95- t . true ( includes ( err , 'ERR' ) ) ;
96- t . true ( includes ( warn , 'WRN' ) ) ;
142+ t . true ( includes ( actualError , 'ERR' ) ) ;
143+ t . true ( includes ( actualWarning , 'WRN' ) ) ;
97144} ) ;
0 commit comments