4

I tried removing spaces in command as suggested in this post. I also tried to reencode mochawesome.json as suggested in this post. But non worked.

You can find my json files here on gdrive.

When I try to merge them, I get following error:

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...

I am on Windows 10. Following are node related version:

>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"
  }
}

Update

I tried running just mochawesome-merge cypress/reports/*.json and it printed the merged json on the console. So I tried to first pipe merged json string to .txt file, then renaming .txt file to .json file and finally doing marge. Strangely it started working... So these are my updated package.json scripts:

  "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"
  }

Notice following two new scripts:

"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",

Running npm run final_report2 generates the desired report.

MsA
  • 2,599
  • 3
  • 22
  • 47
  • Please add your `package.json` – Alapan Das Sep 21 '21 at 16:54
  • Added package.json – MsA Sep 21 '21 at 17:36
  • Can you add space before and after `>`, `"merge":"mochawesome-merge cypress/reports/*.json > cypress/reports/merged_report.json",` and then try running `npm run merge`. Run the commands one by one in isolation. – Alapan Das Sep 21 '21 at 18:21
  • Well, initially I tried it with spaces only. It didnt work, so I tried it with removing spaces as suggested in [this](https://github.com/cypress-io/cypress/issues/5103#issuecomment-555366159) post. Also I just tried it once again. No luck. Btw, I tried running just `mochawesome-merge cypress/reports/*.json` and it prints the merged json on the console. So I tried to first pipe merged json string to `.txt` file, then renaming `.txt` file to `.json` file and finally doing `marge`. Strangely it started working... Going to add this to the post – MsA Sep 21 '21 at 20:23
  • Although a lot of information here seems not actually relevant to the error: the error is about incomplete JSON, from a specific file: it would be useful to show what the output of `npx mochawesome-merge cypress/reports/test/test/*.json` is on your system _without_ directing it into a file, to make sure it doesn't contain things like helpful stdout console logs like "starting run..." or "merge finished..." etc. – Mike 'Pomax' Kamermans Sep 21 '21 at 20:26

4 Answers4

0

The problem is this line :

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

You cant use an path for the result json.

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

should work

siouz
  • 1
0

please try this "merge-report":"mochawesome-merge cypress/reports/*.json > merged_report.txt > merged_report.json",

This worked for me.

BlueShadow
  • 49
  • 4
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"

Try it this way, this should work...

camille
  • 16,432
  • 18
  • 38
  • 60
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Nov 29 '21 at 07:50
0

Correct command is

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