11import nock from 'nock' ;
22import tmp from 'tmp' ;
33import { encodeContent } from '../util' ;
4- import { isTargetEvent , parseConfig , getWorkspace , getCommitMessage , getBuildCommands , isGitCloned , getGitUrl } from '../../src/utils/misc' ;
5- import { DEFAULT_COMMIT_MESSAGE } from '../../src/constant' ;
4+ import { isTargetEvent , parseConfig , getCommitMessage , getCloneDepth , getBuildCommands , isGitCloned , getGitUrl } from '../../src/utils/misc' ;
5+ import { DEFAULT_COMMIT_MESSAGE , DEFAULT_CLONE_DEPTH } from '../../src/constant' ;
66
77const fs = require ( 'fs' ) ;
88const path = require ( 'path' ) ;
@@ -88,7 +88,7 @@ describe('parseConfig', () => {
8888 } ) ;
8989} ) ;
9090
91- describe ( 'getWorkspace ' , ( ) => {
91+ describe ( 'getCommitMessage ' , ( ) => {
9292 const OLD_ENV = process . env ;
9393
9494 beforeEach ( ( ) => {
@@ -101,24 +101,17 @@ describe('getWorkspace', () => {
101101 process . env = OLD_ENV ;
102102 } ) ;
103103
104- it ( 'should return workspace ' , ( ) => {
105- process . env . INPUT_GITHUB_WORKSPACE = 'test' ;
106- expect ( getWorkspace ( ) ) . toBe ( 'test' ) ;
104+ it ( 'should get commit message ' , ( ) => {
105+ process . env . INPUT_COMMIT_MESSAGE = 'test' ;
106+ expect ( getCommitMessage ( ) ) . toBe ( 'test' ) ;
107107 } ) ;
108108
109- it ( 'should throw error' , ( ) => {
110- const fn = jest . fn ( ) ;
111- try {
112- expect ( getWorkspace ( ) ) . toBe ( 'test' ) ;
113- } catch ( error ) {
114- fn ( ) ;
115- expect ( error . message ) . toBe ( 'Input required and not supplied: GITHUB_WORKSPACE' ) ;
116- }
117- expect ( fn ) . toBeCalled ( ) ;
109+ it ( 'should get commit default message' , ( ) => {
110+ expect ( getCommitMessage ( ) ) . toBe ( DEFAULT_COMMIT_MESSAGE ) ;
118111 } ) ;
119112} ) ;
120113
121- describe ( 'getCommitMessage ' , ( ) => {
114+ describe ( 'getCloneDepth ' , ( ) => {
122115 const OLD_ENV = process . env ;
123116
124117 beforeEach ( ( ) => {
@@ -131,13 +124,13 @@ describe('getCommitMessage', () => {
131124 process . env = OLD_ENV ;
132125 } ) ;
133126
134- it ( 'should get commit message ' , ( ) => {
135- process . env . INPUT_COMMIT_MESSAGE = 'test ' ;
136- expect ( getCommitMessage ( ) ) . toBe ( 'test ' ) ;
127+ it ( 'should get clone depth ' , ( ) => {
128+ process . env . INPUT_CLONE_DEPTH = '3 ' ;
129+ expect ( getCloneDepth ( ) ) . toBe ( '3 ' ) ;
137130 } ) ;
138131
139- it ( 'should get commit default message ' , ( ) => {
140- expect ( getCommitMessage ( ) ) . toBe ( DEFAULT_COMMIT_MESSAGE ) ;
132+ it ( 'should get default clone depth ' , ( ) => {
133+ expect ( getCloneDepth ( ) ) . toBe ( DEFAULT_CLONE_DEPTH ) ;
141134 } ) ;
142135} ) ;
143136
@@ -168,6 +161,26 @@ describe('getBuildCommands', () => {
168161
169162describe ( 'isGitCloned' , ( ) => {
170163 const OLD_ENV = process . env ;
164+ const context = ( ) => ( {
165+ payload : {
166+ action : 'created' ,
167+ } ,
168+ eventName : 'release' ,
169+ sha : '' ,
170+ ref : '' ,
171+ workflow : dir . name ,
172+ action : '' ,
173+ actor : '' ,
174+ issue : {
175+ owner : '' ,
176+ repo : '' ,
177+ number : 1 ,
178+ } ,
179+ repo : {
180+ owner : '' ,
181+ repo : '' ,
182+ } ,
183+ } ) ;
171184 let dir ;
172185
173186 beforeEach ( ( ) => {
@@ -184,13 +197,11 @@ describe('isGitCloned', () => {
184197
185198 it ( 'should return true' , ( ) => {
186199 fs . mkdirSync ( path . resolve ( dir . name , '.git' ) ) ;
187- process . env . INPUT_GITHUB_WORKSPACE = dir . name ;
188- expect ( isGitCloned ( ) ) . toBeTruthy ( ) ;
200+ expect ( isGitCloned ( context ( ) ) ) . toBeTruthy ( ) ;
189201 } ) ;
190202
191203 it ( 'should return false' , ( ) => {
192- process . env . INPUT_GITHUB_WORKSPACE = dir . name ;
193- expect ( isGitCloned ( ) ) . toBeFalsy ( ) ;
204+ expect ( isGitCloned ( context ( ) ) ) . toBeFalsy ( ) ;
194205 } ) ;
195206} ) ;
196207
0 commit comments