Antontelesh / mochawesome-merge

Merge several Mochawesome JSON reports
MIT License
85 stars 16 forks source link

JSON files not found. #51

Closed akshaysgithub closed 4 years ago

akshaysgithub commented 4 years ago

Hello,

I want to create a single html file with the library. It's failing to find the json files. I can see that the json files are generated.

Error :

2 Running command yarn mochawesome-merge > mochawesome.json

I tried going one directory up as well, no luck

Running command cd $PWD/cypress/report/

I can see that the json file is there.


mochawesome] Report JSON saved to /codebuild/output/src308570643/src/github.com/company/magento-cypress/cypress/report/mochawesome-report/mochawesome_08142020_142823.json

[mochawesome] Report HTML saved to /codebuild/output/src308570643/src/github.com/company/magento-cypress/cypress/report/mochawesome-report/mochawesome_08142020_142823.html

Buildspec.yml


version: 0.2
env:
  variables:
    BUILD_DIR: "."
phases:
  install:
    runtime-versions:
      nodejs: 10
    commands:
      - npm i
      - apt-get update && apt-get install -y yarn libgtk2.0-0 libnotify-dev libgconf-2-4 libnss3 libxss1 libasound2 xvfb
      - yarn install
  build:
    commands:
      - ls -al
      - pwd
      - npx wait-on http://localhost:3000 &
      - npx cypress run --env MAGENTO_HOST=COMPANYDOMAIN.com
      - cd $PWD/cypress/report/
      - yarn add mocha@5.2.0 mochawesome mochawesome-merge
      - yarn mochawesome-merge > mochawesome.json
      - yarn marge mochawesome.json
      - aws s3 sync $PWD/cypress/report/mochawesome-report/ s3://cypress.company.com/

What am I doing wrong? Any ideas. Thank you. :-)

Antontelesh commented 4 years ago

@akshaysgithub could you send the actual error being thrown?

akshaysgithub commented 4 years ago

@akshaysgithub could you send the actual error being thrown?

[Container] 2020/08/14 14:28:32 Running command yarn mochawesome-merge > mochawesome.json ERROR: Failed to merge reports Error: Pattern ./mochawesome-report/mochawesome*.json matched no report files at pattern (/codebuild/output/src308570643/src/github.com/company/magento-cypress/node_modules/mochawesome-merge/lib/index.js:14:11) at Array.map () at items (/codebuild/output/src308570643/src/github.com/company/magento-cypress/node_modules/mochawesome-merge/lib/utils.js:3:46) at merge (/codebuild/output/src308570643/src/github.com/company/magento-cypress/node_modules/mochawesome-merge/lib/index.js:59:17) at Object. (/codebuild/output/src308570643/src/github.com/company/magento-cypress/node_modules/mochawesome-merge/bin/mochawesome-merge.js:32:1) at Module._compile (internal/modules/cjs/loader.js:778:30) at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10) at Module.load (internal/modules/cjs/loader.js:653:32) at tryModuleLoad (internal/modules/cjs/loader.js:593:12) at Function.Module._load (internal/modules/cjs/loader.js:585:3) error Command failed with exit code 1.

Antontelesh commented 4 years ago

Could you try providing a path pattern yourself instead of changing directory to $PWD/cypress/report?

Something like this:


build:
    commands:
      - ls -al
      - pwd
      - npx wait-on http://localhost:3000 &
      - npx cypress run --env MAGENTO_HOST=COMPANYDOMAIN.com
      - yarn add mocha@5.2.0 mochawesome mochawesome-merge
      - yarn mochawesome-merge ./cypress/report/mochawesome-report/*.json > ./cypress/report/mochawesome.json
      - yarn marge mochawesome.json
      - aws s3 sync $PWD/cypress/report/mochawesome-report/ s3://cypress.company.com/
akshaysgithub commented 4 years ago

Could you try providing a path pattern yourself instead of changing directory to $PWD/cypress/report?

Something like this:


build:
    commands:
      - ls -al
      - pwd
      - npx wait-on http://localhost:3000 &
      - npx cypress run --env MAGENTO_HOST=COMPANYDOMAIN.com
      - yarn add mocha@5.2.0 mochawesome mochawesome-merge
      - yarn mochawesome-merge ./cypress/report/mochawesome-report/*.json > ./cypress/report/mochawesome.json
      - yarn marge mochawesome.json
      - aws s3 sync $PWD/cypress/report/mochawesome-report/ s3://cypress.company.com/

The changes almost worked, the merge worked, but the marge command is giving issues.

I have tried 2 options, one is to CD into the directory and run

yarn marge mochawesome.json

and

      - yarn mochawesome-merge ./cypress/report/mochawesome-report/*.json > ./cypress/report/mochawesome-report/mochawesome.json
      - yarn marge ./cypress/report/mochawesome-report/mochawesome.json

When I try cd into directory, it says file not found. I can confirm there is mochawesome.json in the mentioned directory.


 Running command yarn mochawesome-merge ./cypress/report/mochawesome-report/*.json > ./cypress/report/mochawesome-report/mochawesome.json
[Container] 2020/08/14 18:01:45 Running command yarn marge ./cypress/report/mochawesome-report/mochawesome.json
yarn run v1.22.4
$ /codebuild/output/src645161999/src/github.com/company/magento-cypress/node_modules/.bin/marge ./cypress/report/mochawesome-report/mochawesome.json

✘ Some files could not be processed:./cypress/report/mochawesome-report/mochawesome.json
  Unexpected token y in JSON at position 0

error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.[Container] 2020/08/14 18:01:46 Command did not exit successfully yarn marge ./cypress/report/mochawesome-report/mochawesome.json exit status 1
[Container] 2020/08/14 18:01:46 Phase complete: BUILD State: FAILED
[Container] 2020/08/14 18:01:46 Phase context status code: COMMAND_EXECUTION_ERROR Message: Error while executing command: yarn marge ./cypress/report/mochawesome-report/mochawesome.json. Reason: exit status 1
[Container] 2020/08/14 18:01:46 Entering phase POST_BUILD
[Container] 2020/08/14 18:01:46 Phase complete: POST_BUILD State: SUCCEEDED
[Container] 2020/08/14 18:01:46 Phase context status code:  Message: 

Many many thanks for all your help. :-)

Antontelesh commented 4 years ago

So, the first error is probably because when you run yarn command_name it runs command_name from within your project root, regardless if you do cd folder-name before. That’s my assumption.

The second error is easily fixable. It happens because if you use the > operator to write to the file, it will write all the yarn output to that file, including the first console message before actually running the command. That generates invalid JSON.

To fix it, just change the > operator to the -o option, like the following:

yarn mochawesome-merge ./cypress/report/*.json -o ./cypress/report/mochawesome-report/mochawesome.json
akshaysgithub commented 4 years ago

So, the first error is probably because when you run yarn command_name it runs command_name from within your project root, regardless if you do cd folder-name before. That’s my assumption.

The second error is easily fixable. It happens because if you use the > operator to write to the file, it will write all the yarn output to that file, including the first console message before actually running the command. That generates invalid JSON.

To fix it, just change the > operator to the -o option, like the following:

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

Adding the -o fixed the issues. Thanks a lot. Thank you very much. :-)