@@ -4,55 +4,116 @@ const { Issue, Result, Results } = require("../src/check")
4
4
5
5
const baseDir = "/path/to"
6
6
7
- function buildIssue ( no = 1 ) {
7
+ function buildIssue ( { severity , identifier = 1 } ) {
8
8
return new Issue ( {
9
9
location : {
10
- "@_file" : `/path/to/app/src/source${ no } .kt` ,
11
- "@_line" : `${ no } ` ,
10
+ "@_file" : `/path/to/app/src/source${ identifier } .kt` ,
11
+ "@_line" : `${ identifier } ` ,
12
12
} ,
13
13
"@_id" : "SomeError" ,
14
- "@_severity" : "Warning" ,
15
- "@_message" : `Error message${ no } ` ,
14
+ "@_severity" : severity ,
15
+ "@_message" : `Error message${ identifier } ` ,
16
16
"@_summary" : "Some Error" ,
17
17
"@_errorLine1" : "line1" ,
18
18
"@_errorLine2" : "line2"
19
19
} )
20
20
}
21
21
22
22
beforeEach ( ( ) => {
23
+ core . summary . emptyBuffer ( )
23
24
core . summary . write = jest . fn ( )
24
25
} )
25
26
26
- test ( "single result" , async ( ) => {
27
- const result = new Result ( [ buildIssue ( ) ] )
28
- const results = new Results ( [ { path : "/path/to/app/build/result.xml" , result } ] )
27
+ afterEach ( ( ) => {
28
+ core . summary . write . mockReset ( )
29
+ } )
29
30
30
- await report ( { results, core, baseDir } )
31
+ describe ( "single result" , ( ) => {
32
+ test ( "when the results is success" , async ( ) => {
33
+ const result = new Result ( [ ] )
34
+ const results = new Results ( [ { path : "/path/to/app/build/result.xml" , result } ] )
31
35
32
- expect ( core . summary . write . mock . calls . length ) . toEqual ( 1 )
36
+ await report ( { results , core, baseDir } )
33
37
34
- const summary = core . summary . stringify ( )
38
+ expect ( core . summary . write . mock . calls . length ) . toEqual ( 1 )
39
+
40
+ const summary = core . summary . stringify ( )
41
+
42
+ expect ( summary ) . toMatch ( [
43
+ "<h2>✔ Android Lint</h2>" ,
44
+ "<p>No issue.</p>"
45
+ ] . join ( "\n" ) )
46
+
47
+ expect ( summary ) . not . toMatch ( "<h3>app/build/result.xml</h3>" )
48
+ } )
49
+
50
+ test ( "when the results is error" , async ( ) => {
51
+ const result = new Result ( [ buildIssue ( { severity : "Error" , identifier : 1 } ) ] )
52
+ const results = new Results ( [ { path : "/path/to/app/build/result.xml" , result } ] )
53
+
54
+ await report ( { results, core, baseDir } )
55
+
56
+ expect ( core . summary . write . mock . calls . length ) . toEqual ( 1 )
35
57
36
- expect ( summary ) . toMatch ( "<h2>Android Lint</h2>" )
37
- expect ( summary ) . toMatch ( "<h3>app/build/result.xml</h3>" )
38
- expect ( summary ) . toMatch ( "<details><summary>⚠️ Warnings</summary>" )
39
- expect ( summary ) . toMatch ( "#### app/src/source1.kt (1 issues)" )
40
- expect ( summary ) . toMatch ( "* **Line#1** - SomeError: Error message1" )
41
- expect ( summary ) . toMatch ( " ```" )
42
- expect ( summary ) . toMatch ( " line1" )
43
- expect ( summary ) . toMatch ( " line2" )
44
- expect ( summary ) . toMatch ( " ```" )
58
+ const summary = core . summary . stringify ( )
59
+
60
+ expect ( summary ) . toMatch ( [
61
+ "<h2>❌ Android Lint</h2>" ,
62
+ "<h3>app/build/result.xml</h3>" ,
63
+ "<details><summary>❌ Errors</summary>" ,
64
+ "" ,
65
+ "#### app/src/source1.kt (1 issues)" ,
66
+ "* **Line#1** - SomeError: Error message1" ,
67
+ " ```" ,
68
+ " line1" ,
69
+ " line2" ,
70
+ " ```"
71
+ ] . join ( "\n" ) )
72
+
73
+ expect ( summary ) . not . toMatch ( "No issue" )
74
+ expect ( summary ) . not . toMatch ( "Warnings" )
75
+ } )
76
+
77
+ test ( "when the results is warning" , async ( ) => {
78
+ const result = new Result ( [ buildIssue ( { severity : "Warning" , identifier : 2 } ) ] )
79
+ const results = new Results ( [ { path : "/path/to/app/build/result.xml" , result } ] )
80
+
81
+ await report ( { results, core, baseDir } )
82
+
83
+ expect ( core . summary . write . mock . calls . length ) . toEqual ( 1 )
84
+
85
+ const summary = core . summary . stringify ( )
86
+
87
+ expect ( summary ) . toMatch ( [
88
+ "<h2>⚠ Android Lint</h2>" ,
89
+ "<h3>app/build/result.xml</h3>" ,
90
+ "<details><summary>⚠️ Warnings</summary>" ,
91
+ "" ,
92
+ "#### app/src/source2.kt (1 issues)" ,
93
+ "* **Line#2** - SomeError: Error message2" ,
94
+ " ```" ,
95
+ " line1" ,
96
+ " line2" ,
97
+ " ```"
98
+ ] . join ( "\n" ) )
99
+
100
+ expect ( summary ) . not . toMatch ( "No issue" )
101
+ expect ( summary ) . not . toMatch ( "Errors" )
102
+ } )
45
103
} )
46
104
47
105
test ( "multiple results" , async ( ) => {
48
106
const results = new Results ( [
49
107
{
50
108
path : "/path/to/app/build/result1.xml" ,
51
- result : new Result ( [ buildIssue ( 1 ) , buildIssue ( 2 ) ] )
109
+ result : new Result ( [
110
+ buildIssue ( { identifier : 1 , severity : "Error" } ) ,
111
+ buildIssue ( { identifier : 2 , severity : "Warning" } )
112
+ ] )
52
113
} ,
53
114
{
54
115
path : "/path/to/app/build/result2.xml" ,
55
- result : new Result ( [ buildIssue ( 3 ) ] )
116
+ result : new Result ( [ buildIssue ( { identifier : 3 , severity : "Error" } ) ] )
56
117
}
57
118
] )
58
119
@@ -62,12 +123,36 @@ test("multiple results", async () => {
62
123
63
124
const summary = core . summary . stringify ( )
64
125
65
- expect ( summary ) . toMatch ( "<h2>Android Lint</h2>" )
66
- expect ( summary ) . toMatch ( "<h3>app/build/result1.xml</h3>" )
67
- expect ( summary ) . toMatch ( "<details><summary>⚠️ Warnings</summary>" )
68
- expect ( summary ) . toMatch ( "#### app/src/source1.kt (1 issues)" )
69
- expect ( summary ) . toMatch ( "* **Line#1** - SomeError: Error message1" )
70
- expect ( summary ) . toMatch ( "* **Line#2** - SomeError: Error message2" )
71
- expect ( summary ) . toMatch ( "#### app/src/source2.kt (1 issues)" )
72
- expect ( summary ) . toMatch ( "* **Line#3** - SomeError: Error message3" )
126
+ expect ( summary ) . toMatch ( [
127
+ "<h2>❌ Android Lint</h2>" ,
128
+ "<h3>app/build/result1.xml</h3>" ,
129
+ "<details><summary>❌ Errors</summary>" ,
130
+ "" ,
131
+ "#### app/src/source1.kt (1 issues)" ,
132
+ "* **Line#1** - SomeError: Error message1" ,
133
+ " ```" ,
134
+ " line1" ,
135
+ " line2" ,
136
+ " ```" ,
137
+ "</details>" ,
138
+ "<details><summary>⚠️ Warnings</summary>" ,
139
+ "" ,
140
+ "#### app/src/source2.kt (1 issues)" ,
141
+ "* **Line#2** - SomeError: Error message2" ,
142
+ " ```" ,
143
+ " line1" ,
144
+ " line2" ,
145
+ " ```" ,
146
+ "</details>" ,
147
+ "<h3>app/build/result2.xml</h3>" ,
148
+ "<details><summary>❌ Errors</summary>" ,
149
+ "" ,
150
+ "#### app/src/source3.kt (1 issues)" ,
151
+ "* **Line#3** - SomeError: Error message3" ,
152
+ " ```" ,
153
+ " line1" ,
154
+ " line2" ,
155
+ " ```" ,
156
+ "</details>"
157
+ ] . join ( "\n" ) )
73
158
} )
0 commit comments