{"id":15552236,"url":"https://github.com/bahmutov/grep-tests-from-pull-requests","last_synced_at":"2025-09-28T20:31:09.806Z","repository":{"id":39801974,"uuid":"450182197","full_name":"bahmutov/grep-tests-from-pull-requests","owner":"bahmutov","description":"Grabs the test tags to run from the pull request text","archived":false,"fork":false,"pushed_at":"2024-10-21T21:00:52.000Z","size":251,"stargazers_count":7,"open_issues_count":2,"forks_count":2,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-12-27T20:27:53.455Z","etag":null,"topics":["cypress-plugin"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bahmutov.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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,"publiccode":null,"codemeta":null}},"created_at":"2022-01-20T16:54:33.000Z","updated_at":"2024-10-21T20:59:34.000Z","dependencies_parsed_at":"2024-06-24T17:35:51.009Z","dependency_job_id":"228bbb1d-d40f-4c9c-814b-6fbedc73b8bf","html_url":"https://github.com/bahmutov/grep-tests-from-pull-requests","commit_stats":{"total_commits":29,"total_committers":2,"mean_commits":14.5,"dds":0.03448275862068961,"last_synced_commit":"9d6b2c81df689740a2f7a931fcb22e3e8bca0c00"},"previous_names":[],"tags_count":25,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bahmutov%2Fgrep-tests-from-pull-requests","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bahmutov%2Fgrep-tests-from-pull-requests/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bahmutov%2Fgrep-tests-from-pull-requests/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bahmutov%2Fgrep-tests-from-pull-requests/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bahmutov","download_url":"https://codeload.github.com/bahmutov/grep-tests-from-pull-requests/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":234558807,"owners_count":18852283,"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":["cypress-plugin"],"created_at":"2024-10-02T14:13:12.480Z","updated_at":"2025-09-28T20:31:09.800Z","avatar_url":"https://github.com/bahmutov.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# grep-tests-from-pull-requests\n\n\u003e Grabs the test tags to run from the pull request text\n\nRead the blog post [Pick Tests To Run Using The Pull Request Text](https://glebbahmutov.com/blog/pick-tests-using-pull-request/).\n\n## Install\n\n```shell\n# add this plugin as a dev dependency using NPM\n$ npm i -D grep-tests-from-pull-requests\n# or using Yarn\n$ yarn add -D grep-tests-from-pull-requests\n```\n\nRegister the plugin in your plugins file _before_ [cypress-grep](https://github.com/cypress-io/cypress-grep) registration.\n\n```js\n// cypress/plugins/index.js\nconst pickTestsFromPullRequest = require('grep-tests-from-pull-requests')\nmodule.exports = async (on, config) =\u003e {\n  // include this plugin before cypress-grep\n  // so if we find the test tags in the pull request body\n  // we can grep for them by setting the grep config\n  const pullOptions = {\n    // try to find checkbox lines in the pull request body with these tags\n    tags: ['@log', '@sanity', '@user'],\n    // repo with the pull request text to read\n    owner: 'bahmutov',\n    repo: 'todomvc-no-tests-vercel',\n    // to get a private repo above, you might need a personal token\n    token: process.env.PERSONAL_GH_TOKEN || process.env.GITHUB_TOKEN,\n  }\n  await pickTestsFromPullRequest(on, config, pullOptions)\n\n  // cypress-grep plugin registration\n\n  // IMPORTANT: the config.env object might be modified\n  // by the above plugins, thus return the config object from this function\n  return config\n}\n```\n\n**Important:** notice the plugin registration is an async function, thus you must await the registration. This makes your plugin file function `async`. Make sure to return the `config` object, as it might be changed by this plugin.\n\n**Tip:** you can find the test tags, but skip using them using an option\n\n```js\nconst pickTestsFromPullRequest = require('grep-tests-from-pull-requests')\nconst pullOptions = {\n  ...,\n  setTests: true // default, use false to disable setting the test tags\n}\nawait pickTestsFromPullRequest(on, config, pullOptions)\n```\n\n## baseUrl\n\nIf the pull request text OR its comments have a line with just `baseUrl \u003cURL\u003e` the it will be extracted too. This makes it convenient to specify a custom deploy to be tested for this specific pull request.\n\n```text\n// pull request text\nsome test tags\n\nThese tests should be run against this URL\nbaseUrl https://preview-1.acme.co\n```\n\nThe base URL is found if it is a single line of text in the pull request body or its comment in one of these formats:\n\n```text\nbaseUrl https://preview-1.acme.co\nTestURL: https://preview-1.acme.co\n```\n\nIf the URL is present in the body and in several comments, the URL found in the latest comment wins.\n\n**Tip:** you can control if you want to set the baseUrl based on the pull request text using an option\n\n```js\nconst pickTestsFromPullRequest = require('grep-tests-from-pull-requests')\nconst pullOptions = {\n  ...,\n  setBaseUrl: true // default, use false to disable setting the baseUrl\n}\nawait pickTestsFromPullRequest(on, config, pullOptions)\n```\n\n## additionalSpecs\n\nSometimes you want to be explicit and run some specs by name or wildcard. Simply add a list of such specs:\n\n    Run these Cypress specs too:\n\n    - `cypress/e2e/spec-b.cy.js`\n    - cypress/e2e/**/*.cy.js\n\nThe entire list will be returned in the property `additionalSpecs`. Back ticks will be removed.\n\n## pagesToTest\n\nYou can pass parts of URLs that the tests should visit if you are using [cypress-visited-urls](https://github.com/bahmutov/cypress-visited-urls) plugin. List the URLs as a list after:\n\n    Find specs that visit these pages:\n\n    - /homepage/u1234\n    - /checkout/step\n\nThen your project can use `cypress-visited-urls` plugin to check which specs visit the list of these URLs\n\n## Resolved value\n\nThe function might resolve with an object if the pull request was found. You can check if the user wants to run all the tests, or a list of tags\n\n```js\nconst pickTestsFromPullRequest = require('grep-tests-from-pull-requests')\nconst testsToRun = await pickTestsFromPullRequest(...)\nif (testsToRun) {\n  if (testsToRun.baseUrl) {\n    console.log('testing deploy at %s', testsToRun.baseUrl)\n  }\n  if (testsToRun.all) {\n    console.log('running all tests')\n  } else if (testsToRun.tags.length) {\n    console.log('the user picked %s tags to run', testsToRun.tags.join(', '))\n  } else {\n    console.log('the user did not pick any tests to run')\n  }\n}\n```\n\n## Additional environment variables\n\nIf the pull request has lines that start with `CYPRESS_...=value` then they are automatically are parsed and cast and added to the `Cypress.env` object. For example\n\n```\nCYPRESS_num=1\nCYPRESS_correct=true\nCYPRESS_FRIENDLY_GREETING=Hello\n```\n\nWill add the values `{num: 1, correct: true, FRIENDLY_GREETING: \"Hello\"}` to the `Cypress.env`.\n\nIf the string value is a valid JSON, it is automatically parsed\n\n```\nCYPRESS_person={\"name\":\"Joe\"}\n// produces Cypress.env('person') object { name: 'Joe' }\n```\n\n**Note:** an empty value is converted to `undefined`. The `undefined` value will NOT replace any existing config `env` values.\n\n```\n# pull request text\nCYPRESS_age=\n# will produce\n{ age: undefined }\n# you are running with command \"CYPRESS_age=42 npx cypress run ...`\n# the final config env object will have \"age: 42\"\n```\n\nIf you really want to skip a value, prefix it somehow, like `xCYPRESS_...=value` or set it to `null` like this `CYPRESS_age=null`\n\n## Skip / enable Cypress tests\n\nYou can find a checkbox in the pull request text to skip / run Cypress tests. This makes it simple to skip the E2E testing steps temporarily. Include the following checkbox line in the pull request body.\n\n```\n- [x] run Cypress tests\n```\n\n## Aliases\n\nThis package includes several scripts that let you find the pull request body and the test tags and the base URL of a given pull request.\n\n### get-pr-body\n\nPrints the test tags found in the pull request text\n\n```\n$ npx get-pr-body --owner bahmutov --repo todomvc-no-tests-vercel --pull 12\n```\n\n### get-pr-comments\n\nPrints all pull request comments\n\n```\n$ npx get-pr-comments --owner bahmutov --repo todomvc-no-tests-vercel --pull 12\n```\n\n### get-pr-tests\n\nPrints all test tags found in the pull request\n\n```\n$ npx get-pr-tests --owner bahmutov --repo todomvc-no-tests-vercel --pull 12\n```\n\nYou can pass the list of allowed tags\n\n```\n$ npx get-pr-tests --owner bahmutov --repo todomvc-no-tests-vercel --pull 12 \\\n  --tags one,two,three\n```\n\n### should-pr-run-cypress-tests\n\nTells if the pull request body has a checkbox to run or skip the Cypress tests. If the tests should run, this script exits with code 0. If the PR disables the Cypress tests, it exits with code 1.\n\n```\n$ npx should-pr-run-cypress-tests --owner bahmutov --repo todomvc-no-tests-vercel --pull 12\n$ echo $?\n# 0 - we need to run the Cypress tests\n```\n\n**Tip:** you can pass the full GitHub pull request URL instead of passing the individual command line arguments\n\n```\n$ npx should-pr-run-cypress-tests --owner bahmutov --repo todomvc-no-tests-vercel --pull 15\n# is the same as\n$ npx should-pr-run-cypress-tests --pr-url https://github.com/bahmutov/todomvc-tests-circleci/pull/15\n```\n\n## Open vs all pull requests\n\nBy default this library gets the pull request that is `open`. If you want to fetch the info from a closed pull request, use an option `all`. For example, the bin scripts accept `--all` argument to fetch all pull requests when searching for specific one.\n\n## Debugging\n\nThis plugin uses [debug](https://github.com/debug-js/debug#readme) module to output verbose log messages. Run with environment variable `DEBUG=grep-tests-from-pull-requests` to see those logs.\n\n## Small print\n\nAuthor: Gleb Bahmutov \u0026copy; 2022\n\n- [@bahmutov](https://twitter.com/bahmutov)\n- [glebbahmutov.com](https://glebbahmutov.com)\n- [blog](https://glebbahmutov.com/blog/)\n- [videos](https://www.youtube.com/glebbahmutov)\n- [presentations](https://slides.com/bahmutov)\n- [cypress.tips](https://cypress.tips)\n\nLicense: MIT - do anything with the code, but don't blame me if it does not work.\n\nSupport: if you find any problems with this module, email / tweet /\n[open issue](https://github.com/bahmutov/grep-tests-from-pull-requests/issues) on Github\n\n## MIT License\n\nCopyright (c) 2022 Gleb Bahmutov \u0026lt;gleb.bahmutov@gmail.com\u0026gt;\n\nPermission is hereby granted, free of charge, to any person\nobtaining a copy of this software and associated documentation\nfiles (the \"Software\"), to deal in the Software without\nrestriction, including without limitation the rights to use,\ncopy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the\nSoftware is furnished to do so, subject to the following\nconditions:\n\nThe above copyright notice and this permission notice shall be\nincluded in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND,\nEXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES\nOF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND\nNONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT\nHOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,\nWHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING\nFROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR\nOTHER DEALINGS IN THE SOFTWARE.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbahmutov%2Fgrep-tests-from-pull-requests","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbahmutov%2Fgrep-tests-from-pull-requests","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbahmutov%2Fgrep-tests-from-pull-requests/lists"}