Skip to content
/ cypress Public
  • Notifications You must be signed in to change notification settings
  • Fork 3.1k
  • Star 46.4k
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Sign up for GitHub

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Jump to bottom

Incorrect JSON coding format after mochawesome-merge #5111

Open
AliceShi789654 opened this issue Sep 10, 2019 · 18 comments
Open

Incorrect JSON coding format after mochawesome-merge #5111

AliceShi789654 opened this issue Sep 10, 2019 · 18 comments
Labels
E2E Issue related to end-to-end testing existing workaround topic: reporters 📄 Triaged Issue has been routed to backlog. This is not a commitment to have it prioritized by the team.

Comments

@AliceShi789654
Copy link

AliceShi789654 commented Sep 10, 2019

Current behavior:

about : #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.

@AliceShi789654
Copy link
Author

AliceShi789654 commented Sep 10, 2019

I have updated the sample code and now it runs cypress:run successfully: https://github.com/AliceShi789654/Atest. But mochawesome-report-generator was still failed. Thanks.

PS C:\1_Code\Atest2\Atest> npm install

> cypress@3.4.1 postinstall C:\1_Code\Atest2\Atest\node_modules\cypress
> node index.js --exec install


Cypress 3.4.1 is installed in C:\Users\hshi\AppData\Local\Cypress\Cache\3.4.1

npm notice created a lockfile as package-lock.json. You should commit this file.
npm WARN eslint-plugin-chai-friendly@0.4.1 requires a peer of eslint@>=3.0.0 but none is installed. You must install peer dependencies yourself.
npm WARN eslint-plugin-cypress@2.6.1 requires a peer of eslint@>= 3.2.1 but none is installed. You must install peer dependencies yourself.
npm WARN Atest No description
npm WARN Atest No repository field.
npm WARN Atest No license field.

added 283 packages from 571 contributors and audited 619 packages in 26.22s
found 0 vulnerabilities

PS C:\1_Code\Atest2\Atest> npm run cypress:run

> @ cypress:run C:\1_Code\Atest2\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
    √ visit baidu home page and search for testerhome: (7311ms)


  1 passing (11s)

[mochawesome] Report JSON saved to C:\1_Code\Atest2\Atest\mochawesome-report\mochawesome.json


  (Results)

  ┌─────────────────────────────┐
  │ Tests:        1             │
  │ Passing:      1             │
  │ Failing:      0             │
  │ Pending:      0             │
  │ Skipped:      0             │
  │ Screenshots:  1             │
  │ Video:        true          │
  │ Duration:     10 seconds    │
  │ Spec Ran:     demo_baidu.ts │
  └─────────────────────────────┘


  (Screenshots)

  - C:\1_Code\Atest2\Atest\cypress\screenshots\demo_baidu.ts\My first test case for cypress -- visit baidu home page and search for testerhome.png (1000x1393)


  (Video)

  - Started processing:   Compressing to 32 CRF
  - Finished processing:  C:\1_Code\Atest2\Atest\cypress\videos\demo_baidu.ts.mp4 (2 seconds)


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


  My first test case for cypress
    √ Does not match! (44ms)


  1 passing (122ms)

[mochawesome] Report JSON saved to C:\1_Code\Atest2\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:  C:\1_Code\Atest2\Atest\cypress\videos\sample-spec.ts.mp4 (0 seconds)


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

  (Run Finished)


      Spec                                                Tests  Passing  Failing  Pending  Skipped
  ┌────────────────────────────────────────────────────────────────────────────────────────────────┐
  │ √ demo_baidu.ts                             00:10        1        1        -        -        - │
  ├────────────────────────────────────────────────────────────────────────────────────────────────┤
  │ √ sample-spec.ts                             98ms        1        1        -        -        - │
  └────────────────────────────────────────────────────────────────────────────────────────────────┘
    All specs passed!                           00:10        2        2        -        -        -

PS C:\1_Code\Atest2\Atest> npx mochawesome-merge > mochawesome.json
PS C:\1_Code\Atest2\Atest> npx mochawesome-report-generator mochawesome.json
npx: installed 50 in 6.986s

✘ Some files could not be processed:
mochawesome.json
  Unexpected token � in JSON at position 0
PS C:\1_Code\Atest2\Atest>

@maximumsnow
Copy link

maximumsnow commented Sep 11, 2019

I believe I'm seeing the same issue. I added comments to issue #5103

I'm not going to duplicate them here.

@HareemManzoor
Copy link

HareemManzoor commented Sep 15, 2019

Getting same issue.
image
@jennifer-shehane

@maximumsnow maximumsnow mentioned this issue Sep 18, 2019
Incorrect JSON coding format after mochawesome-merge #5103
Closed
@HareemManzoor
Copy link

HareemManzoor commented Oct 1, 2019

@maximumsnow Add following lines of code to your package.json file under scripts tag.

"scripts": {
  "delete-mochawesome-folder":"rm -f mochawesome-report/*.json",
  "e2e_mochawesome": "yarn cypress run --spec cypress/integration/Tests/*.js",
  "merge-json":"npx mochawesome-merge --reportDir mochawesome-report > mochawesome1.json",
  "html-generator": " npx mochawesome-report-generator mochawesome1.json"
}
  1. Make sure you have installed
npm install --save-dev mocha mochawesome mochawesome-merge mochawesome-report-generator
  1. Make sure all the previous .json files are removed from the mochawesome-report folder as well as from cypress main folder.

Now execute above commands in sequence and here you go ;)

image

@prudhvidandamudi
Copy link

prudhvidandamudi commented Oct 23, 2019

facing same issue, anyone has any solution??

image

@HareemManzoor
Copy link

HareemManzoor commented Oct 25, 2019

@prudhvidandamudi please make sure that you are removing all the previous json reports. Also can you please the folder structure? Just want to make sure that you have placed your json report in correct folder. Thanks in advance :)

@jennifer-shehane jennifer-shehane added the topic: reporters 📄 label Oct 25, 2019
@mylearning1005
Copy link

mylearning1005 commented Apr 16, 2020

I am getting the following error : Can some one please help

PS C:\Cypress_Practice_tests\UITest> npx mochawesome-report-generator mochawesome.json
npx: installed 48 in 6.446s

✘ Some files could not be processed:
mochawesome.json
  Unexpected token � in JSON at position 0
PS C:\Cypress_Practice_tests\CalculateFunding-UITest> 

package.json

  "devDependencies": {
    "cypress": "^4.3.0",
    "mocha": "5.2.0",
    "mochawesome": "4.1.0",
    "mochawesome-merge": "4.0.3",
    "mochawesome-report-generator": "4.1.0"
  }

cypress.json

{
    "reporter": "mochawesome",
    "reporterOptions": {
      "reportDir": "cypress/results",
      "overwrite": false,
      "html": false,
      "json": true
    }
  }

@mstephano
Copy link

mstephano commented May 12, 2020

I had same issue with Unexpected token while trying to create the report on Windows 10. Here is my solution on another issue: Antontelesh/mochawesome-merge#6 (comment)

@automationJatinder
Copy link

automationJatinder commented Jul 7, 2020

I am still facing this problem (Unexpected token � in JSON at position 0) when using marge command to create HTML file. Does anyone has a solution for this?

@gaurav05153
Copy link

gaurav05153 commented Jul 23, 2020

@maximumsnow Add following lines of code to your package.json file under scripts tag.

"scripts": {
  "delete-mochawesome-folder":"rm -f mochawesome-report/*.json",
  "e2e_mochawesome": "yarn cypress run --spec cypress/integration/Tests/*.js",
  "merge-json":"npx mochawesome-merge --reportDir mochawesome-report > mochawesome1.json",
  "html-generator": " npx mochawesome-report-generator mochawesome1.json"
}
  1. Make sure you have installed
npm install --save-dev mocha mochawesome mochawesome-merge mochawesome-report-generator
  1. Make sure all the previous .json files are removed from the mochawesome-report folder as well as from cypress main folder.

Now execute above commands in sequence and here you go ;)

image

@gaurav05153
Copy link

gaurav05153 commented Jul 23, 2020

I tried your approach but "html-generator" step didn't work for me. Still I am on same issue where different report jsons are created but generation of a combined HTML report didn't work for me.
marge command (npx marge mochawesome.json) is also throwing below error:
mochawesomeconsolidated.json
Unexpected token � in JSON at position 0

@gaurav05153
Copy link

gaurav05153 commented Jul 23, 2020

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:

  1. install cypress-mochawesome-reporter
  2. add below line in your configuration file:
    "reporter": "cypress-mochawesome-reporter"
  3. Add import 'cypress-mochawesome-reporter/register' to index.js inside support folder
  4. run your all the test files(.js files)
  5. at last,
    npm 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.

@nids2307
Copy link

nids2307 commented Sep 9, 2020

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:

  1. install cypress-mochawesome-reporter
  2. add below line in your configuration file:
    "reporter": "cypress-mochawesome-reporter"
  3. Add import 'cypress-mochawesome-reporter/register' to index.js inside support folder
  4. run your all the test files(.js files)
  5. at last,
    npm 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.

When I try to install cypress-mochawesome-reporter, I see the following error:
yarn add -D cypress-mochaewsome-reporter
yarn add v1.22.4
[1/4] Resolving packages...
error An unexpected error occurred: " https://repo.website.com/artifactory/api/npm/npmjs/cypress-mochaewsome-reporter: not_found".

@hnnesv
Copy link

hnnesv commented Aug 16, 2021

In 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:

mochawesome-merge .\report\*.json > .\merged.json # doesn't work

For me the fix was to instead use something as follows to explicitly use ASCII:

mochawesome-merge .\report\*.json | out-file -encoding ascii .\merged.json

@mflynn001
Copy link

mflynn001 commented Mar 22, 2022

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

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

@cypress-bot cypress-bot bot added the stage: backlog label Apr 29, 2022
@mustaf19
Copy link

mustaf19 commented May 12, 2023

Its an issue since ancient times.. I still have this issue..

@nagash77
Copy link
Contributor

nagash77 commented May 12, 2023

@mustaf19 did the solution @mflynn001 shared work for you?

@nagash77 nagash77 added the existing workaround label May 12, 2023
@nagash77 nagash77 self-assigned this May 12, 2023
@nagash77 nagash77 added E2E Issue related to end-to-end testing Triaged Issue has been routed to backlog. This is not a commitment to have it prioritized by the team. labels May 17, 2023
@nagash77 nagash77 removed their assignment May 17, 2023
@isacraraujo
Copy link

isacraraujo commented May 23, 2023

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

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

Amazing! I'm using Mochawesome in Cypress, and this simple detail solved my problem!

@jennifer-shehane jennifer-shehane removed the stage: backlog label Nov 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
E2E Issue related to end-to-end testing existing workaround topic: reporters 📄 Triaged Issue has been routed to backlog. This is not a commitment to have it prioritized by the team.
Projects
None yet
Development

No branches or pull requests

15 participants
@nagash77 @jennifer-shehane @hnnesv @maximumsnow @mstephano @AliceShi789654 @HareemManzoor @automationJatinder @prudhvidandamudi @isacraraujo @mustaf19 @nids2307 @gaurav05153 @mylearning1005 @mflynn001

Footer

© 2024 GitHub, Inc.

哆哆女性网鬼打鬼电影给家起个有诗意的名字香火店起什么名字好起姓名测试打分结果打分1518起名圆圆含义avatarifymylifestyle女孩起名 然个人设计工作室起名字琉璃免费观看电视剧最有名的元宵节古诗汇通单号查询诸天大道宗如何起麻辣烫店名属鼠的男孩起个什么名字关于新起点的名言卧底3给小狗怎么起名51job.com招聘网属马起名宜忌用字有大全九江公司起名起1个商标名起名字吉凶预测功夫面4851宝宝怎么样起名字性感沙滩3中文版药窕淑女女孩起名梓君的含义监禁风暴淀粉肠小王子日销售额涨超10倍罗斯否认插足凯特王妃婚姻不负春光新的一天从800个哈欠开始有个姐真把千机伞做出来了国产伟哥去年销售近13亿充个话费竟沦为间接洗钱工具重庆警方辟谣“男子杀人焚尸”男子给前妻转账 现任妻子起诉要回春分繁花正当时呼北高速交通事故已致14人死亡杨洋拄拐现身医院月嫂回应掌掴婴儿是在赶虫子男孩疑遭霸凌 家长讨说法被踢出群因自嘲式简历走红的教授更新简介网友建议重庆地铁不准乘客携带菜筐清明节放假3天调休1天郑州一火锅店爆改成麻辣烫店19岁小伙救下5人后溺亡 多方发声两大学生合买彩票中奖一人不认账张家界的山上“长”满了韩国人?单亲妈妈陷入热恋 14岁儿子报警#春分立蛋大挑战#青海通报栏杆断裂小学生跌落住进ICU代拍被何赛飞拿着魔杖追着打315晚会后胖东来又人满为患了当地回应沈阳致3死车祸车主疑毒驾武汉大学樱花即将进入盛花期张立群任西安交通大学校长为江西彩礼“减负”的“试婚人”网友洛杉矶偶遇贾玲倪萍分享减重40斤方法男孩8年未见母亲被告知被遗忘小米汽车超级工厂正式揭幕周杰伦一审败诉网易特朗普谈“凯特王妃P图照”考生莫言也上北大硕士复试名单了妈妈回应孩子在校撞护栏坠楼恒大被罚41.75亿到底怎么缴男子持台球杆殴打2名女店员被抓校方回应护栏损坏小学生课间坠楼外国人感慨凌晨的中国很安全火箭最近9战8胜1负王树国3次鞠躬告别西交大师生房客欠租失踪 房东直发愁萧美琴窜访捷克 外交部回应山西省委原副书记商黎光被逮捕阿根廷将发行1万与2万面值的纸币英国王室又一合照被质疑P图男子被猫抓伤后确诊“猫抓病”

哆哆女性网 XML地图 TXT地图 虚拟主机 SEO 网站制作 网站优化