我尝试按照本文中的建议删除命令中的空格。我还尝试按照本文中的建议重新编码 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
生成所需的报告。