{"id":21524713,"url":"https://github.com/assertedio/mocha-ldjson","last_synced_at":"2025-03-17T18:17:12.605Z","repository":{"id":38007117,"uuid":"247502503","full_name":"assertedio/mocha-ldjson","owner":"assertedio","description":"Mocha reporter to write ld-json to file","archived":false,"fork":false,"pushed_at":"2023-01-09T22:56:42.000Z","size":746,"stargazers_count":0,"open_issues_count":14,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-02-24T06:38:56.302Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/assertedio.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":"2020-03-15T16:13:55.000Z","updated_at":"2020-08-12T14:03:25.000Z","dependencies_parsed_at":"2023-02-08T15:31:52.167Z","dependency_job_id":null,"html_url":"https://github.com/assertedio/mocha-ldjson","commit_stats":null,"previous_names":[],"tags_count":21,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/assertedio%2Fmocha-ldjson","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/assertedio%2Fmocha-ldjson/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/assertedio%2Fmocha-ldjson/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/assertedio%2Fmocha-ldjson/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/assertedio","download_url":"https://codeload.github.com/assertedio/mocha-ldjson/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244085011,"owners_count":20395523,"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-24T01:28:42.011Z","updated_at":"2025-03-17T18:17:12.580Z","avatar_url":"https://github.com/assertedio.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# mocha-ldjson\nMocha reporter to stream ld-json (newline-delimited json) results to a file as the tests execute.\n\nThis way, regardless of the final outcome of the test run (exception, terminated process, hung process, etc) \nyou'll still have the results up until the point at which Mocha stopped calling the reporter.\n\n\n## Install\n```bash\nnpm i --save-dev mocha-ldjson\n```\n\n## Use\n\nJust run:\n\n```bash\nmocha some-test-file.js --reporter mocha-ldjson\n```\n\nAnd it will output the LDJSON to the current working directory inside `reports/report.ldjson`.\n\nShould look like:\n\n```\n{\"data\":{\"id\":null,\"type\":\"start\",\"file\":null,\"title\":null,\"fullTitlePath\":[],\"fullTitle\":null,\"duration\":null,\"result\":null,\"error\":null,\"root\":false,\"timedOut\":false},\"timestamp\":\"2020-04-14T14:56:09.250Z\",\"elapsedMs\":13,\"stats\":{\"duration\":null,\"suites\":0,\"tests\":0,\"passes\":0,\"pending\":0,\"failures\":0,\"start\":\"2020-04-14T14:56:09.236Z\"}}\n{\"data\":{\"id\":\"ck9013kmb000058fd5s2p97f6\",\"type\":\"suite\",\"file\":null,\"title\":null,\"fullTitlePath\":[],\"fullTitle\":\"\",\"duration\":null,\"result\":null,\"error\":null,\"root\":true,\"timedOut\":false},\"timestamp\":\"2020-04-14T14:56:09.251Z\",\"elapsedMs\":14,\"stats\":{\"duration\":null,\"suites\":0,\"tests\":0,\"passes\":0,\"pending\":0,\"failures\":0,\"start\":\"2020-04-14T14:56:09.236Z\"}}\n{\"data\":{\"id\":\"ck9013kmc000158fd5x60dzdy\",\"type\":\"suite\",\"file\":\"/home/ehacke/workspace/assertedio/mocha-ldjson/tests/resources/examples/simple.js\",\"title\":\"suite 1\",\"fullTitlePath\":[\"suite 1\"],\"fullTitle\":\"suite 1\",\"duration\":null,\"result\":null,\"error\":null,\"root\":false,\"timedOut\":false},\"timestamp\":\"2020-04-14T14:56:09.252Z\",\"elapsedMs\":15,\"stats\":{\"duration\":null,\"suites\":1,\"tests\":0,\"passes\":0,\"pending\":0,\"failures\":0,\"start\":\"2020-04-14T14:56:09.236Z\"}}\n{\"data\":{\"id\":\"ck9013kmc000258fd6vaxaseq\",\"type\":\"test\",\"file\":\"/home/ehacke/workspace/assertedio/mocha-ldjson/tests/resources/examples/simple.js\",\"title\":\"test pass\",\"fullTitlePath\":[\"suite 1\",\"test pass\"],\"fullTitle\":\"suite 1 -\u003e test pass\",\"duration\":null,\"result\":null,\"error\":null,\"root\":false,\"timedOut\":false},\"timestamp\":\"2020-04-14T14:56:09.252Z\",\"elapsedMs\":15,\"stats\":{\"duration\":null,\"suites\":1,\"tests\":0,\"passes\":0,\"pending\":0,\"failures\":0,\"start\":\"2020-04-14T14:56:09.236Z\"}}\n{\"data\":{\"id\":\"ck9013kmc000258fd6vaxaseq\",\"type\":\"pass\",\"file\":\"/home/ehacke/workspace/assertedio/mocha-ldjson/tests/resources/examples/simple.js\",\"title\":\"test pass\",\"fullTitlePath\":[\"suite 1\",\"test pass\"],\"fullTitle\":\"suite 1 -\u003e test pass\",\"duration\":0,\"result\":\"passed\",\"error\":null,\"root\":false,\"timedOut\":false},\"timestamp\":\"2020-04-14T14:56:09.254Z\",\"elapsedMs\":17,\"stats\":{\"duration\":null,\"suites\":1,\"tests\":0,\"passes\":1,\"pending\":0,\"failures\":0,\"start\":\"2020-04-14T14:56:09.236Z\"}}\n{\"data\":{\"id\":\"ck9013kmf000358fd8wfwd5ut\",\"type\":\"test\",\"file\":\"/home/ehacke/workspace/assertedio/mocha-ldjson/tests/resources/examples/simple.js\",\"title\":\"test fail\",\"fullTitlePath\":[\"suite 1\",\"test fail\"],\"fullTitle\":\"suite 1 -\u003e test fail\",\"duration\":null,\"result\":null,\"error\":null,\"root\":false,\"timedOut\":false},\"timestamp\":\"2020-04-14T14:56:09.255Z\",\"elapsedMs\":18,\"stats\":{\"duration\":null,\"suites\":1,\"tests\":1,\"passes\":1,\"pending\":0,\"failures\":0,\"start\":\"2020-04-14T14:56:09.236Z\"}}\n{\"data\":{\"id\":\"ck9013kmf000358fd8wfwd5ut\",\"type\":\"fail\",\"file\":\"/home/ehacke/workspace/assertedio/mocha-ldjson/tests/resources/examples/simple.js\",\"title\":\"test fail\",\"fullTitlePath\":[\"suite 1\",\"test fail\"],\"fullTitle\":\"suite 1 -\u003e test fail\",\"duration\":2,\"result\":\"failed\",\"error\":{\"message\":\"AssertionError: expected { foo: 'bar' } to deeply equal { foo: 'baz' }\",\"stack\":\"AssertionError: expected { foo: 'bar' } to deeply equal { foo: 'baz' }\\n    at Context.\u003canonymous\u003e (tests/resources/examples/simple.js:8:31)\\n    at processImmediate (internal/timers.js:456:21)\",\"diff\":\" {\\n-   \\\"foo\\\": \\\"bar\\\"\\n+   \\\"foo\\\": \\\"baz\\\"\\n }\\n\"},\"root\":false,\"timedOut\":false},\"timestamp\":\"2020-04-14T14:56:09.259Z\",\"elapsedMs\":22,\"stats\":{\"duration\":null,\"suites\":1,\"tests\":1,\"passes\":1,\"pending\":0,\"failures\":1,\"start\":\"2020-04-14T14:56:09.236Z\"}}\n{\"data\":{\"id\":\"ck9013kmj000458fd98xve68k\",\"type\":\"test\",\"file\":\"/home/ehacke/workspace/assertedio/mocha-ldjson/tests/resources/examples/simple.js\",\"title\":\"skipped test\",\"fullTitlePath\":[\"suite 1\",\"skipped test\"],\"fullTitle\":\"suite 1 -\u003e skipped test\",\"duration\":null,\"result\":null,\"error\":null,\"root\":false,\"timedOut\":false},\"timestamp\":\"2020-04-14T14:56:09.259Z\",\"elapsedMs\":22,\"stats\":{\"duration\":null,\"suites\":1,\"tests\":2,\"passes\":1,\"pending\":0,\"failures\":1,\"start\":\"2020-04-14T14:56:09.236Z\"}}\n{\"data\":{\"id\":\"ck9013kmj000458fd98xve68k\",\"type\":\"pass\",\"file\":\"/home/ehacke/workspace/assertedio/mocha-ldjson/tests/resources/examples/simple.js\",\"title\":\"skipped test\",\"fullTitlePath\":[\"suite 1\",\"skipped test\"],\"fullTitle\":\"suite 1 -\u003e skipped test\",\"duration\":0,\"result\":\"passed\",\"error\":null,\"root\":false,\"timedOut\":false},\"timestamp\":\"2020-04-14T14:56:09.260Z\",\"elapsedMs\":23,\"stats\":{\"duration\":null,\"suites\":1,\"tests\":2,\"passes\":2,\"pending\":0,\"failures\":1,\"start\":\"2020-04-14T14:56:09.236Z\"}}\n....\n```\n\nDifferent events have different details, but all follow the format:\n\n```json5\n{\n  \"data\": {\n    \"type\": \"start|suite|test|pass|fail|suite end|end\",\n    \"id\": \"some-id\", // ID to join the event boundries\n    \"file\": \"mocha-ldjson/tests/resources/examples/single-passing.js\",\n    \"title\": \"passing test\",\n    \"fullTitlePath\": [\n      \"passing suite\",\n      \"passing test\"\n    ],\n    \"fullTitle\": \"passing suite -\u003e passing test\",\n    \"duration\": 2,\n    \"result\": \"passed\",\n    \"error\": null,\n    \"root\": false,\n    \"timedOut\": false\n    // Additional fields depending on the event type\n  },\n  \"stats\": {\n    \"suites\": 0,\n    \"tests\": 0,\n    \"passes\": 0,\n    \"pending\": 0,\n    \"failures\": 0,\n    // Sometime \"start\", \"end\", or \"duration\" depending on the event type \n  },\n  \"timestamp\": \"2020-03-15T22:21:45.622Z\", // Time the event occurred at\n  \"elapsedMs\": 15, // Time since the reporter was initialized\n}\n```\n\n## Options\n\n### Output Path\n\nUse: `mocha some-test-file.js --reporter=mocha-ldsjson --reporter-options=outputPath=some/path/thing.ldjson`\n\nDefaults to `reports/report.ldjson`.\n\nIf you specify only a directory, the filename will default to `report.ldjson` within that directory.\n\n### Overall Timeout\n\nUse: `mocha some-test-file.js --reporter=mocha-ldsjson --reporter-options=overallTimeoutMs=10000`\n\nDefaults to `undefined`, with no default timeout.\n\nThis is a way of enforcing an overall timeout for the entire test run itself. Once the timeout is reached, an exception\nis thrown to terminate the test process, and a non-zero exit code is returned.\n\nKeep in mind that if external processes are spawned during testing, they may not be terminated cleanly as `after` \nand `afterEach` hooks are not called on timeout.\n\n## Event Types\n\nAll event types map directly to the `RunnerConstants` defined in the Mocha library.\n\n## Some Event Examples\n\n### Start Run Event\n\n```json5\n{\n  \"data\": {\n    \"id\": null,\n    \"type\": \"start\",\n    \"file\": null,\n    \"title\": null,\n    \"fullTitlePath\": [],\n    \"fullTitle\": null,\n    \"duration\": null,\n    \"result\": null,\n    \"error\": null,\n    \"root\": false,\n    \"timedOut\": false\n  },\n  \"timestamp\": \"2020-04-14T14:46:41.855Z\",\n  \"elapsedMs\": 13,\n  \"stats\": {\n    \"duration\": null,\n    \"suites\": 0,\n    \"tests\": 0,\n    \"passes\": 0,\n    \"pending\": 0,\n    \"failures\": 0,\n    \"start\": \"2020-04-14T14:46:41.842Z\"\n  }\n}\n```\n\n### Start Suite Event\n\n```json5\n{\n  \"data\": {\n    \"id\": \"ck900retc0001mvfd05ox47yw\",\n    \"type\": \"suite\",\n    \"file\": \"mocha-ldjson/tests/resources/examples/single-passing.js\",\n    \"title\": \"passing suite\",\n    \"fullTitlePath\": [\n      \"passing suite\"\n    ],\n    \"fullTitle\": \"passing suite\",\n    \"duration\": null,\n    \"result\": null,\n    \"error\": null,\n    \"root\": false,\n    \"timedOut\": false\n  },\n  \"timestamp\": \"2020-04-14T14:46:41.856Z\",\n  \"elapsedMs\": 14,\n  \"stats\": {\n    \"duration\": null,\n    \"suites\": 1,\n    \"tests\": 0,\n    \"passes\": 0,\n    \"pending\": 0,\n    \"failures\": 0,\n    \"start\": \"2020-04-14T14:46:41.842Z\"\n  }\n}\n```\n\n### Before All Hook Ended Event\n\n```json5\n{\n  \"data\": {\n    \"id\": \"ck900retd0002mvfdbhxoa0iz\",\n    \"type\": \"hook end\",\n    \"file\": \"mocha-ldjson/tests/resources/examples/single-passing.js\",\n    \"title\": \"\\\"before all\\\" hook\",\n    \"fullTitlePath\": [\n      \"passing suite\",\n      \"\\\"before all\\\" hook\"\n    ],\n    \"fullTitle\": \"passing suite -\u003e \\\"before all\\\" hook\",\n    \"duration\": 0,\n    \"result\": null,\n    \"error\": null,\n    \"root\": false,\n    \"timedOut\": false\n  },\n  \"timestamp\": \"2020-04-14T14:46:41.857Z\",\n  \"elapsedMs\": 15,\n  \"stats\": {\n    \"duration\": null,\n    \"suites\": 1,\n    \"tests\": 0,\n    \"passes\": 0,\n    \"pending\": 0,\n    \"failures\": 0,\n    \"start\": \"2020-04-14T14:46:41.842Z\"\n  }\n}\n```\n\n## Passing Test Event\n\n```json5\n{\n  \"data\": {\n    \"id\": \"ck900retd0003mvfdeqae6ztg\",\n    \"type\": \"test\",\n    \"file\": \"mocha-ldjson/tests/resources/examples/single-passing.js\",\n    \"title\": \"passing test\",\n    \"fullTitlePath\": [\n      \"passing suite\",\n      \"passing test\"\n    ],\n    \"fullTitle\": \"passing suite -\u003e passing test\",\n    \"duration\": null,\n    \"result\": null,\n    \"error\": null,\n    \"root\": false,\n    \"timedOut\": false\n  },\n  \"timestamp\": \"2020-04-14T14:46:41.857Z\",\n  \"elapsedMs\": 15,\n  \"stats\": {\n    \"duration\": null,\n    \"suites\": 1,\n    \"tests\": 0,\n    \"passes\": 0,\n    \"pending\": 0,\n    \"failures\": 0,\n    \"start\": \"2020-04-14T14:46:41.842Z\"\n  }\n}\n```\n\n### Failing Test Event\n\n```json5\n{\n  \"data\": {\n    \"id\": \"ck900qjza0002jufd1kqn97kr\",\n    \"type\": \"fail\",\n    \"file\": \"mocha-ldjson/tests/resources/examples/single-failing.js\",\n    \"title\": \"failing test\",\n    \"fullTitlePath\": [\n      \"failing suite\",\n      \"failing test\"\n    ],\n    \"fullTitle\": \"failing suite -\u003e failing test\",\n    \"duration\": 2,\n    \"result\": \"failed\",\n    \"error\": {\n      \"message\": \"AssertionError: expected true to deeply equal false\",\n      \"stack\": \"AssertionError: expected true to deeply equal false\\n    at Context.\u003canonymous\u003e (tests/resources/examples/single-failing.js:5:21)\\n    at processImmediate (internal/timers.js:456:21)\",\n      \"diff\": \"- true\\n+ false\\n\"\n    },\n    \"root\": false,\n    \"timedOut\": false\n  },\n  \"timestamp\": \"2020-04-14T14:46:01.898Z\",\n  \"elapsedMs\": 19,\n  \"stats\": {\n    \"duration\": null,\n    \"suites\": 1,\n    \"tests\": 0,\n    \"passes\": 0,\n    \"pending\": 0,\n    \"failures\": 1,\n    \"start\": \"2020-04-14T14:46:01.879Z\"\n  }\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fassertedio%2Fmocha-ldjson","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fassertedio%2Fmocha-ldjson","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fassertedio%2Fmocha-ldjson/lists"}