Cypress: Incorrect JSON coding format after mochawesome-merge

Created on 9 Sep 2019  ยท  13Comments  ยท  Source: cypress-io/cypress

Steps to reproduce: (app code and test code)

package.json:

script {"cypress-run": "cypress run"}

cypress.json:

{
 "reporter": "mochawesome",
  "reporterOptions": {
    "overwrite": false,
    "html": false,
    "json": true
  }
}

run the following command:

PS C:\1_Code\Atest> npm install
PS C:\1_Code\Atest> npm run cypress:run
  --  Report JSON saved to .\mochawesome-report, mochawesome.json, mochawesome_001.json, mochawesome_002.json
PS C:\1_Code\Atest> npx mochawesome-merge  > mochawesome.json
  --  merged JSON saved to .\mochawesome.json
PS C:\1_Code\Atest> npx mochawesome-report-generator mochawesome.json
npx: installed 50 in 6.289s
โœ˜ Some files could not be processed:
mochawesome.json
  Unexpected token ๏ฟฝ in JSON at position 0

mochawesome.json encoding: Unincode

how to resolved it?

Versions

"cypress": "^3.4.1",
"mocha": "^5.2.0",
    "mocha-junit-reporter": "^1.23.1",
    "mocha-multi-reporters": "^1.1.7",
    "mochawesome": "^4.1.0",
    "mochawesome-merge": "^2.0.1",
    "mochawesome-report-generator": "^4.0.1",

Most helpful comment

Had the same issue. But got it solved after removing space.

npx mochawesome-merge --reportDir cypress/result**s > m**ochawesome.json
npx mochawesome-merge --reportDir cypress/result**s>m**ochawesome.json

All 13 comments

I was unable to recreate the issue as described. My log on npm run cypress:run Maybe make sure you don't have any conflicting modules globally installed.

npm run cypress:run

> @ cypress:run /Users/jennifer/Dev/Atest
> cypress run


====================================================================================================

  (Run Starting)

  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
  โ”‚ Cypress:    3.4.1                                                                              โ”‚
  โ”‚ Browser:    Electron 61 (headless)                                                             โ”‚
  โ”‚ Specs:      2 found (demo_baidu.ts, sample-spec.ts)                                            โ”‚
  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜


โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€

  Running: demo_baidu.ts...                                                                (1 of 2)


  My first test case for cypress
    1) visit baidu home page and search for testerhome:


  0 passing (6s)
  1 failing

  1) My first test case for cypress
       visit baidu home page and search for testerhome::
     Uncaught Error: Script error.

Cypress detected that an uncaught error was thrown from a cross origin script.

We cannot provide you the stack trace, line number, or file where this error occurred.

Check your Developer Tools Console for the actual error - it should be printed there.

It's possible to enable debugging these scripts by adding the 'crossorigin' attribute and setting a CORS header.

https://on.cypress.io/cross-origin-script-error

This error originated from your application code, not from Cypress.

When Cypress detects uncaught errors originating from your application it will automatically fail the current test.

This behavior is configurable, and you can choose to turn this off by listening to the 'uncaught:exception' event.

https://on.cypress.io/uncaught-exception-from-application
      at createErrFromMsg (http://www.baidu.com/__cypress/runner/cypress_runner.js:76831:14)
      at Object.createUncaughtException (http://www.baidu.com/__cypress/runner/cypress_runner.js:76836:13)
      at Object.onUncaughtException (http://www.baidu.com/__cypress/runner/cypress_runner.js:80407:20)
      at onError (http://www.baidu.com/__cypress/runner/cypress_runner.js:79633:39)



[mochawesome] Report JSON saved to /Users/jennifer/Dev/Atest/mochawesome-report/mochawesome.json


  (Results)

  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
  โ”‚ Tests:        1             โ”‚
  โ”‚ Passing:      0             โ”‚
  โ”‚ Failing:      1             โ”‚
  โ”‚ Pending:      0             โ”‚
  โ”‚ Skipped:      0             โ”‚
  โ”‚ Screenshots:  1             โ”‚
  โ”‚ Video:        true          โ”‚
  โ”‚ Duration:     5 seconds     โ”‚
  โ”‚ Spec Ran:     demo_baidu.ts โ”‚
  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜


  (Screenshots)

  - /Users/jennifer/Dev/Atest/cypress/screenshots/demo_baidu.ts/My first test case for cypress -- visit baidu home page and search for testerhome (failed).png (1280x720)


  (Video)

  - Started processing:   Compressing to 32 CRF
  - Finished processing:  /Users/jennifer/Dev/Atest/cypress/videos/demo_baidu.ts.mp4 (0 seconds)


โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€

  Running: sample-spec.ts...                                                               (2 of 2)


  My first test case for cypress
    โœ“ Does not match!


  1 passing (47ms)

[mochawesome] Report JSON saved to /Users/jennifer/Dev/Atest/mochawesome-report/mochawesome_001.json


  (Results)

  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
  โ”‚ Tests:        1              โ”‚
  โ”‚ Passing:      1              โ”‚
  โ”‚ Failing:      0              โ”‚
  โ”‚ Pending:      0              โ”‚
  โ”‚ Skipped:      0              โ”‚
  โ”‚ Screenshots:  0              โ”‚
  โ”‚ Video:        true           โ”‚
  โ”‚ Duration:     0 seconds      โ”‚
  โ”‚ Spec Ran:     sample-spec.ts โ”‚
  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜


  (Video)

  - Started processing:   Compressing to 32 CRF
  - Finished processing:  /Users/jennifer/Dev/Atest/cypress/videos/sample-spec.ts.mp4 (0 seconds)


====================================================================================================

  (Run Finished)


      Spec                                                Tests  Passing  Failing  Pending  Skipped
  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
  โ”‚ โœ– demo_baidu.ts                             00:05        1        -        1        -        - โ”‚
  โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
  โ”‚ โœ” sample-spec.ts                             46ms        1        1        -        -        - โ”‚
  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
    1 of 2 failed (50%)                         00:06        2        1        1        -        -

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! @ cypress:run: `cypress run`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the @ cypress:run script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/jennifer/.npm/_logs/2019-09-09T14_22_06_614Z-debug.log

Unfortunately we have to close this issue as there is not enough information to reproduce the problem. This does not mean that your issue is not happening - it just means that we do not have a path to move forward.

Please comment in this issue with a reproducible example and we will reopen the issue. ๐Ÿ™

I'm looking at setting up a POC with Cypress and I'm going through the steps outlined on https://docs.cypress.io/guides/tooling/reporters.html#Multiple-reporters-examples

I believe I am having the same issue. I'm merging the reports for all the example spec files that cypress loads so they are all passing (if that makes any difference).

Running: npx mochawesome-merge --reportDir cypress/results > mochawesome.json
creates the mochawesome.json but it appears to be malformed because when I run the next command: npx mochawesome-report-generator mochawesome.json
I get "Unexpected token ๏ฟฝ in JSON at position 0"

Windows v10.0.14393
Nodejs v10.16.3

"cypress": "^3.4.1",
"mocha": "^5.2.0",
"mocha-junit-reporter": "^1.23.1",
"mocha-multi-reporters": "^1.1.7",
"mochawesome": "^4.1.0",
"mochawesome-merge": "^2.0.1",
"mochawesome-report-generator": "^4.0.1"

An update... I can open the "merged" json file in VSCode and copy the contents to a new json file and the mochawesome-report-generator processes it without error. So there is something about that "merged" file that VSCode didn't load into the editor to be copied to the new file is causing the error.

duplication steps:

  1. Create new folder named cypress-error
  2. run npm init -y
  3. run npm install cypress [email protected] mocha-junit-reporter mocha-multi-reporters mochawesome mochawesome-merge mochawesome-report-generator --save-dev
  4. run ./node_modules/.bin/cypress open
  5. close the cypress UI
  6. Add the following to cypress.json
    { "reporter": "mochawesome", "reporterOptions": { "reportDir": "cypress/results", "overwrite": false, "html": false, "json": true } }
  7. Replace the scripts section of package.json with the following *Note the delete:reports command has been changed for windows so it doesn't match what is in https://docs.cypress.io/guides/tooling/reporters.html#Multiple-reporters-examples
    "scripts": { "cy:run": "cypress run", "delete:reports": "del /F/Q/S cypress\\results\\*.*", "prereport": "npm run delete:reports", "report": "cypress run" }
  8. run node run report
  9. verify json files were created in cypress/results
  10. run npx mochawesome-merge --reportDir cypress/results > merged.json
  11. run npx mochawesome-report-generator merged.json

Result:
โœ˜ Some files could not be processed:
merged.json
Unexpected token ๏ฟฝ in JSON at position 0

I have the same issue

I'm looking at setting up a POC with Cypress and I'm going through the steps outlined on https://docs.cypress.io/guides/tooling/reporters.html#Multiple-reporters-examples

I believe I am having the same issue. I'm merging the reports for all the example spec files that cypress loads so they are all passing (if that makes any difference).

Running: npx mochawesome-merge --reportDir cypress/results > mochawesome.json
creates the mochawesome.json but it appears to be malformed because when I run the next command: npx mochawesome-report-generator mochawesome.json
I get "Unexpected token ๏ฟฝ in JSON at position 0"

Windows v10.0.14393
Nodejs v10.16.3

"cypress": "^3.4.1",
"mocha": "^5.2.0",
"mocha-junit-reporter": "^1.23.1",
"mocha-multi-reporters": "^1.1.7",
"mochawesome": "^4.1.0",
"mochawesome-merge": "^2.0.1",
"mochawesome-report-generator": "^4.0.1"

I have the same issue. I'm not sure why the Json file format result of the merge is UTF-16. But if I create a new one and copy/paste and save in a new Json, marge works ok and the HTML file is created.

@jennifer-shehane maybe we can reopen this issue or create a new one.

This issue is also reported as #5111 which is still open.

Had the same issue. But got it solved after removing space.

npx mochawesome-merge --reportDir cypress/result**s > m**ochawesome.json
npx mochawesome-merge --reportDir cypress/result**s>m**ochawesome.json

@thinkx-23 Thanks so much for the comment! i'll try this week and i'll give you some feedback.

update: It's working!

Had the same issue. But got it solved after removing space.
npx mochawesome-merge --reportDir cypress/results > mochawesome.json
npx mochawesome-merge --reportDir cypress/results>mochawesome.json

Thank you so much . It worked !!!

Removing spaces did not work for me on Windows 10. Here is my solution on another issue:
https://github.com/Antontelesh/mochawesome-merge/issues/6#issuecomment-627496076

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

ERROR: Failed to merge reports

SyntaxError: cypress/reports/output.json: Unexpected end of JSON input
    at JSON.parse (<anonymous>)
    at C:\Mayank\Cypress_Code\node_modules\jsonfile\index.js:33:18
    at C:\Mayank\Cypress_Code\node_modules\graceful-fs\graceful-fs.js:123:16
    at FSReqCallback.readFileAfterClose [as oncomplete] (internal/fs/read_file_context.js:63:3)

Anyone have any solutions for the above issue in Windows 10

Removing spaces did not work for me on Windows 10. Here is my solution on another issue:
Antontelesh/mochawesome-merge#6 (comment)

I used the json online editor, opened the file and without making changes, saved it at the same location and it worked!

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

ERROR: Failed to merge reports

SyntaxError: cypress/reports/output.json: Unexpected end of JSON input
    at JSON.parse (<anonymous>)
    at C:\Mayank\Cypress_Code\node_modules\jsonfile\index.js:33:18
    at C:\Mayank\Cypress_Code\node_modules\graceful-fs\graceful-fs.js:123:16
    at FSReqCallback.readFileAfterClose [as oncomplete] (internal/fs/read_file_context.js:63:3)

Anyone have any solutions for the above issue in Windows 10

Open your 'package.json' file and make these three definations under scripts scetion,

"scripts": {

"cypress:test": "npx cypress run -b chrome -r mochawesome -s '.\\cypress\\integration\\examples\\api.js\\'",
"merge_reports": "mochawesome-merge cypress/report/mochawesome-report/*.json > cypress/report/output.json",
"report": "marge cypress/report/output.json --reportDir ./ --inline"

},

Now save the project and execute these scripts as,
' npm run cypress:test '
' npm run merge_reports '
' npm run report '

Copy the html file link from test execution and open it in browser.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jennifer-shehane picture jennifer-shehane  ยท  3Comments

weskor picture weskor  ยท  3Comments

tahayk picture tahayk  ยท  3Comments

igorpavlov picture igorpavlov  ยท  3Comments

egucciar picture egucciar  ยท  3Comments