@@ -44,8 +44,9 @@ describe('Commit Linter action', () => {
44
44
beforeEach ( ( ) => {
45
45
core = require ( '@actions/core' )
46
46
td . replace ( core , 'getInput' )
47
- td . replace ( core , 'setFailed' )
48
47
td . replace ( core , 'setOutput' )
48
+ td . replace ( console , 'log' )
49
+ td . replace ( console , 'error' )
49
50
td . when ( core . getInput ( 'configFile' ) ) . thenReturn ( './commitlint.config.js' )
50
51
td . when ( core . getInput ( 'firstParent' ) ) . thenReturn ( 'true' )
51
52
td . when ( core . getInput ( 'failOnWarnings' ) ) . thenReturn ( 'false' )
@@ -71,7 +72,8 @@ describe('Commit Linter action', () => {
71
72
72
73
await runAction ( )
73
74
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 )
75
77
} )
76
78
77
79
it ( 'should fail for single push with incorrect message' , async ( ) => {
@@ -84,7 +86,7 @@ describe('Commit Linter action', () => {
84
86
85
87
await runAction ( )
86
88
87
- td . verify ( core . setFailed ( contains ( 'You have commit messages with errors' ) ) )
89
+ td . verify ( console . error ( contains ( 'You have commit messages with errors' ) ) )
88
90
} )
89
91
90
92
it ( 'should fail for push range with wrong messages' , async ( ) => {
@@ -99,8 +101,8 @@ describe('Commit Linter action', () => {
99
101
100
102
await runAction ( )
101
103
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' ) ) )
104
106
} )
105
107
106
108
it ( 'should pass for push range with correct messages' , async ( ) => {
@@ -116,7 +118,7 @@ describe('Commit Linter action', () => {
116
118
117
119
await runAction ( )
118
120
119
- td . verify ( core . setFailed ( ) , { times : 0 , ignoreExtraArgs : true } )
121
+ td . verify ( console . error ( ) , { times : 0 , ignoreExtraArgs : true } )
120
122
td . verify ( console . log ( 'Lint free! 🎉' ) )
121
123
} )
122
124
@@ -138,8 +140,8 @@ describe('Commit Linter action', () => {
138
140
'Commit was forced, checking only the latest commit from push instead of a range of commit messages' ,
139
141
) ,
140
142
)
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' ) ) )
143
145
} )
144
146
145
147
it ( 'should lint only last commit when "before" field is an empty sha' , async ( ) => {
@@ -155,8 +157,8 @@ describe('Commit Linter action', () => {
155
157
156
158
await runAction ( )
157
159
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' ) ) )
160
162
} )
161
163
162
164
it ( 'should fail for commit with scope that is not a lerna package' , async ( ) => {
@@ -171,7 +173,7 @@ describe('Commit Linter action', () => {
171
173
await runAction ( )
172
174
173
175
td . verify (
174
- core . setFailed ( contains ( 'chore(wrong): not including package scope' ) ) ,
176
+ console . error ( contains ( 'chore(wrong): not including package scope' ) ) ,
175
177
)
176
178
} )
177
179
@@ -201,23 +203,21 @@ describe('Commit Linter action', () => {
201
203
202
204
await runAction ( )
203
205
206
+ td . verify ( console . error ( contains ( 'ib-21212121212121: without jira ticket' ) ) )
204
207
td . verify (
205
- core . setFailed ( contains ( 'ib-21212121212121: without jira ticket' ) ) ,
206
- )
207
- td . verify (
208
- core . setFailed (
208
+ console . error (
209
209
contains (
210
210
'ib-21212121212121 taskId must not be loonger than 9 characters' ,
211
211
) ,
212
212
) ,
213
213
)
214
214
td . verify (
215
- core . setFailed (
215
+ console . error (
216
216
contains ( 'ib-21212121212121 taskId must be uppercase case' ) ,
217
217
) ,
218
218
)
219
219
td . verify (
220
- core . setFailed (
220
+ console . error (
221
221
contains ( 'ib-21212121212121 commitStatus must be uppercase case' ) ,
222
222
) ,
223
223
)
@@ -258,7 +258,7 @@ describe('Commit Linter action', () => {
258
258
259
259
await runAction ( )
260
260
261
- td . verify ( core . setFailed ( contains ( 'wrong commit from another branch' ) ) )
261
+ td . verify ( console . error ( contains ( 'wrong commit from another branch' ) ) )
262
262
} )
263
263
264
264
describe ( 'when there are multiple commits failing in the pull request' , ( ) => {
@@ -307,21 +307,21 @@ describe('Commit Linter action', () => {
307
307
it ( 'should NOT show errors for a message from before the push' , async ( ) => {
308
308
await runAction ( )
309
309
310
- td . verify ( core . setFailed ( contains ( 'message from before push' ) ) , {
310
+ td . verify ( console . error ( contains ( 'message from before push' ) ) , {
311
311
times : 0 ,
312
312
} )
313
313
} )
314
314
315
315
it ( 'should show errors for the first wrong message' , async ( ) => {
316
316
await runAction ( )
317
317
318
- td . verify ( core . setFailed ( contains ( firstMessage ) ) )
318
+ td . verify ( console . error ( contains ( firstMessage ) ) )
319
319
} )
320
320
321
321
it ( 'should show errors for the second wrong message' , async ( ) => {
322
322
await runAction ( )
323
323
324
- td . verify ( core . setFailed ( contains ( secondMessage ) ) )
324
+ td . verify ( console . error ( contains ( secondMessage ) ) )
325
325
} )
326
326
327
327
it ( 'should generate a JSON output of the errors' , async ( ) => {
@@ -352,8 +352,9 @@ describe('Commit Linter action', () => {
352
352
it ( 'should show an error message' , async ( ) => {
353
353
await runAction ( )
354
354
355
+ expect ( process . exitCode ) . toBe ( 1 )
355
356
td . verify (
356
- core . setFailed (
357
+ console . error (
357
358
contains ( "error trying to get list of pull request's commits" ) ,
358
359
) ,
359
360
)
@@ -362,7 +363,7 @@ describe('Commit Linter action', () => {
362
363
it ( 'should show the original error message' , async ( ) => {
363
364
await runAction ( )
364
365
365
- td . verify ( core . setFailed ( contains ( 'HttpError: Bad credentials' ) ) )
366
+ td . verify ( console . error ( contains ( 'HttpError: Bad credentials' ) ) )
366
367
} )
367
368
} )
368
369
@@ -383,7 +384,7 @@ describe('Commit Linter action', () => {
383
384
it ( 'should pass' , async ( ) => {
384
385
await runAction ( )
385
386
386
- td . verify ( core . setFailed ( ) , { times : 0 , ignoreExtraArgs : true } )
387
+ td . verify ( console . error ( ) , { times : 0 , ignoreExtraArgs : true } )
387
388
} )
388
389
389
390
it ( 'should show success message' , async ( ) => {
@@ -448,7 +449,7 @@ describe('Commit Linter action', () => {
448
449
it ( 'should pass and show that warnings exist' , async ( ) => {
449
450
await runAction ( )
450
451
451
- td . verify ( core . setFailed ( ) , { times : 0 , ignoreExtraArgs : true } )
452
+ td . verify ( console . error ( ) , { times : 0 , ignoreExtraArgs : true } )
452
453
td . verify ( console . log ( contains ( 'You have commit messages with warnings' ) ) )
453
454
} )
454
455
@@ -467,7 +468,7 @@ describe('Commit Linter action', () => {
467
468
await runAction ( )
468
469
469
470
td . verify (
470
- core . setFailed ( contains ( 'You have commit messages with errors' ) ) ,
471
+ console . error ( contains ( 'You have commit messages with errors' ) ) ,
471
472
)
472
473
} )
473
474
@@ -503,9 +504,7 @@ describe('Commit Linter action', () => {
503
504
it ( 'should fail' , async ( ) => {
504
505
await runAction ( )
505
506
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' ) ) )
509
508
} )
510
509
511
510
it ( 'should show the results in an output' , async ( ) => {
@@ -541,7 +540,7 @@ describe('Commit Linter action', () => {
541
540
await runAction ( )
542
541
543
542
td . verify (
544
- core . setFailed ( contains ( 'You have commit messages with errors' ) ) ,
543
+ console . error ( contains ( 'You have commit messages with errors' ) ) ,
545
544
)
546
545
} )
547
546
} )
0 commit comments