@@ -37,13 +37,15 @@ const runAction = () => {
37
37
38
38
describe ( 'Commit Linter action' , ( ) => {
39
39
let core
40
+ let cwd
40
41
41
42
beforeEach ( ( ) => {
42
43
core = require ( '@actions/core' )
43
44
td . replace ( core , 'getInput' )
44
45
td . replace ( core , 'setFailed' )
45
46
td . when ( core . getInput ( 'configFile' ) ) . thenReturn ( './commitlint.config.js' )
46
47
td . when ( core . getInput ( 'firstParent' ) ) . thenReturn ( 'true' )
48
+ td . when ( core . getInput ( 'failOnWarnings' ) ) . thenReturn ( 'false' )
47
49
} )
48
50
49
51
afterEach ( ( ) => {
@@ -53,7 +55,7 @@ describe('Commit Linter action', () => {
53
55
} )
54
56
55
57
it ( 'should fail for single push with incorrect message' , async ( ) => {
56
- const cwd = await git . bootstrap ( 'fixtures/conventional' )
58
+ cwd = await git . bootstrap ( 'fixtures/conventional' )
57
59
await gitEmptyCommit ( cwd , 'wrong message' )
58
60
const [ to ] = await getCommitHashes ( cwd )
59
61
await createPushEventPayload ( cwd , { to } )
@@ -66,7 +68,7 @@ describe('Commit Linter action', () => {
66
68
} )
67
69
68
70
it ( 'should pass for single push with correct message' , async ( ) => {
69
- const cwd = await git . bootstrap ( 'fixtures/conventional' )
71
+ cwd = await git . bootstrap ( 'fixtures/conventional' )
70
72
await gitEmptyCommit ( cwd , 'chore: correct message' )
71
73
const [ to ] = await getCommitHashes ( cwd )
72
74
await createPushEventPayload ( cwd , { to } )
@@ -81,7 +83,7 @@ describe('Commit Linter action', () => {
81
83
} )
82
84
83
85
it ( 'should fail for push range with wrong messages' , async ( ) => {
84
- const cwd = await git . bootstrap ( 'fixtures/conventional' )
86
+ cwd = await git . bootstrap ( 'fixtures/conventional' )
85
87
await gitEmptyCommit ( cwd , 'message from before push' )
86
88
await gitEmptyCommit ( cwd , 'wrong message 1' )
87
89
await gitEmptyCommit ( cwd , 'wrong message 2' )
@@ -97,7 +99,7 @@ describe('Commit Linter action', () => {
97
99
} )
98
100
99
101
it ( 'should pass for push range with correct messages' , async ( ) => {
100
- const cwd = await git . bootstrap ( 'fixtures/conventional' )
102
+ cwd = await git . bootstrap ( 'fixtures/conventional' )
101
103
await gitEmptyCommit ( cwd , 'message from before push' )
102
104
await gitEmptyCommit ( cwd , 'chore: correct message 1' )
103
105
await gitEmptyCommit ( cwd , 'chore: correct message 2' )
@@ -114,7 +116,7 @@ describe('Commit Linter action', () => {
114
116
} )
115
117
116
118
it ( 'should lint only last commit for forced push' , async ( ) => {
117
- const cwd = await git . bootstrap ( 'fixtures/conventional' )
119
+ cwd = await git . bootstrap ( 'fixtures/conventional' )
118
120
await gitEmptyCommit ( cwd , 'message from before push' )
119
121
await gitEmptyCommit ( cwd , 'wrong message 1' )
120
122
await gitEmptyCommit ( cwd , 'wrong message 2' )
@@ -137,7 +139,7 @@ describe('Commit Linter action', () => {
137
139
138
140
it ( 'should lint only last commit when "before" field is an empty sha' , async ( ) => {
139
141
const gitEmptySha = '0000000000000000000000000000000000000000'
140
- const cwd = await git . bootstrap ( 'fixtures/conventional' )
142
+ cwd = await git . bootstrap ( 'fixtures/conventional' )
141
143
await gitEmptyCommit ( cwd , 'message from before push' )
142
144
await gitEmptyCommit ( cwd , 'wrong message 1' )
143
145
await gitEmptyCommit ( cwd , 'chore(WRONG): message 2' )
@@ -153,7 +155,7 @@ describe('Commit Linter action', () => {
153
155
} )
154
156
155
157
it ( 'should fail for commit with scope that is not a lerna package' , async ( ) => {
156
- const cwd = await git . bootstrap ( 'fixtures/lerna-scopes' )
158
+ cwd = await git . bootstrap ( 'fixtures/lerna-scopes' )
157
159
td . when ( core . getInput ( 'configFile' ) ) . thenReturn ( './commitlint.config.yml' )
158
160
await gitEmptyCommit ( cwd , 'chore(wrong): not including package scope' )
159
161
const [ to ] = await getCommitHashes ( cwd )
@@ -169,7 +171,7 @@ describe('Commit Linter action', () => {
169
171
} )
170
172
171
173
it ( 'should pass for scope that is a lerna package' , async ( ) => {
172
- const cwd = await git . bootstrap ( 'fixtures/lerna-scopes' )
174
+ cwd = await git . bootstrap ( 'fixtures/lerna-scopes' )
173
175
td . when ( core . getInput ( 'configFile' ) ) . thenReturn ( './commitlint.config.yml' )
174
176
await gitEmptyCommit ( cwd , 'chore(second-package): this works' )
175
177
const [ to ] = await getCommitHashes ( cwd )
@@ -184,7 +186,7 @@ describe('Commit Linter action', () => {
184
186
} )
185
187
186
188
it ( "should fail for commit that doesn't comply with jira rules" , async ( ) => {
187
- const cwd = await git . bootstrap ( 'fixtures/jira' )
189
+ cwd = await git . bootstrap ( 'fixtures/jira' )
188
190
td . when ( core . getInput ( 'configFile' ) ) . thenReturn ( './commitlint.config.js' )
189
191
await gitEmptyCommit ( cwd , 'ib-21212121212121: without jira ticket' )
190
192
const [ to ] = await getCommitHashes ( cwd )
@@ -217,7 +219,7 @@ describe('Commit Linter action', () => {
217
219
} )
218
220
219
221
it ( 'should NOT consider commits from another branch' , async ( ) => {
220
- const cwd = await git . bootstrap ( 'fixtures/conventional' )
222
+ cwd = await git . bootstrap ( 'fixtures/conventional' )
221
223
await gitEmptyCommit ( cwd , 'chore: commit before' )
222
224
await gitEmptyCommit ( cwd , 'chore: correct message' )
223
225
await execa . command ( 'git checkout -b another-branch' , { cwd } )
@@ -236,7 +238,7 @@ describe('Commit Linter action', () => {
236
238
} )
237
239
238
240
it ( 'should consider commits from another branch when firstParent is false' , async ( ) => {
239
- const cwd = await git . bootstrap ( 'fixtures/conventional' )
241
+ cwd = await git . bootstrap ( 'fixtures/conventional' )
240
242
await gitEmptyCommit ( cwd , 'chore: commit before' )
241
243
await gitEmptyCommit ( cwd , 'chore: correct message' )
242
244
await execa . command ( 'git checkout -b another-branch' , { cwd } )
@@ -255,7 +257,7 @@ describe('Commit Linter action', () => {
255
257
} )
256
258
257
259
it ( 'should lint all commits from a pull request' , async ( ) => {
258
- const cwd = await git . bootstrap ( 'fixtures/conventional' )
260
+ cwd = await git . bootstrap ( 'fixtures/conventional' )
259
261
td . when ( core . getInput ( 'configFile' ) ) . thenReturn ( './commitlint.config.js' )
260
262
await gitEmptyCommit ( cwd , 'message from before push' )
261
263
await gitEmptyCommit ( cwd , 'wrong message 1' )
@@ -286,7 +288,7 @@ describe('Commit Linter action', () => {
286
288
} )
287
289
288
290
it ( 'should show an error message when failing to fetch commits' , async ( ) => {
289
- const cwd = await git . bootstrap ( 'fixtures/conventional' )
291
+ cwd = await git . bootstrap ( 'fixtures/conventional' )
290
292
td . when ( core . getInput ( 'configFile' ) ) . thenReturn ( './commitlint.config.js' )
291
293
await gitEmptyCommit ( cwd , 'commit message' )
292
294
await createPullRequestEventPayload ( cwd )
@@ -310,4 +312,78 @@ describe('Commit Linter action', () => {
310
312
)
311
313
td . verify ( core . setFailed ( contains ( 'HttpError: Bad credentials' ) ) )
312
314
} )
315
+
316
+ describe ( 'when all errors are just warnings' , ( ) => {
317
+ beforeEach ( async ( ) => {
318
+ cwd = await git . bootstrap ( 'fixtures/conventional' )
319
+ await gitEmptyCommit (
320
+ cwd ,
321
+ 'chore: correct message\nsome context without leading blank line' ,
322
+ )
323
+ const [ to ] = await getCommitHashes ( cwd )
324
+ await createPushEventPayload ( cwd , { to } )
325
+ updatePushEnvVars ( cwd , to )
326
+ td . replace ( process , 'cwd' , ( ) => cwd )
327
+ td . replace ( console , 'log' )
328
+ } )
329
+
330
+ it ( 'should pass and show that warnings exist' , async ( ) => {
331
+ await runAction ( )
332
+
333
+ td . verify ( core . setFailed ( ) , { times : 0 , ignoreExtraArgs : true } )
334
+ td . verify ( console . log ( contains ( 'You have commit messages with warnings' ) ) )
335
+ } )
336
+
337
+ describe ( 'and failOnWarnings is set to true' , ( ) => {
338
+ beforeEach ( ( ) => {
339
+ td . when ( core . getInput ( 'failOnWarnings' ) ) . thenReturn ( 'true' )
340
+ } )
341
+
342
+ it ( 'should fail' , async ( ) => {
343
+ await runAction ( )
344
+
345
+ td . verify (
346
+ core . setFailed ( contains ( 'You have commit messages with errors' ) ) ,
347
+ )
348
+ } )
349
+ } )
350
+ } )
351
+
352
+ describe ( 'when a subset of errors are just warnings' , ( ) => {
353
+ beforeEach ( async ( ) => {
354
+ cwd = await git . bootstrap ( 'fixtures/conventional' )
355
+ await gitEmptyCommit (
356
+ cwd ,
357
+ 'chore: correct message\nsome context without leading blank line' ,
358
+ )
359
+ await gitEmptyCommit ( cwd , 'wrong message' )
360
+ const [ before , to ] = await getCommitHashes ( cwd )
361
+ await createPushEventPayload ( cwd , { before, to } )
362
+ updatePushEnvVars ( cwd , to )
363
+ td . replace ( process , 'cwd' , ( ) => cwd )
364
+ td . replace ( console , 'log' )
365
+ } )
366
+
367
+ it ( 'should fail' , async ( ) => {
368
+ await runAction ( )
369
+
370
+ td . verify (
371
+ core . setFailed ( contains ( 'You have commit messages with errors' ) ) ,
372
+ )
373
+ } )
374
+
375
+ describe ( 'and failOnWarnings is set to true' , ( ) => {
376
+ beforeEach ( ( ) => {
377
+ td . when ( core . getInput ( 'failOnWarnings' ) ) . thenReturn ( 'true' )
378
+ } )
379
+
380
+ it ( 'should fail' , async ( ) => {
381
+ await runAction ( )
382
+
383
+ td . verify (
384
+ core . setFailed ( contains ( 'You have commit messages with errors' ) ) ,
385
+ )
386
+ } )
387
+ } )
388
+ } )
313
389
} )
0 commit comments