@@ -16,6 +16,12 @@ jest.spyOn(core, "debug").mockImplementation(() => {});
1616jest . spyOn ( core , "setFailed" ) . mockImplementation ( ( ) => { } ) ;
1717jest . spyOn ( core , "setOutput" ) . mockImplementation ( ( ) => { } ) ;
1818
19+ afterEach ( ( ) => {
20+ process . env [ "INPUT_CHECKCOMMITS" ] = "" ;
21+ process . env [ "INPUT_CHECKLABELS" ] = "" ;
22+ process . env [ "INPUT_CHECKDIFF" ] = "" ;
23+ } ) ;
24+
1925describe ( "processCommits" , ( ) => {
2026 test ( "We process commits successfully" , async ( ) => {
2127 let prCommits = [ { author : { login : "robot" } } ] ;
@@ -43,6 +49,53 @@ describe("processCommits", () => {
4349 } ) ;
4450} ) ;
4551
52+ describe ( "processDiff" , ( ) => {
53+ test ( "We process the diff successfully" , async ( ) => {
54+ let prDiff = `| diff --git a/.github/workflows/check-dist.yml b/.github/workflows/check-dist.yml
55+ index 2f4e8d9..93c2072 100644
56+ --- a/.github/workflows/check-dist.yml
57+ +++ b/.github/workflows/check-dist.yml
58+ @@ -44,7 +44,7 @@ jobs:
59+ id: diff
60+
61+ # If index.js was different than expected, upload the expected version as an artifact
62+ - - uses: actions/upload-artifact@v2
63+ if: blah
64+ with:
65+ name: dist` ;
66+ let spy = jest
67+ . spyOn ( pullRequest , "getDiff" )
68+ . mockImplementation ( ( ) => prDiff ) ;
69+ expect ( pullRequest . getDiff ( ) ) . toBe ( prDiff ) ;
70+
71+ let diff = await runner . processDiff ( ) ;
72+ expect ( diff ) . toStrictEqual ( true ) ;
73+ } ) ;
74+
75+ test ( "We process the diff unsuccessfully" , async ( ) => {
76+ let prDiff = `| diff --git a/.github/workflows/check-dist.yml b/.github/workflows/check-dist.yml
77+ index 2f4e8d9..93c2072 100644
78+ --- a/.github/workflows/check-dist.yml
79+ +++ b/.github/workflows/check-dist.yml
80+ @@ -44,7 +44,7 @@ jobs:
81+ id: diff
82+
83+ # If index.js was different than expected, upload the expected version as an artifact
84+ - - uses: actions/upload-artifact@v2
85+ + - uses: actions/upload-artifact@v3
86+ if: blah
87+ with:
88+ name: dist` ;
89+ let spy = jest
90+ . spyOn ( pullRequest , "getDiff" )
91+ . mockImplementation ( ( ) => prDiff ) ;
92+ expect ( pullRequest . getDiff ( ) ) . toBe ( prDiff ) ;
93+
94+ let diff = await runner . processDiff ( ) ;
95+ expect ( diff ) . toStrictEqual ( false ) ;
96+ } ) ;
97+ } ) ;
98+
4699describe ( "labelsEqual" , ( ) => {
47100 test ( "We process labels successfully" , async ( ) => {
48101 let prLabels = [ "bug" , "feature-request" ] ;
@@ -90,8 +143,10 @@ describe("processLabels", () => {
90143} ) ;
91144
92145describe ( "processPrivilegedReviewer" , ( ) => {
93- test ( "We process commits and labels successfully with all options enabled" , async ( ) => {
146+ test ( "We process commits, diff and labels successfully with all options enabled" , async ( ) => {
94147 process . env [ "INPUT_CHECKCOMMITS" ] = "true" ;
148+ process . env [ "INPUT_CHECKLABELS" ] = "true" ;
149+ process . env [ "INPUT_CHECKDIFF" ] = "true" ;
95150 let prLabels = [ { name : "bug" } , { name : "feature-request" } ] ;
96151 let spyLabels = jest
97152 . spyOn ( pullRequest , "listLabels" )
@@ -104,20 +159,31 @@ describe("processPrivilegedReviewer", () => {
104159 . mockImplementation ( ( ) => prCommits ) ;
105160 expect ( pullRequest . listCommits ( ) ) . toBe ( prCommits ) ;
106161
107- let commits = await runner . processPrivilegedReviewer ( "robot" , {
162+ let prDiff = `| diff --git a/.github/workflows/check-dist.yml b/.github/workflows/check-dist.yml
163+ index 2f4e8d9..93c2072 100644
164+ --- a/.github/workflows/check-dist.yml
165+ +++ b/.github/workflows/check-dist.yml
166+ @@ -44,7 +44,7 @@ jobs:
167+ id: diff
168+
169+ # If index.js was different than expected, upload the expected version as an artifact
170+ - - uses: actions/upload-artifact@v2
171+ if: blah
172+ with:
173+ name: dist` ;
174+ let spyDiff = jest
175+ . spyOn ( pullRequest , "getDiff" )
176+ . mockImplementation ( ( ) => prDiff ) ;
177+ expect ( pullRequest . getDiff ( ) ) . toBe ( prDiff ) ;
178+
179+ let processed = await runner . processPrivilegedReviewer ( "robot" , {
108180 labels : [ "bug" , "feature-request" ] ,
109181 } ) ;
110- expect ( commits ) . toStrictEqual ( true ) ;
111- process . env [ "INPUT_CHECKCOMMITS" ] = "" ;
182+ expect ( processed ) . toStrictEqual ( true ) ;
112183 } ) ;
113184
114185 test ( "We process commits unsuccessfully with the option enabled" , async ( ) => {
115186 process . env [ "INPUT_CHECKCOMMITS" ] = "true" ;
116- let prLabels = [ { name : "bug" } , { name : "feature-request" } ] ;
117- let spyLabels = jest
118- . spyOn ( pullRequest , "listLabels" )
119- . mockImplementation ( ( ) => prLabels ) ;
120- expect ( pullRequest . listLabels ( ) ) . toBe ( prLabels ) ;
121187
122188 let prCommits = [
123189 { author : { login : "robot" } } ,
@@ -128,20 +194,13 @@ describe("processPrivilegedReviewer", () => {
128194 . mockImplementation ( ( ) => prCommits ) ;
129195 expect ( pullRequest . listCommits ( ) ) . toBe ( prCommits ) ;
130196
131- let commits = await runner . processPrivilegedReviewer ( "robot" , {
197+ let processed = await runner . processPrivilegedReviewer ( "robot" , {
132198 labels : [ "bug" , "feature-request" ] ,
133199 } ) ;
134- expect ( commits ) . toStrictEqual ( false ) ;
135- process . env [ "INPUT_CHECKCOMMITS" ] = "" ;
200+ expect ( processed ) . toStrictEqual ( false ) ;
136201 } ) ;
137202
138203 test ( "We allow bad commits when the option to check them is not set" , async ( ) => {
139- let prLabels = [ { name : "bug" } , { name : "feature-request" } ] ;
140- let spyLabels = jest
141- . spyOn ( pullRequest , "listLabels" )
142- . mockImplementation ( ( ) => prLabels ) ;
143- expect ( pullRequest . listLabels ( ) ) . toBe ( prLabels ) ;
144-
145204 let prCommits = [
146205 { author : { login : "robot" } } ,
147206 { author : { login : "malicious" } } ,
@@ -151,10 +210,10 @@ describe("processPrivilegedReviewer", () => {
151210 . mockImplementation ( ( ) => prCommits ) ;
152211 expect ( pullRequest . listCommits ( ) ) . toBe ( prCommits ) ;
153212
154- let commits = await runner . processPrivilegedReviewer ( "robot" , {
155- labels : [ "bug" , "feature-request" ] ,
213+ let processed = await runner . processPrivilegedReviewer ( "robot" , {
214+ labels : [ ] ,
156215 } ) ;
157- expect ( commits ) . toStrictEqual ( true ) ;
216+ expect ( processed ) . toStrictEqual ( true ) ;
158217 } ) ;
159218
160219 test ( "We process labels unsuccessfully with the option enabled" , async ( ) => {
@@ -165,35 +224,73 @@ describe("processPrivilegedReviewer", () => {
165224 . mockImplementation ( ( ) => prLabels ) ;
166225 expect ( pullRequest . listLabels ( ) ) . toBe ( prLabels ) ;
167226
168- let prCommits = [ { author : { login : "robot" } } ] ;
169- let spyCommits = jest
170- . spyOn ( pullRequest , "listCommits" )
171- . mockImplementation ( ( ) => prCommits ) ;
172- expect ( pullRequest . listCommits ( ) ) . toBe ( prCommits ) ;
173-
174- let commits = await runner . processPrivilegedReviewer ( "robot" , {
227+ let processed = await runner . processPrivilegedReviewer ( "robot" , {
175228 labels : [ "new" , "feature-request" ] ,
176229 } ) ;
177- expect ( commits ) . toStrictEqual ( false ) ;
178- process . env [ "INPUT_CHECKLABELS" ] = "" ;
230+ expect ( processed ) . toStrictEqual ( false ) ;
179231 } ) ;
180232
181- test ( "We allow bad commits when the option to check them is not set" , async ( ) => {
233+ test ( "We allow bad labels when the option to check them is not set" , async ( ) => {
182234 let prLabels = [ { name : "bug" } , { name : "feature-request" } ] ;
183235 let spyLabels = jest
184236 . spyOn ( pullRequest , "listLabels" )
185237 . mockImplementation ( ( ) => prLabels ) ;
186238 expect ( pullRequest . listLabels ( ) ) . toBe ( prLabels ) ;
187239
188- let prCommits = [ { author : { login : "robot" } } ] ;
189- let spyCommits = jest
190- . spyOn ( pullRequest , "listCommits" )
191- . mockImplementation ( ( ) => prCommits ) ;
192- expect ( pullRequest . listCommits ( ) ) . toBe ( prCommits ) ;
193-
194- let commits = await runner . processPrivilegedReviewer ( "robot" , {
240+ let processed = await runner . processPrivilegedReviewer ( "robot" , {
195241 labels : [ "new" , "feature-request" ] ,
196242 } ) ;
197- expect ( commits ) . toStrictEqual ( true ) ;
243+ expect ( processed ) . toStrictEqual ( true ) ;
244+ } ) ;
245+
246+ test ( "We process the diff unsuccessfully with the option enabled" , async ( ) => {
247+ process . env [ "INPUT_CHECKDIFF" ] = "true" ;
248+ let prDiff = `| diff --git a/.github/workflows/check-dist.yml b/.github/workflows/check-dist.yml
249+ index 2f4e8d9..93c2072 100644
250+ --- a/.github/workflows/check-dist.yml
251+ +++ b/.github/workflows/check-dist.yml
252+ @@ -44,7 +44,7 @@ jobs:
253+ id: diff
254+
255+ # If index.js was different than expected, upload the expected version as an artifact
256+ - - uses: actions/upload-artifact@v2
257+ + - uses: actions/upload-artifact@v3
258+ if: blah
259+ with:
260+ name: dist` ;
261+ let spyDiff = jest
262+ . spyOn ( pullRequest , "getDiff" )
263+ . mockImplementation ( ( ) => prDiff ) ;
264+ expect ( pullRequest . getDiff ( ) ) . toBe ( prDiff ) ;
265+
266+ let processed = await runner . processPrivilegedReviewer ( "robot" , {
267+ labels : [ ] ,
268+ } ) ;
269+ expect ( processed ) . toStrictEqual ( false ) ;
270+ } ) ;
271+
272+ test ( "We allow a bad diff when the option to check them is not set" , async ( ) => {
273+ let prDiff = `| diff --git a/.github/workflows/check-dist.yml b/.github/workflows/check-dist.yml
274+ index 2f4e8d9..93c2072 100644
275+ --- a/.github/workflows/check-dist.yml
276+ +++ b/.github/workflows/check-dist.yml
277+ @@ -44,7 +44,7 @@ jobs:
278+ id: diff
279+
280+ # If index.js was different than expected, upload the expected version as an artifact
281+ - - uses: actions/upload-artifact@v2
282+ + - uses: actions/upload-artifact@v3
283+ if: blah
284+ with:
285+ name: dist` ;
286+ let spyDiff = jest
287+ . spyOn ( pullRequest , "getDiff" )
288+ . mockImplementation ( ( ) => prDiff ) ;
289+ expect ( pullRequest . getDiff ( ) ) . toBe ( prDiff ) ;
290+
291+ let processed = await runner . processPrivilegedReviewer ( "robot" , {
292+ labels : [ ] ,
293+ } ) ;
294+ expect ( processed ) . toStrictEqual ( true ) ;
198295 } ) ;
199296} ) ;
0 commit comments