11import type { SimpleGit } from 'simple-git' ;
22import type { Tags } from '@model/tags' ;
3+ import { info } from '@actions/core' ;
34import type { getInput } from '@actions/core' ;
45
56import { it , jest , describe , expect } from '@jest/globals' ;
@@ -21,6 +22,13 @@ jest.mock('@model/tags', () => ({
2122 } ,
2223} ) ) ;
2324
25+ jest . mock ( '@actions/core' , ( ) => ( {
26+ getInput : jest . fn ( ) ,
27+ info : jest . fn ( ) ,
28+ startGroup : jest . fn ( ) ,
29+ endGroup : jest . fn ( )
30+ } ) )
31+
2432describe ( 'Artifacts' , ( ) => {
2533 it ( 'Compile the assets and Deploy when finished' , async ( ) => {
2634 const git = fromPartial < SimpleGit > ( {
@@ -85,6 +93,31 @@ describe('Artifacts', () => {
8593 await expect ( artifacts . update ( ) ) . rejects . toThrow ( 'Failed creating artifacts: Failed to push' ) ;
8694 } ) ;
8795
96+ it ( 'Do not push when the action is not configured to do so' , async ( ) => {
97+ const push = jest . fn ( ) ;
98+ const git = fromPartial < SimpleGit > ( {
99+ commit : jest . fn ( ( ) =>
100+ Promise . resolve ( { summary : { changes : 0 , insertions : 0 , deletions : 0 } } )
101+ ) ,
102+ push,
103+ } ) ;
104+ const tags = fromPartial < Tags > ( { collect : jest . fn ( ) , move : jest . fn ( ) } ) ;
105+ const artifacts = new Artifacts (
106+ git ,
107+ tags ,
108+ configuration ( undefined , {
109+ 'can-push' : 'false' ,
110+ } )
111+ ) ;
112+
113+ jest . mocked ( exec ) . mockImplementation ( async ( ) => Promise . resolve ( 0 ) ) ;
114+
115+ await artifacts . update ( ) ;
116+
117+ expect ( push ) . not . toHaveBeenCalled ( ) ;
118+ expect ( info ) . toHaveBeenCalledWith ( 'Skipping pushing artifacts.' ) ;
119+ } ) ;
120+
88121 it ( 'Throw an error when failing to git-add' , async ( ) => {
89122 const git = fromPartial < SimpleGit > ( { } ) ;
90123 const tags = fromPartial < Tags > ( { collect : jest . fn ( ) } ) ;
@@ -168,7 +201,12 @@ describe('Artifacts', () => {
168201 } ) ;
169202} ) ;
170203
171- function configuration ( env ?: Readonly < NodeJS . ProcessEnv > ) : Configuration {
204+ type InputsConfiguration = Readonly < Record < string , unknown > > ;
205+
206+ function configuration (
207+ env ?: Readonly < NodeJS . ProcessEnv > ,
208+ inputsConfiguration : InputsConfiguration = { }
209+ ) : Configuration {
172210 let _env = env ;
173211
174212 if ( ! _env ) {
@@ -177,11 +215,19 @@ function configuration(env?: Readonly<NodeJS.ProcessEnv>): Configuration {
177215 } ;
178216 }
179217
180- return new Configuration ( stubGetInput ( ) , _env ) ;
218+ return new Configuration (
219+ stubGetInput ( {
220+ command : 'yarn build' ,
221+ 'target-dir' : './build' ,
222+ 'can-push' : 'true' ,
223+ ...inputsConfiguration ,
224+ } ) ,
225+ _env
226+ ) ;
181227}
182228
183- function stubGetInput ( ) : typeof getInput {
229+ function stubGetInput ( inputsConfiguration : InputsConfiguration ) : typeof getInput {
184230 return jest . fn ( ( name : string ) : string => {
185- return name === 'command' ? 'yarn build' : './build' ;
231+ return String ( Object . hasOwn ( inputsConfiguration , name ) ? inputsConfiguration [ name ] : undefined ) ;
186232 } ) ;
187233}
0 commit comments