{"id":15287818,"url":"https://github.com/alsiola/test-ids","last_synced_at":"2026-02-18T03:01:40.698Z","repository":{"id":35983270,"uuid":"220313729","full_name":"alsiola/test-ids","owner":"alsiola","description":"Babel plugin to provide extractable test ids with zero runtime cost.","archived":false,"fork":false,"pushed_at":"2023-01-05T00:43:11.000Z","size":894,"stargazers_count":2,"open_issues_count":17,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-10-21T21:38:59.181Z","etag":null,"topics":["babel","testing"],"latest_commit_sha":null,"homepage":"","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/alsiola.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":"2019-11-07T19:30:10.000Z","updated_at":"2023-11-16T14:54:13.000Z","dependencies_parsed_at":"2023-01-16T10:45:25.630Z","dependency_job_id":null,"html_url":"https://github.com/alsiola/test-ids","commit_stats":null,"previous_names":["alsiola/jsx-test-ids"],"tags_count":6,"template":false,"template_full_name":null,"purl":"pkg:github/alsiola/test-ids","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alsiola%2Ftest-ids","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alsiola%2Ftest-ids/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alsiola%2Ftest-ids/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alsiola%2Ftest-ids/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/alsiola","download_url":"https://codeload.github.com/alsiola/test-ids/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alsiola%2Ftest-ids/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29566643,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-18T00:47:08.760Z","status":"online","status_checked_at":"2026-02-18T02:00:09.468Z","response_time":162,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["babel","testing"],"created_at":"2024-09-30T15:38:05.335Z","updated_at":"2026-02-18T03:01:40.680Z","avatar_url":"https://github.com/alsiola.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# babel-plugin-test-ids\n\n[![CircleCI](https://img.shields.io/circleci/build/github/alsiola/test-ids/master?style=for-the-badge)](https://circleci.com/gh/alsiola/test-ids/tree/master)\n![Test Coverage](https://img.shields.io/codecov/c/github/alsiola/test-ids?style=for-the-badge)\n\n![MIT Licensed](https://img.shields.io/npm/l/babel-plugin-test-ids?style=for-the-badge)\n![Language](https://img.shields.io/github/languages/top/alsiola/test-ids?style=for-the-badge)\n\n[![NPM](https://img.shields.io/npm/v/babel-plugin-test-ids?style=for-the-badge)](https://www.npmjs.com/package/babel-plugin-test-ids)\n![Dependencies](https://img.shields.io/requires/github/alsiola/test-ids?label=dependencies\u0026style=for-the-badge)\n\n![Issues](https://img.shields.io/github/issues/alsiola/test-ids?style=for-the-badge)\n![Pull Requests](https://img.shields.io/github/issues-pr/alsiola/test-ids?style=for-the-badge)\n\nDefine test ids with zero runtime cost, and extract them to a JSON file.\n\n## Install\n\nInstall the package using:\n\n```\nyarn install babel-plugin-test-ids\n```\n\nYou'll need [babel](https://babeljs.io/) `\u003e7.0.0` installed.\n\n## Usage\n\nThere are two parts to this package:\n\n* A babel plugin\n    - Transforms code to replace \"magic\" test ids with string literals\n    - Extracts found test ids to JSON files\n* CLI program\n    - Combines extracted test ids into a single file\n\n### Babel plugin\n#### Setup\n\nThe plugin should be added to the `plugins` array in your babel configuration.\n\n```\nmodule.exports = {\n    plugins: [\n        \"test-ids\"\n    ]\n};\n```\n\nThere are two available configuration options, both optional.\n\n* `extractTo`\n    - String, optional, default `undefined`\n    - Folder location to write extracted test ids\n    - Relative to current working directory\n    - If not defined, no files will be written\n* `magicObject`\n    - String, optional, default `$TestId`\n    - Name of the \"magic object\" to look for (see below)\n\n#### Using the magic object\n\nThe `$TestId` magic object can now be used in your code. It can be used in plain JavaScript files, or (subject to appropriate plugins),\nJSX.  Property access will be transformed by the plugin into a string literal containing the name of the value identifier. The value\nof the injected string literal will then be extracted to a JSON file, in a tree structure matching the original file.\n\nInput (`src/test/file.js`)\n```\nconst foo = {\n    bar: $TestId.MyTestId\n}\n```\n\nTransformed (`src/test/file.js`)\n```\nconst foo = {\n    bar: \"MyTestId\"\n}\n```\n\nExtracted (`test-ids/src/test/file.json`)\n```\n[\n    \"MyTestId\"\n]\n```\n\n#### TypeScript\nIf you're using TypeScript, you'll soon find that usage as above causes build errors, because `$TestId` is\nnot defined. This can be corrected by declaring a global variable, in (for example) `globals.d.ts` at the project\nroot.\n\n```\ndeclare const $TestId: Record\u003cstring, string\u003e;\n```\n\n### CLI\n\nOften it is desirable to have a single \"master\" file of test ids. This can be generated using the provided `glob-test-ids` program.\n\nThere are two inputs, both required:\n\n* `-i, --ids-location` Glob-style location of previously generated extracted test ids\n* `-o, --output` Location to output master file\n\npackage.json\n```\n{\n    \"scripts\": {\n        \"glob\": \"glob-test-ids -i ./test-ids/src/**/*.json -o ./test-ids/master.json\"\n    }\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falsiola%2Ftest-ids","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falsiola%2Ftest-ids","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falsiola%2Ftest-ids/lists"}