3

我尝试按照本文中的建议删除命令中的空格。我还尝试按照本文中的建议重新编码 mochawesome.json 。但非工作。

可以在 gdrive 上找到我的 json 文件。

当我尝试合并它们时,出现以下错误:

npx mochawesome-merge cypress/reports/test/test/*.json>cypress/reports/test/test/merged_report.json 
Debugger attached.
Debugger attached.
ERROR: Failed to merge reports

SyntaxError: cypress/reports/test/test/merged_report.json: Unexpected end of JSON input
    at JSON.parse (<anonymous>)
    at F:\myproj-testing\node_modules\mochawesome-merge\node_modules\jsonfile\index.js:33:18
    at F:\myproj-testing\node_modules\graceful-fs\graceful-fs.js:123:16
    at FSReqCallback.readFileAfterClose [as oncomplete] (internal/fs/read_file_context.js:63:3)
Waiting for the debugger to disconnect...
Waiting for the debugger to disconnect...

我在 Windows 10 上。以下是与节点相关的版本:

>node --version
v14.16.0

> npm --version
Debugger attached.
6.14.11

包.json

{
  "name": "myproj-testing",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "merge":"mochawesome-merge cypress/reports/*.json>cypress/reports/merged_report.json",
    "generate_mochawesome_report": "marge cypress/reports/merged_report.json --reportDir ./ --inline",
    "final_report": "npm run merge && npm run generate_mochawesome_report",
    "generate_report": "python cypress/utils/merge.py && npm run generate_mochawesome_report"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "dependencies": {
    "cypress": "^8.3.0",
    "cypress-file-upload": "^5.0.8"
  },
  "devDependencies": {
    "mocha": "^9.1.1",
    "mochawesome": "^6.2.2",
    "mochawesome-merge": "^4.2.0"
  }
}

更新

我尝试运行mochawesome-merge cypress/reports/*.json,它在控制台上打印了合并的 json。所以我尝试先将合并的 json 字符串通过管道传输到.txt文件,然后将文件重命名.txt.json文件,最后执行marge. 奇怪的是它开始工作了......所以这些是我更新的package.json脚本:

  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "merge":"mochawesome-merge cypress/reports/*.json>cypress/reports/merged_report.json",
    "mergetotxt":"mochawesome-merge cypress/reports/*.json > cypress/reports/merged_report.txt",

    "generate_mochawesome_report": "marge cypress/reports/merged_report.json --reportDir ./ --inline",

    "final_report": "npm run merge && npm run generate_mochawesome_report",
    "final_report2": "npm run mergetotxt && rename cypress\\reports\\merged_report.txt merged_report.json && npm run generate_mochawesome_report",

    "generate_report": "python cypress/utils/merge.py && npm run generate_mochawesome_report"
  }

请注意以下两个新脚本:

"mergetotxt":"mochawesome-merge cypress/reports/*.json > cypress/reports/merged_report.txt",
"final_report2": "npm run mergetotxt && rename cypress\\reports\\merged_report.txt merged_report.json && npm run generate_mochawesome_report",

运行npm run final_report2生成所需的报告。

4

3 回答 3

0

请试试这个“合并报告”:“mochawesome-merge cypress/reports/*.json > merge_report.txt > merge_report.json”,

这对我有用。

于 2021-10-05T13:08:21.547 回答
0

问题是这一行:

"merge":"mochawesome-merge cypress/reports/*.json>cypress/reports/merged_report.json"

您不能使用结果 json 的路径。

"merge":"mochawesome-merge cypress/reports/*.json > merged_report.json"

应该管用

于 2021-09-27T10:43:07.120 回答
0
"merge":"mochawesome-merge cypress/reports/*.json>cypress/reports/output.json",
"generate_mochawesome_report": "marge cypress/reports/output.json --reportDir ./ --inline",
"final_report": "npm run merge && npm run generate_mochawesome_report"

试试这个方法,这应该可以...

于 2021-11-29T07:35:55.970 回答