11import { promises as fs } from 'fs' ;
2- import { load } from 'js-yaml' ;
32import { writePackageJson } from '@form8ion/javascript-core' ;
4- import { scaffoldCheckoutStep , scaffoldNodeSetupStep , writeWorkflowFile } from '@form8ion/github-workflows-core' ;
3+ import {
4+ loadWorkflowFile ,
5+ scaffoldCheckoutStep ,
6+ scaffoldNodeSetupStep ,
7+ writeWorkflowFile
8+ } from '@form8ion/github-workflows-core' ;
59
610import { Given , Then } from '@cucumber/cucumber' ;
711import any from '@travi/any' ;
812import { assert } from 'chai' ;
913import * as td from 'testdouble' ;
1014
11- import { pathToWorkflowsDirectory } from './ci-steps.js' ;
12-
1315const ciWorkflowName = 'node-ci' ;
14- const pathToCiWorkflow = `${ pathToWorkflowsDirectory } /${ ciWorkflowName } .yml` ;
1516
1617Given ( 'the nvmrc is referenced using the modern property {string} caching enabled' , async function ( cachingEnabled ) {
1718 this . existingJobName = any . word ( ) ;
@@ -28,7 +29,7 @@ Given('the nvmrc is referenced using the modern property {string} caching enable
2829 { run : 'npm clean-install' }
2930 ] ;
3031
31- const ciWorkflow = load ( await fs . readFile ( pathToCiWorkflow , 'utf-8' ) ) ;
32+ const ciWorkflow = await loadWorkflowFile ( { projectRoot : this . projectRoot , name : ciWorkflowName } ) ;
3233
3334 ciWorkflow . jobs [ this . existingJobName ] = { steps : this . existingJobSteps } ;
3435
@@ -56,7 +57,7 @@ Given('the version is read from the nvmrc and passed as a value to the setup-nod
5657 { run : 'npm clean-install' }
5758 ] ;
5859
59- const ciWorkflow = load ( await fs . readFile ( pathToCiWorkflow , 'utf-8' ) ) ;
60+ const ciWorkflow = await loadWorkflowFile ( { projectRoot : this . projectRoot , name : ciWorkflowName } ) ;
6061
6162 ciWorkflow . jobs [ this . existingJobName ] = { steps : this . existingJobSteps } ;
6263
@@ -83,7 +84,7 @@ Given('the node version is based on a matrix {string} caching enabled', async fu
8384 { run : 'npm clean-install' }
8485 ] ;
8586
86- const ciWorkflow = load ( await fs . readFile ( pathToCiWorkflow , 'utf-8' ) ) ;
87+ const ciWorkflow = await loadWorkflowFile ( { projectRoot : this . projectRoot , name : ciWorkflowName } ) ;
8788
8889 ciWorkflow . jobs [ this . existingJobName ] = {
8990 strategy : { matrix : { node : this . existingNodeVersions } } ,
@@ -105,7 +106,7 @@ Given('the version is defined statically', async function () {
105106 { run : 'npm clean-install' }
106107 ] ;
107108
108- const ciWorkflow = load ( await fs . readFile ( pathToCiWorkflow , 'utf-8' ) ) ;
109+ const ciWorkflow = await loadWorkflowFile ( { projectRoot : this . projectRoot , name : ciWorkflowName } ) ;
109110
110111 ciWorkflow . jobs [ this . existingJobName ] = { steps : this . existingJobSteps } ;
111112
@@ -156,7 +157,7 @@ Given('multiple node version ranges are defined', async function () {
156157Then ( 'the setup-node step is updated to reference the nvmrc file using the modern property' , async function ( ) {
157158 const {
158159 jobs : { [ this . existingJobName ] : existingJob }
159- } = load ( await fs . readFile ( ` ${ process . cwd ( ) } /.github/workflows/node-ci.yml` , 'utf-8' ) ) ;
160+ } = await loadWorkflowFile ( { projectRoot : this . projectRoot , name : ciWorkflowName } ) ;
160161
161162 assert . isEmpty ( existingJob . steps . filter ( step => 'nvm' === step . id ) ) ;
162163
@@ -166,13 +167,13 @@ Then('the setup-node step is updated to reference the nvmrc file using the moder
166167} ) ;
167168
168169Then ( 'no matrix job is configured' , async function ( ) {
169- const { jobs} = load ( await fs . readFile ( ` ${ process . cwd ( ) } /.github/workflows/node-ci.yml` , 'utf-8' ) ) ;
170+ const { jobs} = await loadWorkflowFile ( { projectRoot : this . projectRoot , name : ciWorkflowName } ) ;
170171
171172 assert . equal ( Object . values ( jobs ) . filter ( job => job . strategy ?. matrix ) . length , 0 ) ;
172173} ) ;
173174
174175Then ( 'the matrix job is unchanged' , async function ( ) {
175- const { jobs} = load ( await fs . readFile ( ` ${ process . cwd ( ) } /.github/workflows/node-ci.yml` , 'utf-8' ) ) ;
176+ const { jobs} = await loadWorkflowFile ( { projectRoot : this . projectRoot , name : ciWorkflowName } ) ;
176177
177178 assert . deepEqual (
178179 jobs [ this . existingJobName ] ,
@@ -181,7 +182,7 @@ Then('the matrix job is unchanged', async function () {
181182} ) ;
182183
183184Then ( 'a matrix job is added' , async function ( ) {
184- const { jobs} = load ( await fs . readFile ( ` ${ process . cwd ( ) } /.github/workflows/node-ci.yml` , 'utf-8' ) ) ;
185+ const { jobs} = await loadWorkflowFile ( { projectRoot : this . projectRoot , name : ciWorkflowName } ) ;
185186 const { 'verify-matrix' : verifyMatrixJob } = jobs ;
186187 const jobDefinitions = Object . values ( jobs ) ;
187188
@@ -204,14 +205,14 @@ Then('a matrix job is added', async function () {
204205} ) ;
205206
206207Then ( 'the matrix job uses {string} as the runner' , async function ( runner ) {
207- const { jobs} = load ( await fs . readFile ( ` ${ process . cwd ( ) } /.github/workflows/node-ci.yml` , 'utf-8' ) ) ;
208+ const { jobs} = await loadWorkflowFile ( { projectRoot : this . projectRoot , name : ciWorkflowName } ) ;
208209 const { 'verify-matrix' : verifyMatrixJob } = jobs ;
209210
210211 assert . equal ( verifyMatrixJob [ 'runs-on' ] , runner ) ;
211212} ) ;
212213
213214Then ( 'the matrix job is updated' , async function ( ) {
214- const { jobs} = load ( await fs . readFile ( ` ${ process . cwd ( ) } /.github/workflows/node-ci.yml` , 'utf-8' ) ) ;
215+ const { jobs} = await loadWorkflowFile ( { projectRoot : this . projectRoot , name : ciWorkflowName } ) ;
215216
216217 assert . equal ( Object . values ( jobs ) . filter ( job => job . strategy ?. matrix ) . length , 1 ) ;
217218 assert . deepEqual (
0 commit comments