{"id":13492585,"url":"https://github.com/kiwicopple/doctest-js","last_synced_at":"2025-04-14T16:24:35.901Z","repository":{"id":40289989,"uuid":"236905403","full_name":"kiwicopple/doctest-js","owner":"kiwicopple","description":"Run JSDoc style doc examples as tests within your test suite","archived":false,"fork":false,"pushed_at":"2022-12-10T19:13:00.000Z","size":1769,"stargazers_count":101,"open_issues_count":26,"forks_count":4,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-03-28T05:11:10.097Z","etag":null,"topics":["hacktoberfest"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","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/kiwicopple.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null},"funding":{"github":["supabase"],"patreon":null,"open_collective":null,"ko_fi":null,"tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"otechie":null,"custom":null}},"created_at":"2020-01-29T04:51:25.000Z","updated_at":"2024-11-10T14:52:06.000Z","dependencies_parsed_at":"2023-01-26T10:31:18.015Z","dependency_job_id":null,"html_url":"https://github.com/kiwicopple/doctest-js","commit_stats":null,"previous_names":["supabase/doctest-js"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kiwicopple%2Fdoctest-js","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kiwicopple%2Fdoctest-js/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kiwicopple%2Fdoctest-js/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kiwicopple%2Fdoctest-js/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kiwicopple","download_url":"https://codeload.github.com/kiwicopple/doctest-js/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248915054,"owners_count":21182556,"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":["hacktoberfest"],"created_at":"2024-07-31T19:01:07.295Z","updated_at":"2025-04-14T16:24:35.870Z","avatar_url":"https://github.com/kiwicopple.png","language":"JavaScript","funding_links":["https://github.com/sponsors/supabase"],"categories":["JavaScript"],"sub_categories":[],"readme":"# doctest-js\n\nLet your documentation be your testing suite. \n\nWrite [JSDoc](http://usejsdoc.org/about-getting-started.html) style doc examples on all your functions and then test them using `doctest-js`.\n\n**Contents**\n\n- [Getting Started](#getting-started)\n  - [1. Install](#1-install)\n  - [2. Write @example comments](#2-write-example-comments)\n  - [3. Run the tests](#3-run-the-tests)\n- [Advanced](#advanced)\n  - [Multiple tests](#multiple-tests)\n  - [Testing classes](#testing-classes)\n- [Usage online](#usage-online)\n- [Contributing](#contributing)\n- [Credits](#credits)\n- [Status](#status)\n\n## Getting Started\n\n### 1. Install\n\n```sh\nnpm install @supabase/doctest-js\n```\n\n### 2. Write @example comments\n\nCreate a [JSDoc style @example](https://jsdoc.app/tags-example.html) on any functions that you want tested. \n\n```javascript\n/**\n * Returns the sum of 2 numbers\n *\n * @example sum(1, 2)\n * //=\u003e 3\n */\nexport const sum = (a, b) =\u003e {\n  return a + b\n}\n```\n\nNote that the expected return value must be prefixed by `//=\u003e`.\n\n### 3. Run the tests\n\nImport the doctest function in your test suite and point it at the file.\n\n```javascript\nimport doctest from '@supabase/doctest-js';\n\ndescribe('Doctests', () =\u003e {\n  // file paths are relative to root of directory\n  doctest('src/sum.js')\n  doctest('src/someOtherFile.js')\n})\n```\n\n## Advanced\n\n### Multiple tests\n\nYou can run multiple tests for the same function.\n\n```javascript\n/**\n * @example sum(1, 2)\n * //=\u003e 3\n * @example sum(3, 4)\n * //=\u003e 7\n */\nexport const sum = (a, b) =\u003e {\n  return a + b\n}\n```\n\n### Testing classes\n\nTesting classes requires you to pass a newed up instance of the class into the test itself. Here is a simple example:\n\n```js\n// Arithmetic.js - a basic class which we need to test\n\nclass Arithmetic {\n  constructor() {}\n\n  /**\n   * @example add(1, 2)\n   * //=\u003e 3\n   */\n  add(a, b) {\n    return a + b\n  }\n}\n\nexport { Arithmetic }\n```\n\n```js\n// Arithmetic.test.js\n\nconst { Arithmetic } = require('./Arithmetic.js')\n\ndescribe('passing doctest', () =\u003e {\n  doctest('./Arithmetic.js', { instance: new Arithmetic() })\n})\n```\n\n## Usage online \n\nSee this in the wild:\n\n- [supabase/postgrest-js](https://github.com/supabase/postgrest-js/blob/master/test/unit/Doctests.test.js)\n\n## Contributing\n\n- Fork the repo on GitHub\n- Clone the project to your own machine\n- Commit changes to your own branch\n- Push your work back up to your fork\n- Submit a Pull request so that we can review your changes and merge\n\n## Credits\n\n* Inspired by [Elixir Doctests](https://elixir-lang.org/getting-started/mix-otp/docs-tests-and-with.html)\n* Original fork of [mainshayne223/doctest-js](https://github.com/MainShayne233/js-doctest). See [issue #1](https://github.com/MainShayne233/js-doctest/issues/1).\n\n## Status\n\nReady for production! Watch and star this repo to keep updated on releases.\n\n![Watch this repo](https://gitcdn.xyz/repo/supabase/monorepo/master/web/static/watch-repo.gif \"Watch this repo\")\n\n\n## Sponsors\n\nWe are building the features of Firebase using enterprise-grade, open source products. We support existing communities wherever possible, and if the products don’t exist we build them and open source them ourselves. Thanks to these sponsors who are making the OSS ecosystem better for everyone.\n\n[![Worklife VC](https://user-images.githubusercontent.com/10214025/90451355-34d71200-e11e-11ea-81f9-1592fd1e9146.png)](https://www.worklife.vc)\n[![New Sponsor](https://user-images.githubusercontent.com/10214025/90518111-e74bbb00-e198-11ea-8f88-c9e3c1aa4b5b.png)](https://github.com/sponsors/supabase)\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkiwicopple%2Fdoctest-js","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkiwicopple%2Fdoctest-js","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkiwicopple%2Fdoctest-js/lists"}