执行 mochawesome-merge 时出现“JSON 输入意外结束”

问题描述 投票:0回答:5

我尝试按照this帖子中的建议删除命令中的空格。我还尝试按照 this 帖子中的建议重新编码 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

package.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
会生成所需的报告。

javascript automated-tests mocha.js cypress mochawesome
5个回答
0
投票

问题出在这一行:

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

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

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

应该可以工作


0
投票

请尝试这个“merge-report”:“mochawesome-merge cypress/reports/*.json > merged_report.txt > merged_report.json”,

这对我有用。


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"

尝试一下这个方法,应该可以...


0
投票

正确的命令是

yarn run mochawesome-merge cypress/reports/*.json -o cypress/reports/report.json

0
投票

更改命令:

mochawesome-merge cypress/reports/*.json > cypress/reports/report.json 

mochawesome-merge cypress/reports/*.json -o cypress/reports/report.json

>
将复制粘贴每个 json 的内容而不聚合内容,导致目标文件中的 json 结构错误。

© www.soinside.com 2019 - 2024. All rights reserved.