{"id":17398431,"url":"https://github.com/vweevers/doctap","last_synced_at":"2025-04-30T05:22:07.467Z","repository":{"id":57153841,"uuid":"73180788","full_name":"vweevers/doctap","owner":"vweevers","description":"Functionally test readme snippets","archived":false,"fork":false,"pushed_at":"2016-11-08T13:54:53.000Z","size":9,"stargazers_count":5,"open_issues_count":7,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-25T01:58:20.190Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/vweevers.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":"2016-11-08T11:45:22.000Z","updated_at":"2019-01-05T13:47:15.000Z","dependencies_parsed_at":"2022-09-06T19:21:51.900Z","dependency_job_id":null,"html_url":"https://github.com/vweevers/doctap","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vweevers%2Fdoctap","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vweevers%2Fdoctap/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vweevers%2Fdoctap/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vweevers%2Fdoctap/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/vweevers","download_url":"https://codeload.github.com/vweevers/doctap/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251645984,"owners_count":21620846,"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-10-16T14:56:19.658Z","updated_at":"2025-04-30T05:22:07.444Z","avatar_url":"https://github.com/vweevers.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# console.log(actual) // expected\n\n**Functionally test readme snippets.**\n\nTransforms markdown code blocks to serially executed [tape](https://github.com/substack/tape) tests. Use trailing comments to specify the expected result of `console.log()` calls and pipe to a [TAP](https://testanything.org/tap-version-13-specification.html) [reporter of your choice](https://github.com/substack/tape#pretty-reporters). Requires Node.js 6.8.0+.\n\n[![npm status](http://img.shields.io/npm/v/doctap.svg?style=flat-square)](https://www.npmjs.org/package/doctap) ![not even sure](https://img.shields.io/badge/good%20idea-maybe%3F-ff69b4.svg) [![Dependency status](https://img.shields.io/david/vweevers/doctap.svg?style=flat-square)](https://david-dm.org/vweevers/doctap)\n\n## usage: doctap \\[file, ..\\]\n\nLet's test the snippets in this very readme.\n\n```js\nconst pkg = require('./package.json')\nconst floor = Math.floor\n\nconsole.log('hello') // 'hello'\nconsole.log(pkg.name) // 'doctap'\nconsole.log(floor(1.2)) // 1\n```\n\n**doctap \\*.md**\n\n```\nTAP version 13\n# readme.md:12\nok 1 'hello' == 'hello'\nok 2 pkg.name == 'doctap'\nok 3 floor(1.2) == 1\n```\n\n*Output continued below.*\n\n## asynchronicity\n\n```js\nconst glob = require('glob')\n\nglob('*.md', { cwd: __dirname }, (err, files) =\u003e {\n  console.log(files) // ['readme.md']\n})\n```\n\n```\n# readme.md:36\nok 4 files == ['readme.md']\n```\n\n## comments are javascript too\n\n```js\nconst name = 'doctap'\nconsole.log(2 * 3) // 2 + 4\nconsole.log('doctap') // name\n```\n\n```\n# readme.md:51\nok 5 2 * 3 == 2 + 4\nok 6 'doctap' == name\n```\n\n## repeated calls\n\n```js\nfor(let value of [1, 2, 3]) {\n  console.log(value * 2) // 2, 4, 6\n}\n```\n\n```\n# readme.md:65\nok 7 value * 2 == 2 1/3\nok 8 value * 2 == 4 2/3\nok 9 value * 2 == 6 3/3\n```\n\n## require\n\nAs you may have noticed above: `require()` is relative to the markdown file.\n\nProvided there's a nearby `package.json`, you can also require your own package by name.\n\n```js\nconst doctap = require('doctap')\n```\n\n## shared scope\n\nIf one snippet declares a variable in the top-most scope (like `glob` above), subsequent snippets can reference it. This is most useful to require shared things in your first snippet, and avoid repeating yourself.\n\n```js\nconsole.log(glob.sync('*.md')) // ['readme.md']\n```\n\n```\n# readme.md:92\nok 10 glob.sync('*.md') == ['readme.md']\n```\n\n## matches your style\n\n```js\nconsole.log('hello') // 'hello'\nconsole.log(\"world\") // `world`\n```\n\n```\n# readme.md:103\nok 11 'hello' == 'hello'\nok 12 \"world\" == `world`\n```\n\n## multiple arguments\n\n```js\nconsole.log('hello %s', 'world') // 'hello world'\nconsole.log(1, 2) // '1 2'\n```\n\n```\n# readme.md:116\nok 13 'hello %s', 'world' == 'hello world'\nok 14 1, 2 == '1 2'\n```\n\n## errors\n\nAn attempt is made to rewrite stack traces, but it's not effective in all places right now, and not applied to failing `tape` assertions either.\n\n```js\nfunction please () {\n  throw new Error('no')\n}\n\nconsole.log(false) // true\nconsole.log(please())\n```\n\n```\n# readme.md:131\nnot ok 15 false == true\n  ---\n    operator: deepEqual\n    expected: true\n    actual:   false\n    at: Test.test (/doctap/readme131.js:26:11)\n  ...\n\n/doctap/readme131.js:19\n      throw new Error('no')\n      ^\n\nError: no\n    at please (/doctap/readme.md:133:9)\n    at Test.test (/doctap/readme.md:137:13)\n    at Test.bound [as _cb] (/doctap/node_modules/tape/lib/test.js:65:32)\n    at ...\n```\n\n## install\n\nWith [npm](https://npmjs.org) do:\n\n```\nnpm install doctap --global\n```\n\n## license\n\n[MIT](http://opensource.org/licenses/MIT) © Vincent Weevers\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvweevers%2Fdoctap","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvweevers%2Fdoctap","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvweevers%2Fdoctap/lists"}