Tag: Karma

Setup ngTest step on Bitrise.io

Bitrise’s buit-in karma jasmine testRunner seems out-of-date, every time gives error:

‘@angular-devkit/build-angular/plugins/karma’ karma plugin is meant to be used from within Angular CLI and will not work correctly outside of it.

It’s not hard to create a script step, things to do:

1. Download chrome.

brew update && brew cask install chromedriver google-chrome

Quite often, we got checksum error, possible cause, network cache, solution: directly run script from github repo, ideally from your forked repo to avoid cache.

brew cask install https://raw.githubusercontent.com/maodd/homebrew-cask/master/Casks/google-chrome.rb

2. Run ngTest, non-watch mode, so it can close itself after done.

./node_modules/@angular/cli/bin/ng test –watch=false –code-coverage

3. (Optional) Collect code coverage report.

The challenge here is Bitrise can deploy a folder as artifact, we need to find a way display report in single html file, also to keep the original multiple test files as many as possible.

We use a html-inline npm package to compact test report files, also zip the whole test result into a single file, and artifact both files.

if [ -d "$BITRISE_SOURCE_DIR/coverage" ]; then
   zip -r $BITRISE_DEPLOY_DIR/coverage.zip $BITRISE_SOURCE_DIR/coverage
   npm i -g html-inline
   html-inline -i $BITRISE_SOURCE_DIR/coverage/index.html -o coverage.html
   cp coverage.html $BITRISE_DEPLOY_DIR

The artifacts for each build looks like this:

Screen Shot 2020-04-03 at 9.20.20 AM.png

Subfolder links inside the coverage report won’t work, but it’s good enough for us, until we can find a better html-package tool.