codeclimate / test-reporter

Code Climate Test Reporter
MIT License
156 stars 76 forks source link

cc-test-reporter sum-coverage BlobID mismatch #437

Closed lancep888 closed 4 years ago

lancep888 commented 4 years ago

Hello, I followed the example here: https://github.com/codeclimate/test-reporter/blob/master/examples/multiple_suites.md#example-1 to setup multiple test coverage reports.

ISSUE

When I try the cc-test-reporter sum-coverage, I keep getting a BlobID mismatch error.

my repo's structure is like this:

REPO |- f1 (directory with its own package.json and dependencies) |- f2 (directory with its own package.json and dependencies) |- f3 (directory with its own package.json and dependencies) |- f4 (directory with its own package.json and dependencies) |- f5 (directory with its own package.json and dependencies) |- f6 (directory with its own package.json and dependencies) |- f7 (directory with its own package.json and dependencies)

Workflow:

  1. CircleCi go to each F directory and runs the test coverage (npm run testcoverage)
  2. using cc-test-reporter format-coverage to store the reports into tmp directory
  3. circleCI persist_to_workspace to store the tmp directory
  4. After every job in run, the last step, upload-coverage, go to the tmp directory, where all 7 reports are stored, and try to sum them up, but there's where I get the issue.

Some code snippets:

workflows:
  version: 2

  generage-and-upload-test-coverage:
    jobs:
      - setup-test-coverage-env
      - test-coverage-1:
          requires:
            - setup-test-coverage-env
      - test-coverage-2:
          requires:
            - setup-test-coverage-env
      - test-coverage-3:
          requires:
            - setup-test-coverage-env
      - test-coverage-4:
          requires:
            - setup-test-coverage-env
      - test-coverage-5:
          requires:
            - setup-test-coverage-env
      - test-coverage-6:
          requires:
            - setup-test-coverage-env
      - test-coverage-7:
          requires:
            - setup-test-coverage-env
      - upload-coverage:
          requires:
             - test-coverage-1
             - test-coverage-2
             - test-coverage-3
             - test-coverage-4
             - test-coverage-5
             - test-coverage-6
             - test-coverage-7
defaults: &defaults
  docker:
    - image: circleci/node
- &prepare_test_coverage
    run:
      name: send test coverage report
      command: |
        # nyc report requires that nyc has already been run,
        # which creates the .nyc_output folder containing necessary data
        cd ~/project/$CIRCLE_PROJECT_REPONAME/<< parameters.function_name >>
        npm run testcoverage
        ~/project/tmp/cc-test-reporter format-coverage -t lcov -o ~/project/tmp/codeclimate.<< parameters.function_name >>.json coverage/lcov.info
        # ~/project/cc-test-reporter format-coverage -t lcov -o coverage/codeclimate.<< parameters.function_name >>.json coverage/lcov.info
commands:
  generate_test_coverage:
    description: "generate test coverage report"
    parameters:
      function_name:
        type: string
    steps:
      - *add_private_repo_cred
      - *checkout_code
      - attach_workspace:
          at: ~/project/tmp
      - *install_test_dependencies
      - *prepare_test_coverage
      - persist_to_workspace:
          root: tmp
          paths: 
            - codeclimate.<< parameters.function_name >>.json
setup-test-coverage-env:
    <<: *defaults
    steps:
      - run:
          name:  Download cc-test-reporter
          command: |
            mkdir -p tmp/
            curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./tmp/cc-test-reporter
            chmod +x ./tmp/cc-test-reporter
      - persist_to_workspace:
          root: tmp
          paths:
            - cc-test-reporter
  test-coverage-1:
    <<: *defaults
    steps:
      - generate_test_coverage:
          function_name: f1
  test-coverage-2:
    <<: *defaults
    steps:
      - generate_test_coverage:
          function_name: f2
  test-coverage-3:
    <<: *defaults
    steps:
      - generate_test_coverage:
          function_name: f3
  test-coverage-4:
    <<: *defaults
    steps:
      - generate_test_coverage:
          function_name: f4
  test-coverage-5:
    <<: *defaults
    steps:
      - generate_test_coverage:
          function_name: f5
  test-coverage-6:
    <<: *defaults
    steps:
      - generate_test_coverage:
          function_name: f6
  test-coverage-7:
    <<: *defaults
    steps:
      - generate_test_coverage:
          function_name: f7
  upload-coverage:
    <<: *defaults
    steps:
      - attach_workspace:
          at: ~/project/tmp
      - run:
          name: Upload coverage results to Code Climate
          command: |
            # The -p 7 here means there are 7 test coverage reports, if in future there are more, adjust the number accordingly
            ./tmp/cc-test-reporter sum-coverage tmp/codeclimate.*.json -p 7 -o tmp/codeclimate.total.json
            ./tmp/cc-test-reporter upload-coverage -i tmp/codeclimate.total.json
vferdiansyah commented 4 years ago

i just recently bumped into this same issue with similar folder structure and workflow. any solutions yet?

timhaley94 commented 4 years ago

I'm currently having this issue

timhaley94 commented 4 years ago

Ok! I solved this for myself.

I was getting this error because my two applications had files with the same name (i.e. src/config.js). The test reporter was confused because it thought these were the same file. All I had to do was use the --add-prefix parameter to let the reporter know they were in different directories.

So, for example, the command in my client directory went from

npm run test
./cc/cc-test-reporter format-coverage -t lcov -o cc/codeclimate.client.json coverage/lcov.info

to:

npm run test
./cc/cc-test-reporter format-coverage --add-prefix=client -t lcov -o cc/codeclimate.client.json coverage/lcov.info

A description of this flag should probably be added to the docs describing how to the multiple test suite documentation.

lancep888 commented 4 years ago

@timhaley94 Genius! I added the --add-prefix flag with the value as the names of each of my function, and I was able to upload the summed up coverage!

I agree the documentation should be updated to reflect this.

- &prepare_test_coverage
    run:
      name: send test coverage report
      command: |
        # nyc report requires that nyc has already been run,
        # which creates the .nyc_output folder containing necessary data
        cd ~/project/$CIRCLE_PROJECT_REPONAME/<< parameters.function_name >>
        npm run testcoverage
        ~/project/tmp/cc-test-reporter format-coverage --add-prefix=<< parameters.function_name >> -t lcov -o ~/project/tmp/codeclimate.<< parameters.function_name >>.json coverage/lcov.info