{"id":22511283,"url":"https://github.com/matmanjs/mocha-annotation","last_synced_at":"2025-07-01T08:04:33.949Z","repository":{"id":38846380,"uuid":"272129307","full_name":"matmanjs/mocha-annotation","owner":"matmanjs","description":"Annotation for mocha","archived":false,"fork":false,"pushed_at":"2023-03-06T03:20:14.000Z","size":450,"stargazers_count":0,"open_issues_count":5,"forks_count":3,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-06-06T18:04:54.201Z","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/matmanjs.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-06-14T03:58:03.000Z","updated_at":"2021-06-02T01:25:53.000Z","dependencies_parsed_at":"2024-10-12T16:01:37.687Z","dependency_job_id":"8dd65121-de5a-405c-b42a-74f06d7b0c53","html_url":"https://github.com/matmanjs/mocha-annotation","commit_stats":{"total_commits":64,"total_committers":5,"mean_commits":12.8,"dds":0.5625,"last_synced_commit":"a27812af60af976b6d956d1b3d7533a630d080a0"},"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/matmanjs/mocha-annotation","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/matmanjs%2Fmocha-annotation","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/matmanjs%2Fmocha-annotation/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/matmanjs%2Fmocha-annotation/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/matmanjs%2Fmocha-annotation/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/matmanjs","download_url":"https://codeload.github.com/matmanjs/mocha-annotation/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/matmanjs%2Fmocha-annotation/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":260406248,"owners_count":23004121,"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-12-07T02:10:45.071Z","updated_at":"2025-07-01T08:04:33.923Z","avatar_url":"https://github.com/matmanjs.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# mocha-annotation\n\n解析使用 Mocha 编写的测试用例中的注解。\n\n\n## 1. 安装\n\n```\n$ npm install mocha-annotation --save\n```\n\n## 2. API\n\n### 2.1 getParseResult(sourceFiles, opts)\n\n获得注解解析结果，结果为一个对象。\n\n- `sourceFiles`，`string[]`，要解析的测试文件的列表\n- `opts`，`Object`，额外参数\n  - `opts.encoding`，`string`，读取文件时需要的文件编码格式，默认为 `utf8`\n  - `opts.isInherit`，`boolean`，是否启用继承注解的方式，如果设置为 `true`，则会按照用例组织的方式，优先使用自己的注解，其他则继承父级的注解\n\n\n例如测试用例代码：\n\n```js\nconst {expect} = require('chai');\n\n/**\n * @author matmanjs\n * @description hello,world!\n * @other one-describe-one-it.test.js\n * @testid one-describe-one-it:describe1\n */\ndescribe('一个 describe 和一个 it', function () {\n  /**\n   * @testid one-describe-one-it:describe1:it1\n   */\n  it('1 等于 1', function () {\n    expect(1).to.equal(1);\n  });\n});\n```\n\n解析的结果为：\n\n```json\n{\n    \"children\": [\n        {\n            \"fullFile\": \"/Users/helinjiang/gitprojects/mocha-annotation/test/data/mocha-examples/one-describe-one-it.test.js\",\n            \"uuid\": \"267d1bc4-3c65-4710-ba87-7d471845c927\",\n            \"children\": [\n                {\n                    \"comment\": {\n                        \"author\": \"matmanjs\",\n                        \"description\": \"hello,world!\",\n                        \"other\": \"one-describe-one-it.test.js\",\n                        \"testid\": \"one-describe-one-it:describe1\"\n                    },\n                    \"nodeInfo\": {\n                        \"describe\": \"一个 describe 和一个 it\",\n                        \"callee\": \"describe\",\n                        \"prelayer\": \"267d1bc4-3c65-4710-ba87-7d471845c927\"\n                    },\n                    \"uuid\": \"42f9e2e4-524d-4b79-b8cb-f752dddab5c7\",\n                    \"children\": [\n                        {\n                            \"comment\": {\n                                \"author\": \"matmanjs\",\n                                \"description\": \"hello,world!\",\n                                \"other\": \"one-describe-one-it.test.js\",\n                                \"testid\": \"one-describe-one-it:describe1:it1\"\n                            },\n                            \"nodeInfo\": {\n                                \"describe\": \"1 等于 1\",\n                                \"callee\": \"it\",\n                                \"prelayer\": \"42f9e2e4-524d-4b79-b8cb-f752dddab5c7\"\n                            },\n                            \"uuid\": \"232e201b-eec3-4967-bd9a-3e710f31b75b\",\n                            \"children\": [],\n                            \"fullFile\": \"/Users/helinjiang/gitprojects/mocha-annotation/test/data/mocha-examples/one-describe-one-it.test.js\",\n                            \"parentId\": \"42f9e2e4-524d-4b79-b8cb-f752dddab5c7\"\n                        }\n                    ],\n                    \"fullFile\": \"/Users/helinjiang/gitprojects/mocha-annotation/test/data/mocha-examples/one-describe-one-it.test.js\",\n                    \"parentId\": \"267d1bc4-3c65-4710-ba87-7d471845c927\"\n                }\n            ],\n            \"comment\": {}\n        }\n    ]\n}\n```\n\n### 2.2 getTestResultMap(mochaTestTreeNode, opts)\n\n获得测试结果，一个扁平化的数据字典，`key` 为测试用例的描述，也即 `fullTitle` 。可以借助 [mochawesome](https://www.npmjs.com/package/mochawesome) 生成的 `mochawesome.json`，获得最终测试结果的结果。\n\n- `mochaTestTreeNode`，`MochaTestTreeNode`，要解析的测试文件的列表\n- `opts`，`Object`，额外参数\n  - `opts.fullTitleSep`，`String`，组合 `fullTitle` 是需要的间隔符号，默认情况下该值会由用例数中的描述组合而成，组合间隔符默认为空格\n  - `opts.mochawesomeJsonFile`，`String`，[mochawesome](https://www.npmjs.com/package/mochawesome) 生成的 `mochawesome.json` 路径\n\n\n\u003e `fullTitle` 参考 mochawesome.json 中的定义方式，即从 suit 到 test 的 title 值拼接起来，中间用 `fullTitleSep` 分割\n\n```json\n{\n    \"/Users/helinjiang/gitprojects/mocha-annotation/test/data/mocha-examples/one-describe-one-it.test.js 一个 describe 和一个 it 1 等于 1\": {\n        \"comment\": {\n            \"author\": \"matmanjs\",\n            \"description\": \"hello,world!\",\n            \"other\": \"one-describe-one-it.test.js\",\n            \"testid\": \"one-describe-one-it:describe1:it1\"\n        },\n        \"nodeInfo\": {\n            \"describe\": \"1 等于 1\",\n            \"callee\": \"it\",\n            \"prelayer\": \"42f9e2e4-524d-4b79-b8cb-f752dddab5c7\"\n        },\n        \"uuid\": \"232e201b-eec3-4967-bd9a-3e710f31b75b\",\n        \"children\": [],\n        \"fullFile\": \"/Users/helinjiang/gitprojects/mocha-annotation/test/data/mocha-examples/one-describe-one-it.test.js\",\n        \"parentId\": \"42f9e2e4-524d-4b79-b8cb-f752dddab5c7\",\n        \"fullTitle\": \"/Users/helinjiang/gitprojects/mocha-annotation/test/data/mocha-examples/one-describe-one-it.test.js 一个 describe 和一个 it 1 等于 1\",\n        \"result\": {\n            \"title\": \"1 等于 1\",\n            \"fullTitle\": \"一个 describe 和一个 it 1 等于 1\",\n            \"timedOut\": false,\n            \"duration\": 0,\n            \"state\": \"passed\",\n            \"speed\": \"fast\",\n            \"pass\": true,\n            \"fail\": false,\n            \"pending\": false,\n            \"context\": null,\n            \"code\": \"expect(1).to.equal(1);\",\n            \"err\": {},\n            \"uuid\": \"43f91ee7-b9ac-4cbc-bd35-8d38b0fef5fb\",\n            \"parentUUID\": \"4a52b6a5-5b59-4bf9-83ce-187e5d099b82\",\n            \"isHook\": false,\n            \"skipped\": false\n        }\n    }\n}\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmatmanjs%2Fmocha-annotation","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmatmanjs%2Fmocha-annotation","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmatmanjs%2Fmocha-annotation/lists"}