11import { promises as fs } from 'node:fs' ;
22import jsYaml from 'js-yaml' ;
3+ import { writeWorkflowFile } from '@form8ion/github-workflows-core' ;
34
45import { afterEach , beforeEach , describe , it , vi , expect } from 'vitest' ;
56import any from '@travi/any' ;
@@ -12,14 +13,14 @@ import lift from './lifter.js';
1213
1314vi . mock ( 'node:fs' ) ;
1415vi . mock ( 'js-yaml' ) ;
16+ vi . mock ( '@form8ion/github-workflows-core' ) ;
1517vi . mock ( './branches/merge-branches' ) ;
1618vi . mock ( '../jobs/index.js' ) ;
1719vi . mock ( '../badges' ) ;
1820
1921describe ( 'lifter' , ( ) => {
2022 const projectRoot = any . string ( ) ;
2123 const rawExistingConfig = any . string ( ) ;
22- const dumpedConfig = any . string ( ) ;
2324 const existingJobs = any . listOf ( any . simpleObject ) ;
2425 const liftedJobs = any . listOf ( any . simpleObject ) ;
2526 const enginesDefinition = any . simpleObject ( ) ;
@@ -49,12 +50,13 @@ describe('lifter', () => {
4950 jobs : existingJobs
5051 } ;
5152 when ( jsYaml . load ) . calledWith ( rawExistingConfig ) . mockReturnValue ( existingConfig ) ;
52- when ( jsYaml . dump )
53- . calledWith ( { ...existingConfig , permissions : { contents : 'read' } , jobs : liftedJobs } )
54- . mockReturnValue ( dumpedConfig ) ;
5553
5654 expect ( await lift ( { projectRoot, results : any . simpleObject ( ) , vcs, runner} ) ) . toEqual ( { badges : badgesResults } ) ;
57- expect ( fs . writeFile ) . toHaveBeenCalledWith ( `${ projectRoot } /.github/workflows/node-ci.yml` , dumpedConfig ) ;
55+ expect ( writeWorkflowFile ) . toHaveBeenCalledWith ( {
56+ projectRoot,
57+ name : 'node-ci' ,
58+ config : { ...existingConfig , permissions : { contents : 'read' } , jobs : liftedJobs }
59+ } ) ;
5860 } ) ;
5961
6062 it ( 'should append the additional branches to the existing list' , async ( ) => {
@@ -68,17 +70,18 @@ describe('lifter', () => {
6870 const mergedBranches = any . listOf ( any . word ) ;
6971 when ( jsYaml . load ) . calledWith ( rawExistingConfig ) . mockReturnValue ( existingConfig ) ;
7072 when ( mergeBranchList ) . calledWith ( existingBranches , branchesToVerify ) . mockReturnValue ( mergedBranches ) ;
71- when ( jsYaml . dump )
72- . calledWith ( {
73+
74+ expect ( await lift ( { projectRoot, results : { ...any . simpleObject ( ) , branchesToVerify} , vcs, runner} ) )
75+ . toEqual ( { badges : badgesResults } ) ;
76+ expect ( writeWorkflowFile ) . toHaveBeenCalledWith ( {
77+ projectRoot,
78+ name : 'node-ci' ,
79+ config : {
7380 ...existingConfig ,
7481 on : { ...existingConfig . on , push : { branches : mergedBranches } } ,
7582 permissions : { contents : 'read' } ,
7683 jobs : liftedJobs
77- } )
78- . mockReturnValue ( dumpedConfig ) ;
79-
80- expect ( await lift ( { projectRoot, results : { ...any . simpleObject ( ) , branchesToVerify} , vcs, runner} ) )
81- . toEqual ( { badges : badgesResults } ) ;
82- expect ( fs . writeFile ) . toHaveBeenCalledWith ( `${ projectRoot } /.github/workflows/node-ci.yml` , dumpedConfig ) ;
84+ }
85+ } ) ;
8386 } ) ;
8487} ) ;
0 commit comments