@@ -261,75 +261,80 @@ describe('Commit Linter action', () => {
261261 td . verify ( core . setFailed ( contains ( 'wrong commit from another branch' ) ) )
262262 } )
263263
264- describe ( 'when there are multiple commits failing in the pull request' , ( ) => {
265- let expectedResultsOutput
266- const firstMessage = 'wrong message 1'
267- const secondMessage = 'wrong message 2'
268-
269- beforeEach ( async ( ) => {
270- cwd = await git . bootstrap ( 'fixtures/conventional' )
271- td . when ( core . getInput ( 'configFile' ) ) . thenReturn ( './commitlint.config.js' )
272- await gitEmptyCommit ( cwd , 'message from before push' )
273- await gitEmptyCommit ( cwd , firstMessage )
274- await gitEmptyCommit ( cwd , secondMessage )
275- await createPullRequestEventPayload ( cwd )
276- const [ , first , to ] = await getCommitHashes ( cwd )
277- updatePullRequestEnvVars ( cwd , to )
278- td . when (
279- listCommits ( {
280- owner : 'wagoid' ,
281- repo : 'commitlint-github-action' ,
282- pull_number : '1' ,
283- } ) ,
284- ) . thenResolve ( {
285- data : [ first , to ] . map ( ( sha ) => ( { sha } ) ) ,
264+ describe . each ( [ 'pull_request' , 'pull_request_target' ] ) (
265+ 'when there are multiple commits failing in the %s event' ,
266+ ( eventName ) => {
267+ let expectedResultsOutput
268+ const firstMessage = 'wrong message 1'
269+ const secondMessage = 'wrong message 2'
270+
271+ beforeEach ( async ( ) => {
272+ cwd = await git . bootstrap ( 'fixtures/conventional' )
273+ td . when ( core . getInput ( 'configFile' ) ) . thenReturn (
274+ './commitlint.config.js' ,
275+ )
276+ await gitEmptyCommit ( cwd , 'message from before push' )
277+ await gitEmptyCommit ( cwd , firstMessage )
278+ await gitEmptyCommit ( cwd , secondMessage )
279+ await createPullRequestEventPayload ( cwd )
280+ const [ , first , to ] = await getCommitHashes ( cwd )
281+ updatePullRequestEnvVars ( cwd , to , { eventName } )
282+ td . when (
283+ listCommits ( {
284+ owner : 'wagoid' ,
285+ repo : 'commitlint-github-action' ,
286+ pull_number : '1' ,
287+ } ) ,
288+ ) . thenResolve ( {
289+ data : [ first , to ] . map ( ( sha ) => ( { sha } ) ) ,
290+ } )
291+ td . replace ( process , 'cwd' , ( ) => cwd )
292+
293+ expectedResultsOutput = [
294+ {
295+ hash : to ,
296+ message : secondMessage ,
297+ valid : false ,
298+ errors : [ 'subject may not be empty' , 'type may not be empty' ] ,
299+ warnings : [ ] ,
300+ } ,
301+ {
302+ hash : first ,
303+ message : firstMessage ,
304+ valid : false ,
305+ errors : [ 'subject may not be empty' , 'type may not be empty' ] ,
306+ warnings : [ ] ,
307+ } ,
308+ ]
286309 } )
287- td . replace ( process , 'cwd' , ( ) => cwd )
288310
289- expectedResultsOutput = [
290- {
291- hash : to ,
292- message : secondMessage ,
293- valid : false ,
294- errors : [ 'subject may not be empty' , 'type may not be empty' ] ,
295- warnings : [ ] ,
296- } ,
297- {
298- hash : first ,
299- message : firstMessage ,
300- valid : false ,
301- errors : [ 'subject may not be empty' , 'type may not be empty' ] ,
302- warnings : [ ] ,
303- } ,
304- ]
305- } )
306-
307- it ( 'should NOT show errors for a message from before the push' , async ( ) => {
308- await runAction ( )
311+ it ( 'should NOT show errors for a message from before the push' , async ( ) => {
312+ await runAction ( )
309313
310- td . verify ( core . setFailed ( contains ( 'message from before push' ) ) , {
311- times : 0 ,
314+ td . verify ( core . setFailed ( contains ( 'message from before push' ) ) , {
315+ times : 0 ,
316+ } )
312317 } )
313- } )
314318
315- it ( 'should show errors for the first wrong message' , async ( ) => {
316- await runAction ( )
319+ it ( 'should show errors for the first wrong message' , async ( ) => {
320+ await runAction ( )
317321
318- td . verify ( core . setFailed ( contains ( firstMessage ) ) )
319- } )
322+ td . verify ( core . setFailed ( contains ( firstMessage ) ) )
323+ } )
320324
321- it ( 'should show errors for the second wrong message' , async ( ) => {
322- await runAction ( )
325+ it ( 'should show errors for the second wrong message' , async ( ) => {
326+ await runAction ( )
323327
324- td . verify ( core . setFailed ( contains ( secondMessage ) ) )
325- } )
328+ td . verify ( core . setFailed ( contains ( secondMessage ) ) )
329+ } )
326330
327- it ( 'should generate a JSON output of the errors' , async ( ) => {
328- await runAction ( )
331+ it ( 'should generate a JSON output of the errors' , async ( ) => {
332+ await runAction ( )
329333
330- td . verify ( core . setOutput ( resultsOutputId , expectedResultsOutput ) )
331- } )
332- } )
334+ td . verify ( core . setOutput ( resultsOutputId , expectedResultsOutput ) )
335+ } )
336+ } ,
337+ )
333338
334339 describe ( 'when it fails to fetch commits' , ( ) => {
335340 beforeEach ( async ( ) => {
0 commit comments