{"id":16284115,"url":"https://github.com/microsoftpremier/js-testcat","last_synced_at":"2026-01-21T15:32:52.827Z","repository":{"id":32472587,"uuid":"134684409","full_name":"MicrosoftPremier/js-testcat","owner":"MicrosoftPremier","description":"Repo for the JavaScript Test Categories npm package","archived":false,"fork":false,"pushed_at":"2022-12-30T18:31:01.000Z","size":638,"stargazers_count":1,"open_issues_count":2,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-07T21:20:02.951Z","etag":null,"topics":["jasmine","mocha","test","testing"],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/MicrosoftPremier.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-05-24T08:21:34.000Z","updated_at":"2022-01-19T15:28:27.000Z","dependencies_parsed_at":"2023-01-14T21:20:02.989Z","dependency_job_id":null,"html_url":"https://github.com/MicrosoftPremier/js-testcat","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MicrosoftPremier%2Fjs-testcat","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MicrosoftPremier%2Fjs-testcat/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MicrosoftPremier%2Fjs-testcat/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MicrosoftPremier%2Fjs-testcat/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/MicrosoftPremier","download_url":"https://codeload.github.com/MicrosoftPremier/js-testcat/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247730062,"owners_count":20986404,"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":["jasmine","mocha","test","testing"],"created_at":"2024-10-10T19:18:22.951Z","updated_at":"2026-01-21T15:32:52.796Z","avatar_url":"https://github.com/MicrosoftPremier.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# JavaScript Test Categories\nAdd test categories to mocha (BDD style) and jasmine tests.\n\n![Build Badge](https://almtcger.visualstudio.com/_apis/public/build/definitions/2ff986e4-4f8b-4ae1-8b86-d111d5fc7294/119/badge)\n[![npm](https://img.shields.io/npm/v/js-testcat.svg?style=flat\u0026maxAge=3600)](https://www.npmjs.com/package/js-testcat)\n[![License](https://img.shields.io/badge/license-MIT-blue.svg?style=flat\u0026maxAge=3600)](https://opensource.org/licenses/MIT)\n\n## Get started\n\n### Install the library\nInstall the library to your project (usually as a dev dependency).\n\n```\nnpm install js-testcat --save-dev\n```\n\n### Use the library\nTo use the library simply import or require it, then use cdescribe or cit instead of describe or it:\n\n#### TypeScript sample\n```typescript\nimport { cdescribe, cit } from 'js-testcat';\n\n// A regular mocha/jasmine test suite/spec\ndescribe('Some Spec', () =\u003e {\n    \n    // A suite/spec with a single test category\n    cdescribe('Spec with test category', 'MyCategory', () =\u003e {\n        \n        it('Test case', () =\u003e {\n            // .. test code\n        });\n\n    });\n\n    // A test case with multiple test categories.\n    cit('Test case with test categories', ['SomeCategory', 'SomeOtherCategory'], () =\u003e {\n\n    });\n\n});\n```\nYou can find more samples in the [js-testcat-samples](https://github.com/MicrosoftPremier/js-testcat-samples) repo.\n\nThe cdescribe specs/suites and cit test cases are executed depending on the test categories you pass to the test run:\n\n- **Neither includes nor excludes**  \n  Js-testcat will execute all test suites/specs and test cases as if you had used describe and it instead of cdescribe and cit.\n- **Includes only**  \n  When you provide only test category includes to the test run, js-testcat only executes test cases and suites/specs that are associated with at least one of the included categories.\n- **Excludes only**  \n  When passing only test category excludes to the test run, js-testcat executes all suites/specs and test cases that are not associated with any of the excluded categories.\n- **Includes and excludes**  \n  If you pass both included and excluded test categories to the test run, js-testcat only executes test suites/specs and test cases that are associated with at least one of the included, but not associated with any of the excluded categories.\n\n**Note:** Test category comparison is done case-sensitive!\n\n## APIs\nJs-testcat uses the following APIs to let you define and configure test categories:\n\n#### cdescribe(description, categories, callback)\nUse the _cdescribe_ function instead of mocha's or jasmine's _describe_ function to create a test suite/spec that is associated with one or more test categories. In addition to the regular _description_ and _callback_ parameters, js-testcat adds the parameter _categories_ that takes either a single category (string) or a list of categories (string[]) and associates the suite/spec with the given test categories.\n\n#### cit(description, categories, callback)\nUse the _cit_ function instead of mocha's or jasmine's _it_ function to create a test case that is associated with one or more test categories. In addition to the regular _description_ and _callback_ parameters, js-testcat adds the parameter _categories_ that takes either a single category (string) or a list of categories (string[]) and associates the suite/spec with the given test categories.\n\n#### addTestcatFile(file) / removeTestcatFile(file)\nThe _addTestcatFile_ and _removeTestcatFile_ functions provide a way of adding or removing test category includes and excludes from a js-testcat file (see below) directly in your test code. Both methods throw an error if the file does not exist.\n\n#### addIncludes(includes) / removeIncludes(includes) / removeAllIncludes()\nThe _addIncludes_, _removeIncludes_, and _removeAllIncludes_ functions provide a way of adding or removing test category includes directly in your test code. Similar to the _categories_ parameter of the _cdescribe_ and _cit_ functions, you may either pass a single include (string) or a list of includes (string[]);\n\n#### getIncludes() / getExcludes()\nIf you want to access the currently included or excluded test categories, you can use the _getIncludes_ and _getExcludes_ functions both of which return a string[].\n\n#### addExcludes(excludes) / removeExcludes(excludes) / removeAllExcludes()\nThe _addExcludes_, _removeExcludes_, and _removeAllExcludes_ functions provide a way of adding or removing test category excludes directly in your test code. Similar to the _categories_ parameter of the _cdescribe_ and _cit_ functions, you may either pass a single exclude (string) or a list of excludes (string[]);\n\n#### reset()\nResets js-testcat to its uninitialized state. This forces js-testcat to re-initialize test categories from environment variables.\n\n## Environment variables\nSince neither mocha nor jasmine provide an easy way of passing arbitrary parameters to the test execution, js-testcat uses the following environment variables to configure included and excluded test categories. \n\n#### JSTESTCAT_INCLUDE / JSTESTCAT_EXCLUDE\nSet _JSTESTCAT_INCLUDE_ to a comma-separated list of category names to include them in the test execution and set _JSTESTCAT_EXCLUDE_ to a comma-separated list of category names to exclude them from the test execution.\n\n#### JSTESTCAT_FILE\nSet _JSTESTCAT_FILE_ to the path to a js-testcat file that contains the test categories you want to include and exclude.\n\n## Js-testcat file format\nThe easiest way to quickly switch between different sets of test categories is to use js-testcat files. A js-testcat file is a simple JSON file containing included and excluded test categories. The below sample file configures js-testcat to run all unit and integration tests but not UI tests. \n\n#### Js-testcat file sample\n```json\n{\n    \"includes\": [\n        \"Unit\",\n        \"Integration\"\n    ],\n    \"excludes\": [\n        \"UI\"\n    ]\n}\n```\n\n## Building and testing js-testcat\nMake sure to have gulp (`npm install -g gulp`) and typescript (`npm install -g typescript`) globally installed, then clone the repo and run `npm install`.\n\nOnce all packages have been restored, run `npm test` to build and test js-testcat or simply run `tsc` to just transpile the code to JavaScript. With the included _launch.json_ you can also easily debug the tests using Visual Studio Code.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmicrosoftpremier%2Fjs-testcat","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmicrosoftpremier%2Fjs-testcat","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmicrosoftpremier%2Fjs-testcat/lists"}