@@ -37,13 +37,15 @@ const runAction = () => {
3737
3838describe ( 'Commit Linter action' , ( ) => {
3939 let core
40+ let cwd
4041
4142 beforeEach ( ( ) => {
4243 core = require ( '@actions/core' )
4344 td . replace ( core , 'getInput' )
4445 td . replace ( core , 'setFailed' )
4546 td . when ( core . getInput ( 'configFile' ) ) . thenReturn ( './commitlint.config.js' )
4647 td . when ( core . getInput ( 'firstParent' ) ) . thenReturn ( 'true' )
48+ td . when ( core . getInput ( 'failOnWarnings' ) ) . thenReturn ( 'false' )
4749 } )
4850
4951 afterEach ( ( ) => {
@@ -53,7 +55,7 @@ describe('Commit Linter action', () => {
5355 } )
5456
5557 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' )
5759 await gitEmptyCommit ( cwd , 'wrong message' )
5860 const [ to ] = await getCommitHashes ( cwd )
5961 await createPushEventPayload ( cwd , { to } )
@@ -66,7 +68,7 @@ describe('Commit Linter action', () => {
6668 } )
6769
6870 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' )
7072 await gitEmptyCommit ( cwd , 'chore: correct message' )
7173 const [ to ] = await getCommitHashes ( cwd )
7274 await createPushEventPayload ( cwd , { to } )
@@ -81,7 +83,7 @@ describe('Commit Linter action', () => {
8183 } )
8284
8385 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' )
8587 await gitEmptyCommit ( cwd , 'message from before push' )
8688 await gitEmptyCommit ( cwd , 'wrong message 1' )
8789 await gitEmptyCommit ( cwd , 'wrong message 2' )
@@ -97,7 +99,7 @@ describe('Commit Linter action', () => {
9799 } )
98100
99101 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' )
101103 await gitEmptyCommit ( cwd , 'message from before push' )
102104 await gitEmptyCommit ( cwd , 'chore: correct message 1' )
103105 await gitEmptyCommit ( cwd , 'chore: correct message 2' )
@@ -114,7 +116,7 @@ describe('Commit Linter action', () => {
114116 } )
115117
116118 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' )
118120 await gitEmptyCommit ( cwd , 'message from before push' )
119121 await gitEmptyCommit ( cwd , 'wrong message 1' )
120122 await gitEmptyCommit ( cwd , 'wrong message 2' )
@@ -137,7 +139,7 @@ describe('Commit Linter action', () => {
137139
138140 it ( 'should lint only last commit when "before" field is an empty sha' , async ( ) => {
139141 const gitEmptySha = '0000000000000000000000000000000000000000'
140- const cwd = await git . bootstrap ( 'fixtures/conventional' )
142+ cwd = await git . bootstrap ( 'fixtures/conventional' )
141143 await gitEmptyCommit ( cwd , 'message from before push' )
142144 await gitEmptyCommit ( cwd , 'wrong message 1' )
143145 await gitEmptyCommit ( cwd , 'chore(WRONG): message 2' )
@@ -153,7 +155,7 @@ describe('Commit Linter action', () => {
153155 } )
154156
155157 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' )
157159 td . when ( core . getInput ( 'configFile' ) ) . thenReturn ( './commitlint.config.yml' )
158160 await gitEmptyCommit ( cwd , 'chore(wrong): not including package scope' )
159161 const [ to ] = await getCommitHashes ( cwd )
@@ -169,7 +171,7 @@ describe('Commit Linter action', () => {
169171 } )
170172
171173 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' )
173175 td . when ( core . getInput ( 'configFile' ) ) . thenReturn ( './commitlint.config.yml' )
174176 await gitEmptyCommit ( cwd , 'chore(second-package): this works' )
175177 const [ to ] = await getCommitHashes ( cwd )
@@ -184,7 +186,7 @@ describe('Commit Linter action', () => {
184186 } )
185187
186188 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' )
188190 td . when ( core . getInput ( 'configFile' ) ) . thenReturn ( './commitlint.config.js' )
189191 await gitEmptyCommit ( cwd , 'ib-21212121212121: without jira ticket' )
190192 const [ to ] = await getCommitHashes ( cwd )
@@ -217,7 +219,7 @@ describe('Commit Linter action', () => {
217219 } )
218220
219221 it ( 'should NOT consider commits from another branch' , async ( ) => {
220- const cwd = await git . bootstrap ( 'fixtures/conventional' )
222+ cwd = await git . bootstrap ( 'fixtures/conventional' )
221223 await gitEmptyCommit ( cwd , 'chore: commit before' )
222224 await gitEmptyCommit ( cwd , 'chore: correct message' )
223225 await execa . command ( 'git checkout -b another-branch' , { cwd } )
@@ -236,7 +238,7 @@ describe('Commit Linter action', () => {
236238 } )
237239
238240 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' )
240242 await gitEmptyCommit ( cwd , 'chore: commit before' )
241243 await gitEmptyCommit ( cwd , 'chore: correct message' )
242244 await execa . command ( 'git checkout -b another-branch' , { cwd } )
@@ -255,7 +257,7 @@ describe('Commit Linter action', () => {
255257 } )
256258
257259 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' )
259261 td . when ( core . getInput ( 'configFile' ) ) . thenReturn ( './commitlint.config.js' )
260262 await gitEmptyCommit ( cwd , 'message from before push' )
261263 await gitEmptyCommit ( cwd , 'wrong message 1' )
@@ -286,7 +288,7 @@ describe('Commit Linter action', () => {
286288 } )
287289
288290 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' )
290292 td . when ( core . getInput ( 'configFile' ) ) . thenReturn ( './commitlint.config.js' )
291293 await gitEmptyCommit ( cwd , 'commit message' )
292294 await createPullRequestEventPayload ( cwd )
@@ -310,4 +312,78 @@ describe('Commit Linter action', () => {
310312 )
311313 td . verify ( core . setFailed ( contains ( 'HttpError: Bad credentials' ) ) )
312314 } )
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+ } )
313389} )
0 commit comments