{"name":"tap-parser","version":"18.0.2","keywords":["tap","test","parser"],"license":"BlueOak-1.0.0","_id":"tap-parser@18.0.2","maintainers":[{"name":"isaacs","email":"i@izs.me"}],"homepage":"https://github.com/tapjs/tapjs#readme","bugs":{"url":"https://github.com/tapjs/tapjs/issues"},"bin":{"tap-parser":"bin/cmd.cjs"},"tap":{"include":["test/*.ts"],"typecheck":false,"coverage-map":"map.js"},"dist":{"shasum":"c7446e25e15e47e8c71653f401237cff35e22358","tarball":"http://registry-npm.ywwl.com/tap-parser/download/tap-parser-18.0.2.tgz","fileCount":86,"integrity":"sha512-bZvlpCGIQfXXCEvypkRYreETh5hsdRNjTcQHRJr5aCA66BQKwg+7jJ3s1N6Z8AKnNmykofWtYFotHJBWQyV8SA==","signatures":[{"sig":"MEUCIBztGySP2+9UWPLqbT5EtIWoVbnY2qkECQ6tJAIm319sAiEAqnDYEvpiqYD3u0xbD0AdezXRwHW/dTvUz0271cF8F08=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":315987,"size":69028,"noattachment":false,"key":"/tap-parser/-/tap-parser-18.0.2.tgz"},"main":"./dist/commonjs/index.js","tshy":{"main":true,"exports":{".":"./src/index.ts","./package.json":"./package.json"}},"type":"module","types":"./dist/commonjs/index.d.ts","module":"./dist/esm/index.js","engines":{"node":"20 || >=22"},"exports":{".":{"import":{"types":"./dist/esm/index.d.ts","default":"./dist/esm/index.js"},"require":{"types":"./dist/commonjs/index.d.ts","default":"./dist/commonjs/index.js"}},"./package.json":"./package.json"},"gitHead":"8575fa9acebae3bc42ef16fb7641afa32d857eb4","scripts":{"snap":"tap","test":"tap","format":"prettier --write . --log-level warn --ignore-path ../../.prettierignore --cache","prepare":"tshy","presnap":"npm run prepare","pretest":"npm run prepare","typedoc":"typedoc --tsconfig tsconfig/esm.json ./src/*.ts"},"_npmUser":{"name":"isaacs","email":"i@izs.me"},"repository":{"url":"git+https://github.com/tapjs/tapjs.git","type":"git"},"_npmVersion":"11.4.2","description":"parse the test anything protocol","directories":{},"_nodeVersion":"24.4.1","dependencies":{"tap-yaml":"4.0.2","events-to-array":"^2.0.3"},"_hasShrinkwrap":false,"_npmOperationalInternal":{"tmp":"tmp/tap-parser_18.0.2_1762038888683_0.22063358607543493","host":"s3://npm-registry-packages-npm-production"},"readme":"# tap-parser\n\nparse the [test anything protocol](http://testanything.org/)\n\nThis parser implements [version 14 of the TAP\nSpecification](https://testanything.org/tap-version-14-specification.html).\n\n# example\n\n```js\n// cjs style\nconst { Parser } = require('tap-parser')\n// or, you can do it this way:\n// import { Parser } from 'tap-parser'\n// or this way:\n// import { Parser } from 'https://unpkg.com/tap-parser@latest/dist/esm/index.js'\nconst p = new Parser(results => console.dir(results))\nprocess.stdin.pipe(p)\n```\n\ngiven some [TAP](http://testanything.org/)-formatted input:\n\n```\n$ node test.js\nTAP version 14\n# beep\nok 1 should be equal\nok 2 should be equivalent\n# boop\nok 3 should be equal\nok 4 (unnamed assert)\n\n1..4\n# tests 4\n# pass  4\n\n# ok\n```\n\nparse the output:\n\n```\n$ node test.js | node parse.js\n{ ok: true, count: 4, pass: 4, plan: { start: 1, end: 4 } }\n```\n\nIf you have a string, you can also turn it into an array of parse events,\nand turn such an array back into a TAP string with `Parser.parse()` and\n`Parser.stringify()`, respectively.\n\n```js\n// JSON.parse/stringify style\n\n// Note that stringifying arbitrary object types isn't supported,\n// because TAP is a streaming line-based protocol, not an object\n// serialization notation like JSON or YAML.\n\nconst { parse, stringify } = require('tap-parser')\nconst fs = require('fs')\nconst tapData = fs.readFileSync('previous-test-output.tap')\nconst result = parse(tapData)\nconsole.dir(result)\nconst reEncodedAsTap = stringify(result)\nconsole.log(reEncodedAsTap)\n```\n\n# usage\n\nThis package also has a `tap-parser` command.\n\n```\nUsage:\n  tap-parser <options>\n\nParses TAP data from stdin, and outputs the parsed result\nin the format specified by the options.  Default output\nuses node's `util.inspect()` method.\n\nOptions:\n\n  -j [<indent>] | --json[=indent]\n    Output event data as JSON with the specified indentation (default=2)\n\n  -t | --tap\n    Output data as reconstituted TAP based on parsed results\n\n  -l | --lines\n    Output each parsed line as it is recognized by the parser\n\n  -b | --bail\n    Emit a `Bail out!` at the first failed test point encountered\n\n  -B | --no-bail\n    Do not bail out at the first failed test point encountered\n    (Default)\n\n  -f | --flat\n    Flatten all assertions to the top level parser\n\n  -F | --no-flat\n    Do not flatten all assertions to the top level parser\n    (Default)\n\n  -w | --ignore-all-whitespace\n    Skip over blank lines outside of YAML blocks\n\n  -o | --omit-version\n    Ignore the `TAP version 13` or `TAP version 14` line at the start of tests\n\n  --strict\n    Run the parser in strict mode\n\n  --no-strict\n    Do not run the parser in strict mode\n\n  -s | --silent\n    Do not print output, just exit success/failure based on TAP stream\n```\n\n# methods\n\n```js\nconst { Parser } = require('tap-parser')\n```\n\n## `const p = new Parser(options, cb)`\n\nReturn a writable stream `p` that emits parse events.\n\nIf `cb` is given it will listen for the `'complete'` event.\n\nIf `options` is given, it may contain the following flags:\n\n- `preserveWhitespace` boolean which is `false` by default and will\n  cause the parser to emit `line` events even for lines containing\n  only whitespace. (Whitespace lines in yaml blocks are always\n  emitted, because whitespace is semantically relevant for yaml.)\n\n- `strict` boolean which is `false` by default and causes the parser\n  to treat non-TAP input as a failure. Strictness is heritable to\n  child subtests. You can also turn strictness on or off by using the\n  `pragma +strict` line in the TAP data to turn strictness on, or\n  `pragma -strict` to turn strictness off.\n\n- `bail` boolean which is `false` by default and will cause the parser\n  to bail out (including emitting a synthetic `Bail out!` line)\n  whenever a failed test point is encountered.\n\n- `omitVersion` boolean which is `false` by default and will cause the\n  parser to ignore `TAP version 13` or `TAP version 14` lines.\n  Version lines in subtests cause problems with some parsers, so\n  they are always ignored.\n\n- `passes` boolean which is false by default and will add \"passes\" property\n  for that contains the result of all passed tests\n\nThe `parent`, `level` and `buffered` options are reserved for internal\nuse.\n\n# events\n\n## `p.on('complete', function (results) {})`\n\nThe `results` object contains a summary of the number of tests\nskipped, failed, passed, etc., as well as a boolean `ok` member which\nis true if and only if the planned test were all found, and either\n\"ok\" or marked as \"TODO\".\n\n## `p.on('line', function (line) {})`\n\nAs each line of input is parsed, a `line` event is emitted.\n\n\"Synthetic\" line events will be emitted to support the `bail`\nbehavior, and to inject `1..0` plan lines in subtests that have no\ntest points. They can be used as a sort of \"passthrough stream\" to\nsanitize and filter a TAP stream, with the caveat that, while `line`\nevents will be semantically equivalent to the TAP input, they will not\nbe a perfect replica of the input.\n\n## `p.on('assert', function (assert) {})`\n\nEvery `/^(not )?ok\\b/` line will emit an `'assert'` event.\n\nEvery `assert` object has these keys:\n\n- `assert.ok` - true if the assertion succeeded, false if failed\n- `assert.id` - the assertion number\n- `assert.name` - optional short description of the assertion\n\nand may also have\n\n- `assert.todo` - optional description of why the assertion failure is\n  not a problem. (Boolean `true` if no explaination provided)\n- `assert.skip` - optional description of why this assertion was\n  skipped (boolean `true` if no explanation provided)\n- `assert.diag` - a diagnostic object with additional information\n  about the test point.\n\n## `p.on('comment', function (comment) {})`\n\nEvery `/^# (.+)/` line will emit the string contents of `comment`.\n\n## `p.on('plan', function (plan) {})`\n\nEvery `/^\\d+\\.\\.\\d+/` line emits a `'plan'` event for the test numbers\n`plan.start` through `plan.end`, inclusive.\n\nIf the test is [completely\nskipped](https://testanything.org/tap-version-14-specification.html#skipping-everything)\nthe result will look like\n\n```\n{ ok: true,\n  count: 0,\n  pass: 0,\n  plan:\n   { start: 1,\n     end: 0,\n     skipAll: true,\n     skipReason: 'This code has no seat belt' } }\n```\n\n## `p.on('version', function (version) {})`\n\nA `/^TAP version (\\d+)/` line emits a `'version'` event with a version\nnumber or string.\n\n## `p.on('bailout', function (reason) {})`\n\nA `bail out!` line will cause the parser to completely stop doing\nanything. Child parser bailouts will bail out their parents as well.\n\n## `p.on('child', function (childParser) {})`\n\nIf a child test set is embedded in the stream like this:\n\n```\nTAP Version 14\n1..2\n# nesting\n    1..2\n    ok 1 - true is ok\n    ok 2 - doag is also okay\nok 1 - nesting\nok 2 - second\n```\n\nthen the child stream will be parsed and events will be raised on the\n`childParser` object.\n\nSince TAP streams with child tests _must_ follow child test sets\nwith a pass or fail assert based on the child test's results, failing\nto handle child tests should always result in the same end result.\nHowever, additional information from those child tests will obviously\nbe lost.\n\nSee `Subtests` below for more information on which sorts of subtest\nformats are supported by this parser.\n\n## `p.on('result', function (assert) {})`\n\nThis is the same as the `assert` event, except that it only emits on the root\nparser, whenever it or any child parser has an `assert` event that is not\nmerely closing a child test block.\n\n## `p.on('pass', function (assert) {})`\n\n## `p.on('fail', function (assert) {})`\n\n## `p.on('skip', function (assert) {})`\n\n## `p.on('todo', function (assert) {})`\n\nEmitted on the root parser object, whenever it or any child parser has an\n`assert` event that is not merely closing a child test block, if the result is\nof the appropriate type.\n\n## `p.on('extra', function (extra) {})`\n\nAll other lines will trigger an `'extra'` event with the line text.\n\n# static method: `const results = Parser.parse(string, options = {})`\n\nThis will return an array of all the events encountered in the parsed TAP\nstring.\n\nAny options to the `Parser` constructor may be provided, in addition to the\nfollowing:\n\n- `flat`: Boolean, default false, flatten nested child tests into a single\n  level. Note that this will lose child test information, and will result\n  in a `complete` event that may not match the counts of assertions in the\n  list. This is useful if you are transforming TAP strings for use by a\n  parser that does not support child tests, or just simply don't care about\n  that level of detail. Result `id` values will be coerced to an\n  incrementing numeric values, and a valid `plan` will be generated at the\n  end of the stream.\n\n# static method: `const tap = Parser.stringify(results, options = {})`\n\nTurn a `results` list of the sort returned by `Parser.parse()` into a TAP\nstring.\n\nThe following options are supported:\n\n- `flat`: Boolean, default false, flatten nested child tests into a single\n  level. Note that this will lose child test information, and will result\n  in a `complete` event that may not match the counts of assertions in the\n  list. This is useful if you are transforming TAP strings for use by a\n  parser that does not support child tests, or just simply don't care about\n  that level of detail. Result `id` values will be coerced to an\n  incrementing numeric values, and a valid `plan` will be generated at the\n  end of the stream.\n\nThe `indent` and `id` options are used internally, and should not be\nmodified.\n\n# install\n\nWith [npm](https://npmjs.org) do:\n\n```\nnpm install tap-parser\n```\n\nYou can use [browserify](http://browserify.org) to `require('tap-parser')` in\nthe browser.\n\n# license\n\nMIT\n\n# subtests\n\n5 flavors of Subtests are suppored by this parser.\n\n1. Unadorned.\n   Indented TAP data with no comment, followed by a test\n   point at the parent level.\n\n   ```\n       ok 1\n       1..1\n   ok 1 - child test\n   1..1\n   ```\n\n2. Indented comment.\n   An indented `# Subtest: <name>` comment, followed by indented TAP\n   data, and then a not-indented test point with a matching name.\n   The summary test point may have yaml diagnostics.\n\n   ```\n       # Subtest: child test\n       ok 1\n       1..1\n   ok 1 - child test\n   1..1\n   ```\n\n3. Unindented comment.\n   A not-indented `# Subtest: <name>` comment, followed by indented TAP\n   content, followed by a test point with a matching name.\n   The summary test point may have yaml diagnostics.\n\n   ```\n   # Subtest: child test\n       ok 1\n       1..1\n   ok 1 - child test\n   1..1\n   ```\n\n4. Buffered, without diagnostics.\n   A test point line ending in {, followed by indented TAP content, ended\n   with a } to close the block. todo/skip directives may come _either_\n   before or after the `{` character. Yaml diagnostics are not allowed.\n\n   ```\n   ok 1 - child test {\n       ok 1\n       1..1\n   }\n   1..1\n   ```\n\n5. Buffered, with diagnostics.\n   A test point line with yaml diagnostics, followed by `{` alone on a\n   line, indented TAP data, and then a `}`.\n\n   ```\n   ok 1 - child test\n     ---\n     some: diagnostic\n     data: true\n     ...\n   {\n       ok 1\n       1..1\n   }\n   ```\n\nIn all cases, the parsed behavior is identical:\n\n1. The parent emits a `child` event with the `childParser` as an\n   argument.\n2. The `childParser` emits a `comment` with `# Subtest: <name>` (or\n   `(anonymous)` for Unadorned subtests.)\n3. When the test is over, the closing test point is emitted on parent\n   test.\n\nThat is, buffered and nonindented/indented comment subtests are parsed\nas if they are identical input, since their semantics are the same. This\nsimplifies implementation of test harness and reporter modules.\n\nSince unadorned subtests have no introduction, a child event is not\nemitted until the first \"relevant tap\" line is encountered. This can\ncause confusion if the test output contains a spurious \" 1..2\" line\nor something, but such cases are rare.\n\nSimilarly, this means that a test point ending in `{` needs to wait to\nemit _either_ the 'assert' or 'child' events until an indented line is\nencountered. _Any_ test point with yaml diagnostics needs to wait to\nsee if it will be followed by a `{` indicating a subtest.\n","publish_time":1762038888885,"_cnpm_publish_time":1762038888885,"dist-tags":{"latest":"18.3.4","pre":"15.0.0"}}