@@ -44,8 +44,9 @@ describe('Commit Linter action', () => {
4444 beforeEach ( ( ) => {
4545 core = require ( '@actions/core' )
4646 td . replace ( core , 'getInput' )
47- td . replace ( core , 'setFailed' )
4847 td . replace ( core , 'setOutput' )
48+ td . replace ( console , 'log' )
49+ td . replace ( console , 'error' )
4950 td . when ( core . getInput ( 'configFile' ) ) . thenReturn ( './commitlint.config.js' )
5051 td . when ( core . getInput ( 'firstParent' ) ) . thenReturn ( 'true' )
5152 td . when ( core . getInput ( 'failOnWarnings' ) ) . thenReturn ( 'false' )
@@ -71,7 +72,8 @@ describe('Commit Linter action', () => {
7172
7273 await runAction ( )
7374
74- td . verify ( core . setFailed ( contains ( 'You have commit messages with errors' ) ) )
75+ td . verify ( console . error ( contains ( 'You have commit messages with errors' ) ) )
76+ expect ( process . exitCode ) . toBe ( 1 )
7577 } )
7678
7779 it ( 'should fail for single push with incorrect message' , async ( ) => {
@@ -84,7 +86,7 @@ describe('Commit Linter action', () => {
8486
8587 await runAction ( )
8688
87- td . verify ( core . setFailed ( contains ( 'You have commit messages with errors' ) ) )
89+ td . verify ( console . error ( contains ( 'You have commit messages with errors' ) ) )
8890 } )
8991
9092 it ( 'should fail for push range with wrong messages' , async ( ) => {
@@ -99,8 +101,8 @@ describe('Commit Linter action', () => {
99101
100102 await runAction ( )
101103
102- td . verify ( core . setFailed ( contains ( 'wrong message 1' ) ) )
103- td . verify ( core . setFailed ( contains ( 'wrong message 2' ) ) )
104+ td . verify ( console . error ( contains ( 'wrong message 1' ) ) )
105+ td . verify ( console . error ( contains ( 'wrong message 2' ) ) )
104106 } )
105107
106108 it ( 'should pass for push range with correct messages' , async ( ) => {
@@ -116,7 +118,7 @@ describe('Commit Linter action', () => {
116118
117119 await runAction ( )
118120
119- td . verify ( core . setFailed ( ) , { times : 0 , ignoreExtraArgs : true } )
121+ td . verify ( console . error ( ) , { times : 0 , ignoreExtraArgs : true } )
120122 td . verify ( console . log ( 'Lint free! 🎉' ) )
121123 } )
122124
@@ -138,8 +140,8 @@ describe('Commit Linter action', () => {
138140 'Commit was forced, checking only the latest commit from push instead of a range of commit messages' ,
139141 ) ,
140142 )
141- td . verify ( core . setFailed ( contains ( 'wrong message 1' ) ) , { times : 0 } )
142- td . verify ( core . setFailed ( contains ( 'wrong message 2' ) ) )
143+ td . verify ( console . error ( contains ( 'wrong message 1' ) ) , { times : 0 } )
144+ td . verify ( console . error ( contains ( 'wrong message 2' ) ) )
143145 } )
144146
145147 it ( 'should lint only last commit when "before" field is an empty sha' , async ( ) => {
@@ -155,8 +157,8 @@ describe('Commit Linter action', () => {
155157
156158 await runAction ( )
157159
158- td . verify ( core . setFailed ( contains ( 'wrong message 1' ) ) , { times : 0 } )
159- td . verify ( core . setFailed ( contains ( 'chore(WRONG): message 2' ) ) )
160+ td . verify ( console . error ( contains ( 'wrong message 1' ) ) , { times : 0 } )
161+ td . verify ( console . error ( contains ( 'chore(WRONG): message 2' ) ) )
160162 } )
161163
162164 it ( 'should fail for commit with scope that is not a lerna package' , async ( ) => {
@@ -171,7 +173,7 @@ describe('Commit Linter action', () => {
171173 await runAction ( )
172174
173175 td . verify (
174- core . setFailed ( contains ( 'chore(wrong): not including package scope' ) ) ,
176+ console . error ( contains ( 'chore(wrong): not including package scope' ) ) ,
175177 )
176178 } )
177179
@@ -201,23 +203,21 @@ describe('Commit Linter action', () => {
201203
202204 await runAction ( )
203205
206+ td . verify ( console . error ( contains ( 'ib-21212121212121: without jira ticket' ) ) )
204207 td . verify (
205- core . setFailed ( contains ( 'ib-21212121212121: without jira ticket' ) ) ,
206- )
207- td . verify (
208- core . setFailed (
208+ console . error (
209209 contains (
210210 'ib-21212121212121 taskId must not be loonger than 9 characters' ,
211211 ) ,
212212 ) ,
213213 )
214214 td . verify (
215- core . setFailed (
215+ console . error (
216216 contains ( 'ib-21212121212121 taskId must be uppercase case' ) ,
217217 ) ,
218218 )
219219 td . verify (
220- core . setFailed (
220+ console . error (
221221 contains ( 'ib-21212121212121 commitStatus must be uppercase case' ) ,
222222 ) ,
223223 )
@@ -258,7 +258,7 @@ describe('Commit Linter action', () => {
258258
259259 await runAction ( )
260260
261- td . verify ( core . setFailed ( contains ( 'wrong commit from another branch' ) ) )
261+ td . verify ( console . error ( contains ( 'wrong commit from another branch' ) ) )
262262 } )
263263
264264 describe ( 'when there are multiple commits failing in the pull request' , ( ) => {
@@ -307,21 +307,21 @@ describe('Commit Linter action', () => {
307307 it ( 'should NOT show errors for a message from before the push' , async ( ) => {
308308 await runAction ( )
309309
310- td . verify ( core . setFailed ( contains ( 'message from before push' ) ) , {
310+ td . verify ( console . error ( contains ( 'message from before push' ) ) , {
311311 times : 0 ,
312312 } )
313313 } )
314314
315315 it ( 'should show errors for the first wrong message' , async ( ) => {
316316 await runAction ( )
317317
318- td . verify ( core . setFailed ( contains ( firstMessage ) ) )
318+ td . verify ( console . error ( contains ( firstMessage ) ) )
319319 } )
320320
321321 it ( 'should show errors for the second wrong message' , async ( ) => {
322322 await runAction ( )
323323
324- td . verify ( core . setFailed ( contains ( secondMessage ) ) )
324+ td . verify ( console . error ( contains ( secondMessage ) ) )
325325 } )
326326
327327 it ( 'should generate a JSON output of the errors' , async ( ) => {
@@ -352,8 +352,9 @@ describe('Commit Linter action', () => {
352352 it ( 'should show an error message' , async ( ) => {
353353 await runAction ( )
354354
355+ expect ( process . exitCode ) . toBe ( 1 )
355356 td . verify (
356- core . setFailed (
357+ console . error (
357358 contains ( "error trying to get list of pull request's commits" ) ,
358359 ) ,
359360 )
@@ -362,7 +363,7 @@ describe('Commit Linter action', () => {
362363 it ( 'should show the original error message' , async ( ) => {
363364 await runAction ( )
364365
365- td . verify ( core . setFailed ( contains ( 'HttpError: Bad credentials' ) ) )
366+ td . verify ( console . error ( contains ( 'HttpError: Bad credentials' ) ) )
366367 } )
367368 } )
368369
@@ -383,7 +384,7 @@ describe('Commit Linter action', () => {
383384 it ( 'should pass' , async ( ) => {
384385 await runAction ( )
385386
386- td . verify ( core . setFailed ( ) , { times : 0 , ignoreExtraArgs : true } )
387+ td . verify ( console . error ( ) , { times : 0 , ignoreExtraArgs : true } )
387388 } )
388389
389390 it ( 'should show success message' , async ( ) => {
@@ -448,7 +449,7 @@ describe('Commit Linter action', () => {
448449 it ( 'should pass and show that warnings exist' , async ( ) => {
449450 await runAction ( )
450451
451- td . verify ( core . setFailed ( ) , { times : 0 , ignoreExtraArgs : true } )
452+ td . verify ( console . error ( ) , { times : 0 , ignoreExtraArgs : true } )
452453 td . verify ( console . log ( contains ( 'You have commit messages with warnings' ) ) )
453454 } )
454455
@@ -467,7 +468,7 @@ describe('Commit Linter action', () => {
467468 await runAction ( )
468469
469470 td . verify (
470- core . setFailed ( contains ( 'You have commit messages with errors' ) ) ,
471+ console . error ( contains ( 'You have commit messages with errors' ) ) ,
471472 )
472473 } )
473474
@@ -503,9 +504,7 @@ describe('Commit Linter action', () => {
503504 it ( 'should fail' , async ( ) => {
504505 await runAction ( )
505506
506- td . verify (
507- core . setFailed ( contains ( 'You have commit messages with errors' ) ) ,
508- )
507+ td . verify ( console . error ( contains ( 'You have commit messages with errors' ) ) )
509508 } )
510509
511510 it ( 'should show the results in an output' , async ( ) => {
@@ -541,7 +540,7 @@ describe('Commit Linter action', () => {
541540 await runAction ( )
542541
543542 td . verify (
544- core . setFailed ( contains ( 'You have commit messages with errors' ) ) ,
543+ console . error ( contains ( 'You have commit messages with errors' ) ) ,
545544 )
546545 } )
547546 } )
0 commit comments