cypress: Incorrect JSON coding format after mochawesome-merge
Current behavior:
about : https://github.com/cypress-io/cypress/issues/5103
Steps to reproduce: (app code and test code)
Although there were errors in the log , but the result is generated. You can get two .json files in 'mochawesome-report '.
Then merge two .json into one to generate in the root directory.
PS C:\1_Code\Atest> npx mochawesome-merge > mochawesome.json
Finally, run the command to generate report failed :
PS C:\1_Code\Atest2> npx mochawesome-report-generator mochawesome.json
npx: installed 50 in 5.759s
✘ Some files could not be processed:
mochawesome.json
Unexpected token � in JSON at position 0
I found that the JSON encoding format after merge was incorrect, and I didn’t want to change it manually. I needed to integrate it into automated deployment and test scripts.
About this issue
- Original URL
- State: open
- Created 5 years ago
- Comments: 18 (1 by maintainers)
If anyone is still struggling with this issue, the solution can be found here: https://www.npmjs.com/package/mochawesome-merge
you need to use the following syntax now to avoid the JSON coding format issue:
npx mochawesome-merge mochawesome-report/.*json -o mochawesome.jsonthe below syntax is technically legacy, but I still seem to run into the issue mentioned here when i use it, so do not use this:
npx mochawesome-merge mochawesome-report/*.json > mochawesome.jsonIn case this is helpful for anyone, I ran into the same issue as the original summary and looks like the issue was related to how Powershell encodes the output to file:
For me the fix was to instead use something as follows to explicitly use ASCII:
Guys, I found the best solution of this problem. With this solution, we don’t have to do much with the configurations or setup.
Solution is the “cypress-mochawesome-reporter”.
It will handle all the corner cases which we were facing with generating mochawesome report, then merge and then marge to consolidate all the jsons. Steps to do:
import 'cypress-mochawesome-reporter/register'toindex.jsinside support foldernpm run generate-mochawesome-report(You can add above line to scripts of your package.json file)It will create a folder results/html where you can find your consolidated report named “mochasome.html”
Just try it, you will have a smile while looking into the consolidate report with all ease. Here is the bonus, you will also be able to see screenshots.
Hope, it will help you.
@mustaf19 did the solution @mflynn001 shared work for you?
I had same issue with Unexpected token while trying to create the report on Windows 10. Here is my solution on another issue: https://github.com/Antontelesh/mochawesome-merge/issues/6#issuecomment-627496076
@maximumsnow Add following lines of code to your package.json file under scripts tag.
.jsonfiles are removed from themochawesome-reportfolder as well as from cypress main folder.Now execute above commands in sequence and here you go 😉
I believe I’m seeing the same issue. I added comments to issue #5103
I’m not going to duplicate them here.