{"id":15553076,"url":"https://github.com/bahmutov/locha","last_synced_at":"2025-07-19T06:37:21.030Z","repository":{"id":66012479,"uuid":"101827105","full_name":"bahmutov/locha","owner":"bahmutov","description":"Loud Mocha (locha) runs specs twice - first time all, second time just the failing ones with extra verbosity","archived":false,"fork":false,"pushed_at":"2017-08-31T14:03:43.000Z","size":39,"stargazers_count":1,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-07-03T21:11:24.040Z","etag":null,"topics":["bdd","mocha","runner","test","testing"],"latest_commit_sha":null,"homepage":null,"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":"2017-08-30T02:12:24.000Z","updated_at":"2017-08-31T04:42:05.000Z","dependencies_parsed_at":"2023-04-16T10:16:35.349Z","dependency_job_id":null,"html_url":"https://github.com/bahmutov/locha","commit_stats":{"total_commits":19,"total_committers":1,"mean_commits":19.0,"dds":0.0,"last_synced_commit":"ee8b448dcad0204d6de2f04d5f4d3fda7477a343"},"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"purl":"pkg:github/bahmutov/locha","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bahmutov%2Flocha","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bahmutov%2Flocha/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bahmutov%2Flocha/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bahmutov%2Flocha/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bahmutov","download_url":"https://codeload.github.com/bahmutov/locha/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bahmutov%2Flocha/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265898329,"owners_count":23845774,"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":["bdd","mocha","runner","test","testing"],"created_at":"2024-10-02T14:23:40.946Z","updated_at":"2025-07-19T06:37:21.010Z","avatar_url":"https://github.com/bahmutov.png","language":"JavaScript","readme":"# locha\n\n\u003e Loud Mocha (locha) runs specs twice - first time runs all tests, \n\u003e then the second time just the failing ones with extra environment variables\n\n[![NPM][npm-icon] ][npm-url]\n\n[![Build status][ci-image] ][ci-url]\n[![semantic-release][semantic-image] ][semantic-url]\n[![js-standard-style][standard-image]][standard-url]\n\n## Demo\n\nFile [demo/failing-spec.js](demo/failing-spec.js) has two specs, one of which is failing.\nThe specs also will produce a lot of log messages if running with `DEBUG=failing ...` flag.\nBy default we do NOT want to see the debug log messages, but we do need these messages to\ndebug a failing test. Usually if CI fails, we would rerun the failing test locally with\n`DEBUG=failing ...`, but why can't CI do this for us automatically? \n\n* Run all tests with minimal verbosity. Most of the tests (if not all!) pass.\n* If any tests failed during the first run, rerun just these failing tests with\n  extra environment variables. For example we can turn on verbose logging.\n\nThe demo below shows `locha` in action. First round has all the tests with just\na few `console.log` statements. Second round of testing is triggered because\ntest \"failing spec B\" fails, and is rerun with `{\"DEBUG\":\"failing\"}` additional\nenvironment variable set, which produces a lot more output.\n\n```text\n$ npm run demo\n\u003e ./bin/locha.js demo/failing-spec.js --env DEBUG:failing\n\n  failing spec\nin \"failing spec A\"\n    ✓ A\nin \"failing spec B\"\n    1) B\n\n  1 passing (14ms)\n  1 failing\n\n  1) failing spec B:\n     Error: B fails\n      at Context.\u003canonymous\u003e (demo/failing-spec.js:22:11)\n\nmocha finished with 1 failure\nFailed first time, rerunning 1 test\n\n  failing spec\nin \"failing spec B\"\n  failing a lot of +0ms\n  failing verbose +1ms\n  failing messages +1ms\n  failing in debug +0ms\n  failing mode in test B +0ms\n    1) B\n\n  0 passing (5ms)\n  1 failing\n\n  1) failing spec B:\n     Error: B fails\n      at Context.\u003canonymous\u003e (demo/failing-spec.js:22:11)\nmocha finished with 1 failure\n```\n\nThe verbose second run makes debugging just the failing tests simple and quick. I picked\nenvironment variables to control verbosity because to me command line switches control\n*what to do*, and environment variables control *how to do it*. Extra logging seems a good\n\"how to do it\" kind of thing.\n\n## Install\n\nRequires [Node](https://nodejs.org/en/) version 6 or above.\n\n```sh\nnpm install --save-dev locha\n```\n\n## Use\n\nPass additional environment variables using `--env` string, and specs as a list of files.\nFor example if we want to set `DEBUG=my-module MODE=test ...` during the second run with\njust failing tests, the test command would be\n\n```json\n{\n    \"scripts\": {\n        \"test\": \"locha --env 'DEBUG:my-module,MODE:test' test/*-spec.js\"\n    },\n    \"devDependencies\": {\n        \"locha\": \"1.0.0\"\n    }\n}\n```\n\n## Debugging\n\nTo see verbose log messages, run with `DEBUG=locha` environment variable\n\n## Examples\n\n* [CoffeeScript tests](coffee-example)\n* [recursive tests](recursive-example)\n* [custom reporters](reporter-example)\n\n## Mocha options\n\nMocha supports a [LOT of command line options](https://github.com/mochajs/mocha/blob/master/bin/_mocha#L62).\nLocha only supports some of them. Here they are\n\n```\n-t, --timeout \u003cms\u003e\n-r, --require \u003cmodule name\u003e\n-R, --reporter \u003creporter name\u003e\n-O, --reporter-options \u003ck=v,k2=v2,...\u003e\n--compilers \u003cext1\u003e:\u003cmodule name1\u003e,\u003cext2\u003e:\u003cmodule name2\u003e\n--opts \u003cfilename\u003e\n--recursive\n```\n\n## Related projects\n\n* [focha](https://github.com/bahmutov/focha) - Mocha \n    wrapper that runs previously failed tests first\n* [rocha](https://github.com/bahmutov/rocha) - Runs Mocha unit tests but randomizes their order\n* [snap-shot-it](https://github.com/bahmutov/snap-shot-it) - Smarter snapshot utility for \n    Mocha and BDD test runners\n\n### Small print\n\nAuthor: Gleb Bahmutov \u0026lt;gleb.bahmutov@gmail.com\u0026gt; \u0026copy; 2017\n\n* [@bahmutov](https://twitter.com/bahmutov)\n* [glebbahmutov.com](https://glebbahmutov.com)\n* [blog](https://glebbahmutov.com/blog)\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/locha/issues) on Github\n\n## MIT License\n\nCopyright (c) 2017 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\n[npm-icon]: https://nodei.co/npm/locha.svg?downloads=true\n[npm-url]: https://npmjs.org/package/locha\n[ci-image]: https://travis-ci.org/bahmutov/locha.svg?branch=master\n[ci-url]: https://travis-ci.org/bahmutov/locha\n[semantic-image]: https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg\n[semantic-url]: https://github.com/semantic-release/semantic-release\n[standard-image]: https://img.shields.io/badge/code%20style-standard-brightgreen.svg\n[standard-url]: http://standardjs.com/\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbahmutov%2Flocha","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbahmutov%2Flocha","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbahmutov%2Flocha/lists"}