11import * as github from '@actions/github' ;
22
3- import buildExec from './buildExec' ;
3+ import {
4+ buildCommitExec ,
5+ buildExec ,
6+ buildGeneralExec ,
7+ buildReportExec ,
8+ buildUploadExec ,
9+ } from './buildExec' ;
410
5- /* eslint-disable @typescript-eslint/no-var-requires */
6- const { version} = require ( '../package.json' ) ;
11+ import { version } from '../package.json' ;
712
813const context = github . context ;
914
@@ -19,6 +24,7 @@ test('no arguments', () => {
1924 if ( context . eventName == 'pull_request' ) {
2025 args . push ( '-C' , `${ context . payload . pull_request . head . sha } ` ) ;
2126 }
27+
2228 expect ( execArgs ) . toEqual ( args ) ;
2329 expect ( failCi ) . toBeFalsy ( ) ;
2430} ) ;
@@ -151,7 +157,7 @@ describe('trim arguments after splitting them', () => {
151157 ] ;
152158
153159 test ( 'files' , ( ) => {
154- const envs = { ' files' : './client-coverage.txt, ./lcov.info' } ;
160+ const envs = { files : './client-coverage.txt, ./lcov.info' } ;
155161
156162 for ( const [ name , value ] of Object . entries ( envs ) ) {
157163 process . env [ 'INPUT_' + name . toUpperCase ( ) ] = value ;
@@ -175,7 +181,7 @@ describe('trim arguments after splitting them', () => {
175181 } ) ;
176182
177183 test ( 'flags' , ( ) => {
178- const envs = { ' flags' : 'ios, mobile' } ;
184+ const envs = { flags : 'ios, mobile' } ;
179185
180186 for ( const [ name , value ] of Object . entries ( envs ) ) {
181187 process . env [ 'INPUT_' + name . toUpperCase ( ) ] = value ;
@@ -199,7 +205,7 @@ describe('trim arguments after splitting them', () => {
199205 } ) ;
200206
201207 test ( 'functionalities' , ( ) => {
202- const envs = { ' functionalities' : 'network, gcov' } ;
208+ const envs = { functionalities : 'network, gcov' } ;
203209
204210 for ( const [ name , value ] of Object . entries ( envs ) ) {
205211 process . env [ 'INPUT_' + name . toUpperCase ( ) ] = value ;
@@ -222,3 +228,212 @@ describe('trim arguments after splitting them', () => {
222228 }
223229 } ) ;
224230} ) ;
231+
232+ test ( 'general args' , ( ) => {
233+ const envs = {
234+ url : 'https://codecov.enterprise.com' ,
235+ verbose : 't' ,
236+ } ;
237+ for ( const env of Object . keys ( envs ) ) {
238+ process . env [ 'INPUT_' + env . toUpperCase ( ) ] = envs [ env ] ;
239+ }
240+
241+ const args = buildGeneralExec ( ) ;
242+
243+ expect ( args ) . toEqual (
244+ expect . arrayContaining ( [
245+ '--enterprise-url' ,
246+ 'https://codecov.enterprise.com' ,
247+ '-v' ,
248+ ] ) ) ;
249+
250+ for ( const env of Object . keys ( envs ) ) {
251+ delete process . env [ 'INPUT_' + env . toUpperCase ( ) ] ;
252+ }
253+ } ) ;
254+
255+
256+ test ( 'upload args using context' , ( ) => {
257+ const expectedArgs = [
258+ '-n' ,
259+ '' ,
260+ ] ;
261+ const { uploadExecArgs, uploadCommand} = buildUploadExec ( ) ;
262+ if ( context . eventName == 'pull_request' ) {
263+ expectedArgs . push ( '-C' , `${ context . payload . pull_request . head . sha } ` ) ;
264+ }
265+ if ( context . eventName == 'pull_request_target' ) {
266+ expectedArgs . push ( '-P' , `${ context . payload . number } ` ) ;
267+ }
268+
269+ expect ( uploadExecArgs ) . toEqual ( expectedArgs ) ;
270+ expect ( uploadCommand ) . toEqual ( 'do-upload' ) ;
271+ } ) ;
272+
273+ test ( 'upload args' , ( ) => {
274+ const envs = {
275+ 'directory' : 'coverage/' ,
276+ 'dry_run' : 'true' ,
277+ 'env_vars' : 'OS,PYTHON' ,
278+ 'fail_ci_if_error' : 'true' ,
279+ 'file' : 'coverage.xml' ,
280+ 'files' : 'dir1/coverage.xml,dir2/coverage.xml' ,
281+ 'flags' : 'test,test2' ,
282+ 'name' : 'codecov' ,
283+ 'override_branch' : 'thomasrockhu/test' ,
284+ 'override_build' : '1' ,
285+ 'override_commit' : '9caabca5474b49de74ef5667deabaf74cdacc244' ,
286+ 'override_pr' : '2' ,
287+ 'root_dir' : 'root/' ,
288+ 'slug' : 'fakeOwner/fakeRepo' ,
289+ 'token' : 'd3859757-ab80-4664-924d-aef22fa7557b' ,
290+ 'working-directory' : 'src' ,
291+ 'plugin' : 'xcode' ,
292+ 'exclude' : 'src' ,
293+ } ;
294+ for ( const env of Object . keys ( envs ) ) {
295+ process . env [ 'INPUT_' + env . toUpperCase ( ) ] = envs [ env ] ;
296+ }
297+
298+ const { uploadExecArgs, uploadCommand} = buildUploadExec ( ) ;
299+ const expectedArgs = [
300+ '-n' ,
301+ 'codecov' ,
302+ '-d' ,
303+ '-e' ,
304+ 'OS,PYTHON' ,
305+ '-Z' ,
306+ '-f' ,
307+ 'coverage.xml' ,
308+ '-f' ,
309+ 'dir1/coverage.xml' ,
310+ '-f' ,
311+ 'dir2/coverage.xml' ,
312+ '-F' ,
313+ 'test' ,
314+ '-F' ,
315+ 'test2' ,
316+ '-B' ,
317+ 'thomasrockhu/test' ,
318+ '-b' ,
319+ '1' ,
320+ '-C' ,
321+ '9caabca5474b49de74ef5667deabaf74cdacc244' ,
322+ '-P' ,
323+ '2' ,
324+ '--network-root-folder' ,
325+ 'root/' ,
326+ '-s' ,
327+ 'coverage/' ,
328+ '-r' ,
329+ 'fakeOwner/fakeRepo' ,
330+ '--plugin' ,
331+ 'xcode' ,
332+ '--exclude' ,
333+ 'src' ,
334+ ] ;
335+
336+ expect ( uploadExecArgs ) . toEqual ( expectedArgs ) ;
337+ expect ( uploadCommand ) . toEqual ( 'do-upload' ) ;
338+ for ( const env of Object . keys ( envs ) ) {
339+ delete process . env [ 'INPUT_' + env . toUpperCase ( ) ] ;
340+ }
341+ } ) ;
342+
343+
344+ test ( 'report args' , ( ) => {
345+ const envs = {
346+ override_commit : '9caabca5474b49de74ef5667deabaf74cdacc244' ,
347+ slug : 'fakeOwner/fakeRepo' ,
348+ token : 'd3859757-ab80-4664-924d-aef22fa7557b' ,
349+ } ;
350+ for ( const env of Object . keys ( envs ) ) {
351+ process . env [ 'INPUT_' + env . toUpperCase ( ) ] = envs [ env ] ;
352+ }
353+
354+ const { reportExecArgs, reportCommand} = buildReportExec ( ) ;
355+
356+ expect ( reportExecArgs ) . toEqual (
357+ expect . arrayContaining ( [
358+ '-C' ,
359+ '9caabca5474b49de74ef5667deabaf74cdacc244' ,
360+ '--slug' ,
361+ 'fakeOwner/fakeRepo' ,
362+ ] ) ) ;
363+ expect ( reportCommand ) . toEqual ( 'create-report' ) ;
364+ for ( const env of Object . keys ( envs ) ) {
365+ delete process . env [ 'INPUT_' + env . toUpperCase ( ) ] ;
366+ }
367+ } ) ;
368+
369+
370+ test ( 'report args using context' , ( ) => {
371+ const envs = {
372+ token : 'd3859757-ab80-4664-924d-aef22fa7557b' ,
373+ } ;
374+ for ( const env of Object . keys ( envs ) ) {
375+ process . env [ 'INPUT_' + env . toUpperCase ( ) ] = envs [ env ] ;
376+ }
377+ const expectedArgs : string [ ] = [ ] ;
378+ if ( context . eventName == 'pull_request' ) {
379+ expectedArgs . push ( '-C' , `${ context . payload . pull_request . head . sha } ` ) ;
380+ }
381+
382+ const { reportExecArgs, reportCommand} = buildReportExec ( ) ;
383+
384+ expect ( reportExecArgs ) . toEqual ( expectedArgs ) ;
385+ expect ( reportCommand ) . toEqual ( 'create-report' ) ;
386+ for ( const env of Object . keys ( envs ) ) {
387+ delete process . env [ 'INPUT_' + env . toUpperCase ( ) ] ;
388+ }
389+ } ) ;
390+
391+
392+ test ( 'commit args' , ( ) => {
393+ const envs = {
394+ override_commit : '9caabca5474b49de74ef5667deabaf74cdacc244' ,
395+ slug : 'fakeOwner/fakeRepo' ,
396+ token : 'd3859757-ab80-4664-924d-aef22fa7557b' ,
397+ override_branch : 'thomasrockhu/test' ,
398+ override_pr : '2' ,
399+ commit_parent : '83231650328f11695dfb754ca0f540516f188d27' ,
400+ } ;
401+ for ( const env of Object . keys ( envs ) ) {
402+ process . env [ 'INPUT_' + env . toUpperCase ( ) ] = envs [ env ] ;
403+ }
404+
405+ const { commitExecArgs, commitCommand} = buildCommitExec ( ) ;
406+
407+ expect ( commitExecArgs ) . toEqual (
408+ expect . arrayContaining ( [
409+ '-C' ,
410+ '9caabca5474b49de74ef5667deabaf74cdacc244' ,
411+ '--slug' ,
412+ 'fakeOwner/fakeRepo' ,
413+ '-B' ,
414+ 'thomasrockhu/test' ,
415+ '--pr' ,
416+ '2' ,
417+ '--parent-sha' ,
418+ '83231650328f11695dfb754ca0f540516f188d27' ,
419+ ] ) ) ;
420+ expect ( commitCommand ) . toEqual ( 'create-commit' ) ;
421+ for ( const env of Object . keys ( envs ) ) {
422+ delete process . env [ 'INPUT_' + env . toUpperCase ( ) ] ;
423+ }
424+ } ) ;
425+
426+ test ( 'commit args using context' , ( ) => {
427+ const expectedArgs :string [ ] = [ ] ;
428+
429+ const { commitExecArgs, commitCommand} = buildCommitExec ( ) ;
430+ if ( context . eventName == 'pull_request' ) {
431+ expectedArgs . push ( '-C' , `${ context . payload . pull_request . head . sha } ` ) ;
432+ }
433+ if ( context . eventName == 'pull_request_target' ) {
434+ expectedArgs . push ( '-P' , `${ context . payload . number } ` ) ;
435+ }
436+
437+ expect ( commitExecArgs ) . toEqual ( expectedArgs ) ;
438+ expect ( commitCommand ) . toEqual ( 'create-commit' ) ;
439+ } ) ;
0 commit comments