{"id":21660093,"url":"https://github.com/kiegroup/act-js","last_synced_at":"2025-12-27T05:01:01.031Z","repository":{"id":62999275,"uuid":"563676437","full_name":"kiegroup/act-js","owner":"kiegroup","description":"A node.js wrapper for nektos/act to programmatically run your github actions locally ","archived":false,"fork":false,"pushed_at":"2024-02-13T17:01:10.000Z","size":272,"stargazers_count":50,"open_issues_count":10,"forks_count":7,"subscribers_count":4,"default_branch":"main","last_synced_at":"2024-04-14T07:41:10.207Z","etag":null,"topics":["custom-github-actions-workflows","github-actions","nodejs","testing"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kiegroup.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2022-11-09T05:01:03.000Z","updated_at":"2024-04-23T22:33:34.484Z","dependencies_parsed_at":"2023-12-27T08:24:24.393Z","dependency_job_id":"3ad4a429-2212-4d90-9f9d-163767a62378","html_url":"https://github.com/kiegroup/act-js","commit_stats":{"total_commits":71,"total_committers":4,"mean_commits":17.75,"dds":0.6056338028169015,"last_synced_commit":"e2d15f637298b03d70407c54663b6eb02e4681f1"},"previous_names":[],"tags_count":43,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kiegroup%2Fact-js","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kiegroup%2Fact-js/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kiegroup%2Fact-js/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kiegroup%2Fact-js/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kiegroup","download_url":"https://codeload.github.com/kiegroup/act-js/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":226305990,"owners_count":17603913,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["custom-github-actions-workflows","github-actions","nodejs","testing"],"created_at":"2024-11-25T09:32:12.052Z","updated_at":"2025-12-27T05:01:00.964Z","avatar_url":"https://github.com/kiegroup.png","language":"TypeScript","funding_links":[],"categories":["TypeScript"],"sub_categories":[],"readme":"# act-js\n\nInstalls [nektos/act](https://github.com/nektos/act) and provides access to it as a CLI as well as an API\n\n## Table of Content\n\n- [Prerequistes](#prerequistes)\n- [Configuration](#configuration)\n- [CLI Usage](#cli-usage)\n- [API Usage](#api-usage)\n  - [Current working directory and Workflow file](#current-working-directory-and-workflow-file)\n  - [Secrets](#secrets)\n  - [Env](#env)\n  - [Input](#input)\n  - [Event payload](#event-payload)\n  - [List workflows](#list-workflows)\n  - [Run a job](#run-a-job)\n    - [Using job id](#using-job-id)\n    - [Using event name](#using-event-name)\n    - [Using event name and job id](#using-event-name-and-job-id)\n    - [Mocking apis during the run](#mocking-apis-during-the-run)\n    - [Mocking steps](#mocking-steps)\n    - [Run result](#run-result)\n- [Mockapi](#mockapi)\n  - [Defining a schema](#defining-a-schema)\n  - [Mock an api](#mock-an-api)\n    - [Mock the entire endpoint](#mock-the-entire-endpoint)\n    - [Mock an endpoint for specific parameter(s)](#mock-an-endpoint-for-specific-parameters)\n  - [Replying with a response](#replying-with-a-response)\n    - [Reply once](#reply-once)\n    - [Reply N times](#reply-n-times)\n    - [Chaining responses](#chaining-responses)\n  - [Typescript Support](#typescript-support)\n- [Example with Mock Github](#example-with-mock-github)\n- [Limitations](#limitations)\n- [Version](#version)\n\n## Prerequistes\n\n`act-js` depends on docker to run workflows.\n\nIf you are using macOS, please be sure to follow the steps outlined in [Docker Docs for how to install Docker Desktop for Mac](https://docs.docker.com/docker-for-mac/install/).\n\nIf you are using Windows, please follow steps for [installing Docker Desktop on Windows](https://docs.docker.com/docker-for-windows/install/).\n\nIf you are using Linux, you will need to [install Docker Engine](https://docs.docker.com/engine/install/).\n\n`act-js` is currently not supported with podman or other container backends (it might work, but it's not guaranteed). Please see [nektos/act #303](https://github.com/nektos/act/issues/303) for updates.\n\n## Configuration\n\nIn you first run with `act-js` as a CLI you will have to configure it.\nPlease refer to [nektos/act configuration](https://github.com/nektos/act/#configuration)\n\nThis does not apply when you are using it as a programmable interface.\n\n## CLI Usage\n\nUse locally with npm scripts\n\n```\nnpm i @kie/act-js\nnpx act-js --version\n```\n\nUse globally\n\n```\nnpm i -g @kie/act-js\nact-js --version\n```\n\nFor detailed usage on how you can use `act-js` please refer to [nektos/act](https://github.com/nektos/act)\n\n## API Usage\n\nProvides an interface for the [nektos/act](https://github.com/nektos/act/) tool to execute it programmatically. By default it uses the `act` executable that comes with the package. However, if you want to use a different executable you can do so by setting the env variable `ACT_BINARY` to point to the location of the executable you want to use.\n\n### Current working directory and Workflow file\n\nYou can set the current working directory as well as the location of workflow files (wrt to the cwd). The current working directory is from where `act` will be executed from. The workflow file location is the location from which `act` will try to read the workflow files from. Setting the workflow file is equivalent to calling `act` with `-W /path/to/workflows` option.\n\nBy default, if no current working directory is passed to the constructor, it is set to be `process.cwd()`.  \nSimilarly, by default, the workflow file location is the current working directory\n\n### Secrets\n\nYou can define, delete and clear secrets that will be used by `act` when you execute a run.\n\nThe method `setGithubToken` is quick wrapper to set the `GITHUB_TOKEN` env variable.\n\n```typescript\nlet act = new Act();\n\n// setSecret returns back the object\nact = act.setSecret(\"secret1\", \"value1\");\n\n// you can chain your setSecrets\nact\n  .setSecret(\"secret1\", \"value1\")\n  .setSecret(\"secret2\", \"value2\")\n  .setSecret(\"secret3\", \"value3\")\n  .setGithubToken(\"token\");\n\n// you can delete a secret\nact.deleteSecret(\"secret1\");\n\n// you clear all the secrets that you had previously defined\nact.clearSecret();\n```\n\n### Env\n\nYou can define, delete and clear env variables that will be used by `act` when you execute a run.\n\nThe method `setGithubStepSummary` is quick wrapper to set the `GITHUB_STEP_SUMMARY` env variable. By default it is set to `/dev/stdout`\n\n```typescript\nlet act = new Act();\n\n// setEnv returns back the object\nact = act.setEnv(\"env1\", \"value1\");\n\n// you can chain your setEnvs\nact\n  .setEnv(\"env1\", \"value1\")\n  .setEnv(\"env2\", \"value2\")\n  .setEnv(\"env3\", \"value3\")\n  .setGithubStepSummary(\"/path/to/some/file\");\n\n// you can delete a Env\nact.deleteEnv(\"env1\");\n\n// you clear all the envs that you had previously defined\nact.clearEnv();\n```\n\n### Input\n\nYou can define github action input that will be used by `act` when you execute a run.\n\n```typescript\nlet act = new Act();\n\n// setInput returns back the object\nact = act.setInput(\"input1\", \"value1\");\n\n// you can chain your setInputs\nact\n  .setInput(\"input1\", \"value1\")\n  .setInput(\"input2\", \"value2\")\n  .setInput(\"input3\", \"value3\")\n\n// you can delete an input\nact.deleteInput(\"input1\");\n\n// you clear all the inputs that you had previously defined\nact.clearInput();\n```\n\n### Event payload\n\nYou can pass an [event payload](https://docs.github.com/en/developers/webhooks-and-events/webhooks/webhook-events-and-payloads) during your workflow execution. It is equivalent to calling `act` with the `-e` flag set.\n\n```typescript\nlet act = new Act();\n\nact\n  .setEvent({\n    pull_request: {\n      head: {\n        ref: \"branch\",\n      },\n    },\n  })\n  .runEvent(\"pull_request\");\n```\n\n### List workflows\n\nYou can list all the workflows in the current working directory.\n\n```typescript\nconst act = new Act();\n\nawait act.list();\n```\n\nOr you can list workflows for a specific event in the current working directory.\n\n```typescript\nconst act = new Act();\n\n// lists all workflows which are triggered due to a pull request event\nawait act.list(\"pull_request\");\n```\n\n`list` returns an array of `Workflow` objects as defined below\n\n```typescript\n[\n  {\n    jobId: \"job id as defined in the workflow\",\n    jobName: \"job name as defined in the workflow\",\n    workflowName: \"name of the workflow\",\n    workflowFile: \"the name of the workflow file\",\n    events: \"event that triggers this workflow\",\n  },\n];\n```\n\n### Run a job\n\nWhen running a job (which ever way), you can optionally pass run options\n\n```typescript\n{\n  cwd?: string;               // overrides the global cwd and uses the one passed in options\n  workflowFile?: string;      // overrides the global workflow file path and uses the one passed in options\n  bind?: boolean;             // bind the cwd instead of copying it during workflow execution\n  artifactServer?: {          // activates the artifact server\n    path: string;             // where to store the uploaded artifacts\n    port: string;             // where to run the artifact server\n  };\n  mockApi: ResponseMocker[];  // specify the apis you want to mock. ResponseMocker is from mock-github\n  mockSteps: MockStep;        // specify which steps you want to mock\n  logFile?: string;           // write the raw output act produces to this file for debugging purposes\n  verbose?: true;             // enable versbose logging\n}\n```\n\n#### Using job id\n\nYou can execute a job using a job id. Equivalent of running `act -j job_id`.\n\nIt returns an array of `Step` outputs. Described [below](#run-result)\n\n```typescript\nconst act = new Act();\n\nlet result = await act.runJob(\"job_id\");\n\n/**\n * This will pass your secrets to act\n * Equivalent to running: act -j job_id -s secret1=value1 -s secret2=value2\n */\nresult = await act\n  .secret(\"secret1\", \"value1\")\n  .secret(\"secret2\", \"value2\")\n  .runJob(\"job_id\");\n```\n\n#### Using event name\n\nYou can trigger a workflow using an event name. Equivalent of running `act event_name`.\n\nIt returns an array of `Job` outputs. Described [below](#run-result)\n\n```typescript\nconst act = new Act();\n\nlet result = await act.runEvent(\"pull_request\");\n\n/**\n * This will pass your secrets to act\n * Equivalent to running: act pull_request -s secret1=value1 -s secret2=value2\n */\nresult = await act\n  .secret(\"secret1\", \"value1\")\n  .secret(\"secret2\", \"value2\")\n  .runJob(\"pull_request\");\n```\n\n#### Using event name and job id\n\nYou can trigger a workflow using an event name and job id. Equivalent of running `act event_name -j job_id`.\n\nIt returns an array of `Job` outputs. Described [below](#run-result)\n\n```typescript\nconst act = new Act();\n\nlet result = await act.runEventAndJob(\"pull_request\", \"jobId\");\n```\n\n#### Mocking apis during the run\n\nYou can use [Mockapi](#mockapi) and [Moctokit](https://github.com/kiegroup/mock-github#moctokit) to mock any kind of HTTP and HTTPS requests during your workflow run provided that the client being used honors HTTP_PROXY and HTTPS_PROXY env variables. \n\n\u003e [!Note]  \n\u003e `Act` won't be able to mock HTTPS requests if the client sends a CONNECT request to establish a secure TCP tunnel. So depending on the client, `Act` may or may not be able to mock HTTPS requests see [#52](https://github.com/kiegroup/act-js/issues/52)\n\n```typescript\nimport { Moctokit } from \"@kie/mock-github\";\nimport { Mockapi } from \"@kie/act-js\";\nconst moctokit = new Moctokit(\"http://api.github.com\");\nconst mockapi = new Mockapi({\n  customApi: {\n    baseUrl: \"http://custom-api.com\",\n    endpoints: {\n      root: {\n        search: {\n          path: \"/\",\n          method: \"get\",\n          parameters: {\n            query: [],\n            path: [],\n            body: [],\n          },\n        },\n      },\n    },\n  },\n});\nconst act = new Act();\n\nlet result = await act.runEvent(\"pull_request\", {\n  mockApi: [\n    // mock a call to github api to get repo name\n    moctokit.rest.repos\n      .get()\n      .setResponse({ status: 200, data: { full_name: \"kiegroup/act-js\" } }),\n    // mock a call to some custom api\n    mockapi.mock.customApi.root\n      .search()\n      .setResponse({ status: 200, data: { msg: \"found\" } }),\n  ],\n});\n```\n\nFor testing actions which use `Octokit`, you will need to make sure that `Octokit` instance is configured to use proxies. You can do so by using [ProxyAgent](https://github.com/octokit/octokit.js#proxy-servers-nodejs-only) or using the hydrated `Octokit` instance from [@actions/github](https://github.com/actions/toolkit/tree/main/packages/github).\n\nExamples to help you get started:\n- [Using ProxyAgent with Octokit](https://github.com/shubhbapna/mock-github-act-js-examples/tree/main/custom-actions/javascript)\n- [Testing @actions/github-script which uses @actions/github internally](https://github.com/shubhbapna/mock-github-act-js-examples/tree/main/workflow/github-script)\n\n#### Mocking steps\n\nThere are cases where some of the steps have to be skipped or mocked because it is not feasible to execute them in a test env and might even be redundant to test them (npm publish for instance). In such cases, we can use the `mockSteps` option when executing `act`.\n\nLet's suppose this is the workflow to test\n\n```yaml\njobs:\n  publish:\n    runs-on: ubuntu-latest\n    steps:\n      - uses: actions/checkout@v2\n      - uses: actions/setup-node@v3\n        with:\n          node-version: 14\n          registry-url: https://registry.npmjs.org/\n      - run: npm install\n      - run: npm run build\n      - name: publish step\n        run: npm publish --access public\n          env:\n            NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}\n```\n\nNow while testing this, we probably don't want to actually publish a package, so we will use `mockSteps` to change the `npm publish --access public` command to something else. Moreover, say the registry url was behind a vpn and not really accessible locally. We can change this registry url as well using `mockSteps`. In particular, for any step you can replace it with any new step you want. The new step doesn't override the old step completely, it just updates the values that are defined in the new step. To delete a particular field, you will have to set it to `undefined` when passing the new step to `mockSteps`.\n\n```typescript\nconst act = new Act();\nlet result = await act.runJob(\"job_id\", {\n  mockSteps: {\n    // job name\n    publish: [\n      {\n        uses: \"actions/setup-node@v3\",\n        mockWith: {\n          with: {\n            \"registry-url\": \"local-regsitry\"\n          }\n        }\n      },\n      {\n        name: \"publish step\",\n        mockWith: \"echo published\",\n      },\n    ],\n  },\n});\n```\n\nSchema for `mockSteps`\n\n```typescript\n{\n  // name of the job for which you want to mock steps\n  [jobName: string]: (\n    {\n      name: \"locates the step using the name field\"\n      mockWith: \"command or a new step as JSON to replace the given step with\"\n    } |\n    {\n      id: \"locates the step using the id field\"\n      mockWith: \"command or a new step as JSON to replace the given step with\"\n    } |\n    {\n      uses: \"locates the step using the uses field\"\n      mockWith: \"command or a new step as JSON to replace the given step with\"\n    } |\n    {\n      run: \"locates the step using the run field\"\n      mockWith: \"command or a new step as JSON to replace the given step with\"\n    } |\n    {\n      index: \"locates the step using the index (0 indexed) in the steps array of the workflow\"\n      mockWith: \"command or a new step as JSON to replace the given step with\"\n    } |\n    {\n      before: \"index of the step or the id/name/run/uses of the step before which you want to insert a step\"\n      mockWith: \"a new step as JSON to be added before the given step\"\n    } |\n    {\n      after: \"index of the step or the id/name/run/uses of the step after which you want to insert a step\"\n      mockWith: \"a new step as JSON to be added after the given step\"\n    }\n  )[]\n}\n```\n\n**Important Notes**: \n- Please use `MockGithub` to run the workflow in a clean safe github repository so that any changes made to the Workflow file are done in the test environment and not to the actual file.\n\n#### Run result\n\nEach run returns an array of `Step` objects that describes what was executed, what was the output and whether it failed or not. Schema:\n\n```typescript\n[\n  {\n    name: \"the command/step name that was executed\",\n    output: \"output of the command\",\n    // 0 implies it succeeded, 1 implies it failed and -1 implies something went wrong with the interface which should be reported to us\n    status: 0 | 1 | -1,\n    groups?: {name: string, output: string}[] // output grouped by annotations if there were any\n  },\n];\n```\n\n## Mockapi\n\n\u003e [!WARNING]  \n\u003e Mocking of apis is currently not compatible with Node 18's native `fetch` implementation since it uses `nock` under the hood See [nock/nock#2397](https://github.com/nock/nock/issues/2397)\n\nProvides a simple interface to mock any api schema that you define.\n\n### Defining a schema\n\nYou need a define an api schema for this class and it will automatically construct mockers for all the endpoints you define.\n\nYou can directly pass the schema during initialization\n\n```typescript\nconst mockapi = new Mockapi({\n  google: {\n    baseUrl: \"https://google.com\",\n    endpoints: {\n      root: {\n        get: {\n          path: \"/\",\n          method: \"get\",\n          parameters: {\n            path: [],\n            query: [\"logo\"],\n            body: [],\n          },\n        },\n      },\n    },\n  },\n});\n```\n\nOr you can pass a path to a JSON file containing the schema\n\n```typescript\nconst mockapi = new Mockapi(\"/path/to/json\");\n```\n\nSchema Description\n\n```typescript\n{\n  [name_of_api: string]: {\n    baseUrl: \"the the base url for the api\",\n    // different routes for the base url that are available\n    endpoints: {\n      // You can group similar api's together. For example all api's related to repositories can be grouped together\n      [scope: string]: {\n        // name for the actual endpoint\n        [endpoint_name: string]: {\n          // path for the endpoint. You can define path parameters by putting them in between curly braces. Below is an example where \"params\" is a path paramter\n          path: \"/path/to/api/with/{params}/and/more\",\n          method: \"get\" | \"post\" | \"put\" | \"patch\" | \"delete\",\n          paramters: {\n            // any path parameters defined in the path need to be included in this array. Note that the name of paramter must match in the path\n            path: [\"params\"],\n            // you can defined any url queries\n            query: [\"query\"],\n            // you can define any request body fields here\n            body: [\"body\"],\n          }\n        }\n      }\n    }\n  },\n  // you can define multiple APIs like above\n}\n```\n\n### Mock an api\n\nThe api(s) from the schema can simple be mocked as `mock.[api_name].[scope_name].[method_name](parms)`\n\n#### Mock the entire endpoint\n\nYou can mock an entire endpoint by simply passing no arguments.\n\n```typescript\nconst mockapi = new Mockapi({\n  google: {\n    baseUrl: \"https://google.com\",\n    endpoints: {\n      root: {\n        get: {\n          path: \"/{search}\",\n          method: \"get\",\n          parameters: {\n            path: [\"search\"],\n            query: [\"logo\"],\n            body: [],\n          },\n        },\n      },\n    },\n  },\n  {\n    amazon: {\n      baseUrl: \"https://amazon.com\",\n      endpoints: {\n        items: {\n          updateItem: {\n            path: \"/update/{itemId}\",\n            method: \"post\",\n            paramters: {\n              path: [\"itemId\"],\n              query: [],\n              body: [\"name\", \"description\"]\n            }\n          }\n        }\n      }\n    }\n  }\n});\n/**\n * This translates to mocking all possible values of path, query and body paramters\n * mentioned in the schema for \"https://google.com/{search}\"\n */\nmockapi.mock.google.root\n  .get()\n  .reply({ status: 200, data: { message: \"found\" } });\n\n/**\n * This translates to mocking all possible values of path, query and body paramters\n * mentioned in the schema for \"https://amazon.com/update/{itemId}\"\n */\nmockapi.mock.amazon.items\n  .updateItem()\n  .reply({ status: 201, data: { message: \"posted\" } });\n\n// this will throw an error since there was no ibm api defined in the schema\nmockapi.mock.ibm.root.get().reply({status: 201, data: { message: \"posted\" }})\n```\n\n#### Mock an endpoint for specific parameter(s)\n\nYou can mock an endpoint for certain paramters. So only if the call to the api has parameters which match the values you defined, it will be get the mocked response.\n\n```typescript\nconst mockapi = new Mockapi({\n  google: {\n    baseUrl: \"https://google.com\",\n    endpoints: {\n      root: {\n        get: {\n          path: \"/{search}\",\n          method: \"get\",\n          parameters: {\n            path: [\"search\"],\n            query: [\"logo\"],\n            body: [],\n          },\n        },\n      },\n    },\n  },\n  {\n    amazon: {\n      baseUrl: \"https://amazon.com\",\n      endpoints: {\n        items: {\n          updateItem: {\n            path: \"/update/{itemId}\",\n            method: \"post\",\n            paramters: {\n              path: [\"itemId\"],\n              query: [],\n              body: [\"name\", \"description\"]\n            }\n          }\n        }\n      }\n    }\n  }\n});\n/**\n * This translates to mocking \"https://google.com/football?logo='football.png'\" and\n * \"https://google.com/football?logo='football.jpeg'\" only\n */\nmockapi.mock.google.root\n  .get({search: \"football\", logo: /football\\.(png|jpeg)/})\n  .reply({ status: 200, data: { message: \"found\" } });\n\n/**\n * This translates to mocking an api call to \"https://amazon.com/update/20\" with a\n * request body where \"name\" is \"book\" and description starts with \"This is book is\"\n */\nmockapi.mock.amazon.items\n  .updateItem({itemId: 20, name: \"book\", description: /This is book is .+/})\n  .reply({ status: 201, data: { message: \"posted\" } });\n```\n\n### Replying with a response\n\nThe endpoint isn't actually mocked with calling `reply` with response you want send back if your application makes an api call to that particular endpoint.\n\n#### Reply once\n\nYou can reply with a response exactly once i.e. the 1st api call to the mocked endpoint will respond with whatever response you set and the 2nd api call won't be mocked.\n\n```typescript\nconst mockapi = new Mockapi({\n  google: {\n    baseUrl: \"https://google.com\",\n    endpoints: {\n      root: {\n        get: {\n          path: \"/{search}\",\n          method: \"get\",\n          parameters: {\n            path: [\"search\"],\n            query: [\"logo\"],\n            body: [],\n          },\n        },\n      },\n    },\n  },\n});\n\n/**\n * Responds with status 200 and data { message: \"message\" } exactly once\n */\nmockapi.mock.google.root\n  .get()\n  .reply({ status: 200, data: { message: \"message\" } });\n```\n\n#### Reply N times\n\nYou can repeat the same response n times i.e. n consecutive calls to the mocked api will get the same response back\n\n```typescript\nconst mockapi = new Mockapi({\n  google: {\n    baseUrl: \"https://google.com\",\n    endpoints: {\n      root: {\n        get: {\n          path: \"/{search}\",\n          method: \"get\",\n          parameters: {\n            path: [\"search\"],\n            query: [\"logo\"],\n            body: [],\n          },\n        },\n      },\n    },\n  }\n});\n\n/**\n * Responds with status 200 and data { message: \"message\" } for exactly 5 consecutive api calls\n */\nmockapi.mock.google.root\n  .get()\n  .reply({ status: 200, data: { message: \"message\" } }, repeat: 5);\n```\n\n#### Setting response and replying later\n\nYou can set an array of responses but actually mock the api later on. Responses are sent in order of their position in the array. This is extremely useful when using moctokit with [Action Compiler](#action-compiler)\n\n```typescript\nconst mockapi = new Mockapi({\n  google: {\n    baseUrl: \"https://google.com\",\n    endpoints: {\n      root: {\n        get: {\n          path: \"/{search}\",\n          method: \"get\",\n          parameters: {\n            path: [\"search\"],\n            query: [\"logo\"],\n            body: [],\n          },\n        },\n      },\n    },\n  }\n});\n\n/**\n * Add just 1 response to an array of responses but don't actually mock the endpoint\n */\nconst mockedGoogle = mockapi.mock.google.root.get()\n                                             .setResponse({\n                                                status: 200,\n                                                data: {message: \"message\"}, repeat: 5\n                                              });\n\n/**\n * Adds all of these responses after the above response in the array. Again doesn't actually mock the api\n */\nmockedGoogle.setResponse([\n  {status: 201, data: {message: \"something\"}},\n  {status: 400, data: {message: \"something else\"}, repeat: 2}\n  {status: 404, data: {message: \"something completely difference\"}}\n]);\n\n/**\n * Now the api is actually being mocked.\n * For the 1st, 2nd, 3rd, 4th and 5th api call the response status would be 200\n * For the 6th api call the response status would be 201\n * For the 7th and 8th api call the response status would be 400\n * For the 9th api call the response status would be 404\n */\nmockedGoogle.reply();\n```\n\n#### Chaining responses\n\nYou can chain multiple responses together\n\n```typescript\nconst mockapi = new Mockapi({\n  google: {\n    baseUrl: \"https://google.com\",\n    endpoints: {\n      root: {\n        get: {\n          path: \"/{search}\",\n          method: \"get\",\n          parameters: {\n            path: [\"search\"],\n            query: [\"logo\"],\n            body: [],\n          },\n        },\n      },\n    },\n  },\n});\n\n/**\n * For the 1st, 2nd, 3rd, 4th and 5th api call the response status would be 200\n * For the 6th api call the response status would be 201\n * For the 7th and 8th api call the response status would be 400\n * For the 9th api call the response status would be 404\n */\nmockapi.mock.google.root\n  .get()\n  .reply({\n    status: 200,\n    data: { owner_url: \"whatever url\" },\n    repeat: 5,\n  })\n  .setResponse([\n    { status: 201, data: { owner_url: \"something\" } },\n    { status: 400, data: { owner_url: \"something else\" }, repeat: 2 },\n  ])\n  .reply()\n  .reply({\n    status: 404,\n    data: { owner_url: \"something completely difference\" },\n  });\n```\n\n### Typescript Support\n\nSince the endpoint mockers are generated dynamically based on the api schema, typescript won't be able to enfource datatype checks like it does for [Moctokit](https://github.com/kiegroup/mock-github#moctokit)\n\n## Example with Mock Github\n\nYou can use this library along with [mock-github](https://github.com/kiegroup/mock-github) to test your workflow files as well as your custom actions.\nHere are some [examples](https://github.com/shubhbapna/mock-github-act-js-examples) on how to do so.\n\nYou can also take look at the following:\n - Testing workflow files in this repository - [ci-check.yaml](.github/workflows/ci-checks.yaml)\n - End to end tests for a custom github action - [build-chain](https://github.com/kiegroup/github-action-build-chain/tree/main/test/e2e)\n\n## Limitations\n\nAny limitations of `nektos/act` apply here as well.\n\n## Version\n\nThe version of `nektos/act` that this library installs corresponds to the most API compatible recent version of `nektos/act`\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkiegroup%2Fact-js","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkiegroup%2Fact-js","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkiegroup%2Fact-js/lists"}