Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot use mockSteps with specific workflowFile passed to Act #24

Closed
shivshav opened this issue Apr 12, 2023 · 1 comment · Fixed by #26
Closed

Cannot use mockSteps with specific workflowFile passed to Act #24

shivshav opened this issue Apr 12, 2023 · 1 comment · Fixed by #26
Assignees
Labels
bug Something isn't working

Comments

@shivshav
Copy link

shivshav commented Apr 12, 2023

Hello there! First of all, thank you for this lib, it's turning out to be very useful so far so I appreciate the work put it into it!

Describe the bug
I believe there's a bug if you try to use both step mocking and passing a specific workflow file to the act runner together

To Reproduce

Workflow file
name: Test
on: [push]

jobs:
  repro:
    name: bug repro
    runs-on: ubuntu-latest
    steps:
    - name: step 1 (mocked)
      run: echo "this is the real command"
    - name: step 2 (not mocked)
      run: echo "this is the real command"

Minimal test file
const path = require("path");
const { Act } = require("@kie/act-js");
const { MockGithub } = require("@kie/mock-github");
const { beforeEach, test, afterEach, expect} = require("@jest/globals");

let mockGithub;


beforeEach(async () => {
    mockGithub = new MockGithub({
        repo: {
            test: {
                files: [
                    {
                        src: path.join(__dirname, "workflowfile-plus-mocksteps-repro.yaml"),
                        dest: "/.github/workflows/workflow-file-plus-mocksteps-repro.yaml",
                    }
                ]
            },
        }
    })
    await mockGithub.setup();

})

afterEach(async () => {
    await mockGithub.teardown();
})

test("workflow file + mockSteps repro", async () => {
    const act = new Act(mockGithub.repo.getPath("test"), ".github/workflows/workflow-file-plus-mocksteps-repro.yaml");
    const result = await act.runEvent("push", {
        logFile: process.env.ACT_LOG ? "workflow.log" : undefined,
        mockSteps: {
            "repro": [{name: "step 1 (mocked)", mockWith: "echo this is the mocked command"}]
        }
    })
    expect(result).toStrictEqual([
        {name: "Main step 1 (mocked)", status: 0, output: "this is the mocked command"},
        {name: "Main step 2 (not mocked)", status: 0, output: "this is the real command"}
    ])
})

Expected behavior

Both options are able to be used in conjunction and the given workflow file executes with the proper step mocked

Logs
Never makes it far enough for the act to actually execute, but the jest output is noted below.

 FAIL  action/deploy/v3/test/repro.test.js
  ✕ workflow file + mockSteps repro (1268 ms)

  ● workflow file + mockSteps repro

    Could not locate workflow-file-plus-mocksteps-repro.yaml

      30 | test("workflow file + mockSteps repro", async () => {
      31 |     const act = new Act(mockGithub.repo.getPath("test"), ".github/workflows/workflow-file-plus-mocksteps-repro.yaml");
    > 32 |     const result = await act.runEvent("push", {
         |                    ^
      33 |         logFile: process.env.ACT_LOG ? "workflow.log" : undefined,
      34 |         mockSteps: {
      35 |             "repro": [{name: "step 1 (mocked)", mockWith: "echo this is the mocked command"}]

      at StepMocker.getWorkflowPath (node_modules/@kie/act-js/build/src/step-mocker/step-mocker.js:63:19)
      at StepMocker.mock (node_modules/@kie/act-js/build/src/step-mocker/step-mocker.js:17:31)
      at node_modules/@kie/act-js/build/src/act/act.js:131:35
          at Array.map (<anonymous>)
      at Act.handleStepMocking (node_modules/@kie/act-js/build/src/act/act.js:129:46)
      at Act.runEvent (node_modules/@kie/act-js/build/src/act/act.js:118:9)
      at Object.<anonymous> (action/deploy/v3/test/repro.test.js:32:20)

Test Suites: 1 failed, 1 total
Tests:       1 failed, 1 total
Snapshots:   0 total
Time:        1.556 s, estimated 2 s
Ran all test suites matching /action\/deploy\/v3\/test\/repro.test.js/i.

Additional context
I suspect this is a problem with the arguments passed to the StepMocker from the Act class. The StepMocker expects the workflowFile + cwd here but what actually gets passed from Act's handleStepMocking call is the path to the workflow file 2x so that when this function tries to find the workflow file, none of the if branches are a match.

@shubhbapna
Copy link
Collaborator

You are absolutely right! Thank you for reporting this. I will have a fix out asap

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants