diff --git a/package-lock.json b/package-lock.json index 2d722f9..4ef007c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@kie/act-js", - "version": "2.0.6", + "version": "2.0.7", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@kie/act-js", - "version": "2.0.6", + "version": "2.0.7", "hasInstallScript": true, "license": "SEE LICENSE IN LICENSE", "dependencies": { diff --git a/package.json b/package.json index b46bc2c..d4029a1 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@kie/act-js", - "version": "2.0.6", + "version": "2.0.7", "description": "nodejs wrapper for nektos/act", "main": "build/src/index.js", "types": "build/src/index.d.ts", diff --git a/src/act/act.ts b/src/act/act.ts index cdc88e6..ab7fe32 100644 --- a/src/act/act.ts +++ b/src/act/act.ts @@ -162,14 +162,24 @@ export class Act { ) { if (opts?.mockSteps) { // there could multiple workflow files with same event triggers or job names. Act executes them all - const workflowNames = ( - await this.list(undefined, opts.cwd, opts.workflowFile) - ).filter(filter); + let workflowFiles: string[] = []; + + // if workflow file was defined then no need to consider all possible options + if (opts.workflowFile) { + workflowFiles = [path.basename(opts.workflowFile)]; + } else if (this.workflowFile !== this.cwd) { + workflowFiles = [path.basename(this.workflowFile)]; + } else { + workflowFiles = ( + await this.list(undefined, opts.cwd, opts.workflowFile) + ).filter(filter).map(l => l.workflowFile); + } + return Promise.all( - workflowNames.map(name => { + workflowFiles.map(workflowFile => { const stepMocker = new StepMocker( - name.workflowFile, - opts.workflowFile ?? this.workflowFile + workflowFile, + opts.cwd ?? this.cwd ); return stepMocker.mock(opts.mockSteps!); }) diff --git a/test/unit/act/act.test.ts b/test/unit/act/act.test.ts index c7d7c0d..2c00ed5 100644 --- a/test/unit/act/act.test.ts +++ b/test/unit/act/act.test.ts @@ -146,10 +146,14 @@ describe("run", () => { ]); }); - test("run job with mocked step", async () => { + test.each([ + ["no specific workflow file", undefined], + ["specific workflow file", path.join(resources, "push1.yml")], + ])("run job with mocked step: %p", async (_title: string, workflowFile: string | undefined) => { const original = fs.readFileSync(path.join(resources, "push1.yml"), "utf8"); - const act = new Act(__dirname, resources); + const act = new Act(resources); const output = await act.runJob("push1", { + workflowFile, mockSteps: { push1: [ { @@ -185,12 +189,15 @@ describe("run", () => { fs.writeFileSync(path.join(resources, "push1.yml"), original); }); - test("run event with mocked step", async () => { + test.each([ + ["no specific workflow file", undefined], + ["specific workflow file", path.join(resources, "pull_request.yml")], + ])("run event with mocked step: %p", async (_title: string, workflowFile: string | undefined) => { const original = fs.readFileSync( path.join(resources, "pull_request.yml"), "utf8" ); - const act = new Act(undefined, resources); + const act = new Act(resources, workflowFile); const output = await act.runEvent("pull_request", { mockSteps: { pr: [