11import { describe , it , before , beforeEach , mock } from 'node:test'
22import assert from 'node:assert/strict'
3- import actionConfigFixture from './fixtures/action-config.js'
43import actionMessage from '../src/action-message.js'
54
65const commitFixture = {
@@ -25,7 +24,6 @@ const prFixture = {
2524
2625let pullsGetResponse = { data : prFixture }
2726let listCommitsResponse = { data : [ { commit : commitFixture } ] }
28- let actionConfigResponse = actionConfigFixture
2927
3028const mockCore = {
3129 info : mock . fn ( ) ,
@@ -43,21 +41,13 @@ const githubClient = {
4341 }
4442}
4543
46- const mockGetActionConfig = mock . fn ( ( ) => actionConfigResponse )
47-
48- mock . module ( '@actions/core' , { exports : mockCore } )
44+ mock . module ( '@actions/core' , { namedExports : mockCore } )
4945mock . module ( '@actions/github' , {
50- exports : {
46+ namedExports : {
5147 getOctokit : mock . fn ( ( ) => githubClient ) ,
5248 context : { payload : { pull_request : contextPrFixture } }
5349 }
5450} )
55- mock . module ( '../src/utils.js' , {
56- exports : {
57- getActionConfig : mockGetActionConfig ,
58- getCommitSubject : ( msg = '' ) => msg . split ( '\n' ) [ 0 ]
59- }
60- } )
6151
6252let lintPR
6353
@@ -68,11 +58,14 @@ before(async () => {
6858function resetMocks ( ) {
6959 pullsGetResponse = { data : prFixture }
7060 listCommitsResponse = { data : [ { commit : commitFixture } ] }
71- actionConfigResponse = actionConfigFixture
61+ process . env . INPUT_COMMITTITLEMATCH = 'true'
62+ process . env . INPUT_IGNORECOMMITS = 'false'
63+ process . env . GITHUB_TOKEN = 'asdf'
64+ delete process . env . INPUT_COMMITLINTRULESPATH
65+ delete process . env . GITHUB_WORKSPACE
7266 for ( const fn of [
7367 mockCore . info , mockCore . warning , mockCore . error , mockCore . setFailed ,
74- githubClient . rest . pulls . get , githubClient . rest . pulls . listCommits ,
75- mockGetActionConfig
68+ githubClient . rest . pulls . get , githubClient . rest . pulls . listCommits
7669 ] ) fn . mock . resetCalls ( )
7770}
7871
@@ -105,7 +98,7 @@ describe('lintPR', () => {
10598 describe ( 'when pull request has one commit' , ( ) => {
10699 describe ( 'when IGNORE_COMMITS is true' , ( ) => {
107100 it ( 'passes if commit message is not conventional' , async ( ) => {
108- actionConfigResponse = { ... actionConfigFixture , IGNORE_COMMITS : true }
101+ process . env . INPUT_IGNORECOMMITS = ' true'
109102 listCommitsResponse = { data : [ { commit : { ...commitFixture , message : 'not conventional' } } ] }
110103
111104 await lintPR ( )
@@ -124,7 +117,7 @@ describe('lintPR', () => {
124117
125118 describe ( 'when COMMIT_TITLE_MATCH is false' , ( ) => {
126119 it ( 'passes when pr title does not match the commit subject' , async ( ) => {
127- actionConfigResponse = { ... actionConfigFixture , COMMIT_TITLE_MATCH : false }
120+ process . env . INPUT_COMMITTITLEMATCH = ' false'
128121 pullsGetResponse = { data : { ...prFixture , title : 'feat: does not match commit' } }
129122
130123 await lintPR ( )
0 commit comments