Skip to content
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.

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

'cc-test-reporter after-build' Error message unclear #379

Closed
robrohan opened this issue Dec 7, 2018 · 8 comments
Closed

'cc-test-reporter after-build' Error message unclear #379

robrohan opened this issue Dec 7, 2018 · 8 comments
Assignees

Comments

@robrohan
Copy link

robrohan commented Dec 7, 2018

I am currently hitting this error while trying to setup code coverage for a typescript project using amazon code build:

$ xxxx ./cc-test-reporter after-build --debug -t lcov --exit-code $?
DEBU[0000] about to run format-coverage                 
DEBU[0000] using formatter lcov                         
DEBU[0000] checking search path  for lcov formatter     
DEBU[0000] checking search path coverage/lcov.info for lcov formatter 
DEBU[0000] couldn't load branch from ENV, trying git... 
DEBU[0000] couldn't load commit sha from ENV, trying git... 
DEBU[0000] couldn't load committed at from ENV, trying git... 
Error: could not find coverage info for source files

The lcov file exists, and using it I can generate a local HTML report correctly - so things are at least mostly right. This error isn't really helping me understand what the uploader has a problem with. It would be nice if it gave possible ways to fix the issue - or even what it thinks 'coverage info' is or 'source files' (is it looking for the source maps? the ts files?)

I'll try to dig through the code and sort it out for myself, but It'd be nicer if it was clearer.

@robrohan robrohan changed the title Error message unclear 'cc-test-reporter after-build' Error message unclear Dec 7, 2018
@robrohan
Copy link
Author

robrohan commented Dec 8, 2018

This turned out to be two things:

  • The build was misconfigured and was actually creating a json format file and uploading that for the lcov.info file. The 'Error: could not find coverage info for source files' should really have been a 'bad file format' type of error. But looking at the return data, it had a valid response, but the line count was zero (which is why that 'Error: could not find coverage info for source files' error was thrown).

  • By default codebuild will only do a git clone depth of 1. That was causing part of the process to get upset that it couldn't find the parent sha when doing that 'trying git...' part. (updating the setting in codebuild fixed that)

Once both of those were solved the coverage file seemed to upload fine. I can see it in Repo Settings > Test Coverage > Recent Reports, however it's not updating the badge or other parts of the UI so I am not 100% sure it working right just yet :-/

@filipesperandio
Copy link
Contributor

Is everything you mentioned applied to master already?
The badges reflect what you have for the master branch.

@robrohan
Copy link
Author

Yeah, it's all sync'd with master and looks like it's uploading, but no badges and no trends or anything. Here is the project: https://github.com/TheRohans/dapao (it could be that the project is so bad it just gave up :-D)

screen shot 2018-12-11 at 6 56 37 pm
screen shot 2018-12-11 at 6 56 46 pm
screen shot 2018-12-11 at 6 56 56 pm

@filipesperandio
Copy link
Contributor

Can you check if the report paths make sense?
Or post one example here for me to take a pick?
I've seen cases where the paths were off and others where the tool was generating reports with no coverage at all.

@robrohan
Copy link
Author

robrohan commented Dec 11, 2018

Ah, it looks like istanbul is doing full paths in the lcov.info file: SF:/Users/robrohan/Projects/dapao/src/collision/AABB.ts. What should they be? Given the root of the git repo:

.
├── LICENSE
├── Makefile
├── README.md
├── buildspec.yml
├── coverage
├── karma.conf.js
├── lib
├── node_modules
├── package-lock.json
├── package.json
├── publish.sh
├── src
├── tsconfig.json
├── tslint.json
└── webpack.config.js

I am guessing something more like SF:./src/collision/AABB.ts?

@filipesperandio
Copy link
Contributor

I guess that will fine if you tune the test reporter with a --prefix
https://docs.codeclimate.com/docs/configuring-test-coverage#section-running-tests-within-a-subdirectory

@robrohan
Copy link
Author

robrohan commented Dec 12, 2018

Awesome - that worked. The instructions are not very clear, or my reading comprehension isn't that great :)

(for future searchers) The output of the format-coverage command is a new file called codeclimate.json which describes the lcov.info file. The upload tool automagically looks for that file. The format coverage file does not modify the original lcov.info file so you likely don't want to use the --output switch.

Everything works now locally. The important parts of buildspec.yml:

...
 pre_build:
    commands:
      - curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
      - chmod +x ./cc-test-reporter
      - ./cc-test-reporter before-build
      - npm install
...
  build:
    commands:
      - make test # or however you want to make ./coverage/lcov.info
...
post_build:
    commands:
      - ./cc-test-reporter format-coverage -t lcov --prefix ${CODEBUILD_SRC_DIR} # auto looks for ./coverage/lcov.info
      - ./cc-test-reporter after-build -t lcov --exit-code $? # auto uploads ./coverage/lcov.info and ./coverage/codeclimate.json
...

@Vadorequest
Copy link

@robrohan Thank you, your feedback was very helpful!

Here is our buildspec.yml

version: 0.2

env:
  # Please refer to https://github.com/UnlyEd/slack-codebuild
  variables:
    SLACK_WEBHOOK_URL: "https://hooks.slack.com/services/XXX"
    CODEBUILD_NOTIFY_ONLY_IF_FAIL: 1
    CC_TEST_REPORTER_ID: XXX

phases:
  install:
    runtime-versions:
      nodejs: 10
    commands:
      - yarn --production=false
      - yarn global add @unly/slack-codebuild

  # See https://github.com/codeclimate/test-reporter/issues/379 for additional info regarding how to setup CodeBuild with CodeClimate
  pre_build:
    commands:
      - curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
      - chmod +x ./cc-test-reporter
      - ./cc-test-reporter before-build

  build:
    commands:
      - yarn test:coverage

  post_build:
    commands:
      - ./cc-test-reporter format-coverage -t lcov --prefix ${CODEBUILD_SRC_DIR} # Looks for ./coverage/lcov.info
      - ./cc-test-reporter after-build -t lcov --exit-code $? # Uploads ./coverage/lcov.info and ./coverage/codeclimate.json
    finally:
      - slack-codebuild

Additionally to this, it is very important to configure Git clone depth through CodeBuild GUI "Edit source"

image

The default value only fetches one commit, which result in coverage test failure as stated in #379 (comment), we figured a value of 5 seems to be optimal. (haven't encountered issues with just 5 commits, yet), but if you have any feedback on this I'm interested!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants