{"id":20452861,"url":"https://github.com/axtk/doctest","last_synced_at":"2026-04-20T14:33:44.755Z","repository":{"id":110829528,"uuid":"287656994","full_name":"axtk/doctest","owner":"axtk","description":"Inline unit testing of JS code","archived":false,"fork":false,"pushed_at":"2020-11-06T02:27:36.000Z","size":24,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-05T09:45:52.553Z","etag":null,"topics":[],"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/axtk.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":"2020-08-15T01:36:08.000Z","updated_at":"2020-11-06T00:54:57.000Z","dependencies_parsed_at":null,"dependency_job_id":"6e90020f-de8f-4790-8d48-3912d76826bd","html_url":"https://github.com/axtk/doctest","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/axtk%2Fdoctest","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/axtk%2Fdoctest/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/axtk%2Fdoctest/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/axtk%2Fdoctest/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/axtk","download_url":"https://codeload.github.com/axtk/doctest/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":242005730,"owners_count":20056431,"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":[],"created_at":"2024-11-15T11:10:37.718Z","updated_at":"2026-04-20T14:33:39.713Z","avatar_url":"https://github.com/axtk.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# doctest\n\n*Inline unit testing of JS code*\n\nThis approach is inspired by the Python *[doctest](https://docs.python.org/3/library/doctest.html)* library enabling the developer to run small unit tests from a docstring comment next to the code, which is a quick and handy way to do unit testing.\n\nDoctests are easy to read, they can work as human-readable examples giving insights to the module's use cases and can be regarded as an extension to the module's documentation (such as *[JSDoc](https://jsdoc.app/)*).\n\nThey are also easy to write, and in the process of development, they can be immediately spotted without the need to look through other files and folders. And if you remove a module file, the doctests are immediately removed as well.\n\nDoctests are also a shorter path to [test-driven development](https://en.wikipedia.org/wiki/Test-driven_development).\n\n## Example\n\n```js\nimport ComplexNumber from './ComplexNumber';\n\n// @test expect(abs(new ComplexNumber(-3, 4))).toEqual(5);\n// @test expect(abs(new ComplexNumber(1, -1))).toEqual(Math.sqrt(2));\n\n// @test Absolute value of imaginary unit is 1\n// import IM_1 from './IM_1';\n// expect(abs(IM_1)).toEqual(1);\n\nexport default function abs(z) {\n    if (!(z instanceof ComplexNumber))\n        throw new Error('Invalid argument: should be a ComplexNumber');\n    return Math.sqrt(z.re*z.re + z.im*z.im);\n}\n```\n\n\\+ [Unit testing of class methods](https://github.com/axtk/complex/blob/master/src/ComplexNumber.js)\n\n## Usage\n\n*(With [jest](https://jestjs.io/) as an example)*\n\n```\n$ npx doctest build ./src/**/*.js\n$ npx jest\n$ npx doctest cleanup\n```\n\nor in a one-liner suitable for a `package.json` script:\n\n```\n\"test\": \"npx doctest build ./src/**/*.js \u0026\u0026 npx jest \u0026\u0026 npx doctest cleanup\",\n```\n\n## Under the hood\n\n*Doctest* generates temporary test files based on the content of the comments in the code and cleans up these files, once a test run is over. This is represented by the commands `npx doctest build` and `npx doctest cleanup`. The list of test files generated in the build phase is stored in the temporary `.doctestdump` file which can be used during the test phase.\n\nFor the sake of separation of concerns, the job of running the generated tests is entrusted to a dedicated unit testing utility (such as *jest* in the setting above) which is not part of this package. The choice of the testing utility is up to the developer's preference.\n\n## Options\n\nThe *doctest* output format can be customized via an optional `doctest.config.js` file (which should resemble the default [`doctest.config.js`](doctest.config.js)). The config will be picked either from the application root or from the location specified in the optional `-c \u003cconfig_path\u003e` command line argument.\n\n## Installation\n\n```\n$ npm i -D github:axtk/doctest\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faxtk%2Fdoctest","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Faxtk%2Fdoctest","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faxtk%2Fdoctest/lists"}