I am trying to generate an nyc/istanbul coverage report on my project (using mocha). I can get this to run from the command line with the following command:
npm test --reporter mocha-bamboo-reporter test/
which is essentially running
nyc mocha --recursive "mocha-bamboo-reporter" "test/"
The tricky part is that I need to run this in bamboo which doesn't seem to support chaining of/multiple commands in one task.
My bamboo config has a mocha test runner:
node_modules/mocha/bin/mocha --reporter mocha-bamboo-reporter --recursive
I have an istanbul/nyc instrument task:
./node_modules/nyc/bin/nyc.js instrument test/ .nyc_output
And then a coverage report task:
./node_modules/nyc/bin/nyc.js report
When this runs I get no data in the report file:
25-Apr-2018 14:27:28 ----------|----------|----------|----------|----------|-------------------|
25-Apr-2018 14:27:28 File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s |
25-Apr-2018 14:27:28 ----------|----------|----------|----------|----------|-------------------|
25-Apr-2018 14:27:28 All files | 0 | 0 | 0 | 0 | |
25-Apr-2018 14:27:28 ----------|----------|----------|----------|----------|-------------------|
Any help would be greatly appreciated.
Figured this out. The best way to do it was to create a custom script within my package.json file and then call that from Bamboo.
package.json
"scripts": {
"test-ci": "nyc -a --reporter=clover mocha --recursive --reporter mocha-bamboo-reporter"
Bamboo - Node.js task
run-script test-ci
Related
I'm using gitlab runner on a mac mini server.
While using user named "runner" I manage to use this command:
gsutil ls -l gs://tests/ |grep staging | sort -k 2 | tail -n 3| head -n 2 |awk '{print $3}' | gsutil -m cp -I .
I manage to get the files, but while using the same command in gitlab-ci.yml like this:
stages:
- test
test:
stage: test
when: always
script:
- gsutil ls -l gs://tests/ |grep staging | sort -k 2 | tail -n 3| head -n 2 |awk '{print $3}' | gsutil -m cp -I .
I get the error:
bash: line 141: gsutil: command not found
Also I checked and gitlab runner is using the same user I used.
The gitlab runner is configured with shell executor.
Changing the command to hold the full path of gsutil didn't help either.
I added whoami to the gitlab-ci.yml and got the result of the same user "runner"
I managed to solve this issue by using this solution:
gcloud-command-not-found-while-installing-google-cloud-sdk
I included this 2 line into my gitlab-ci.yml before using the gsutil command.
source '[path-to-my-home]/google-cloud-sdk/path.bash.inc'
source '[path-to-my-home]/google-cloud-sdk/completion.bash.inc'
Based on this question on StackOverflow, I added test coverage into my Gitlab CI/CD YAML file, and I expect the result gets uploaded into codeclimate.
- go get github.com/axw/gocov/gocov
- export CC_TEST_REPORTER_ID=My_REPO_ID
- 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
- gocov test -v ./... -coverprofile=out
- ./cc-test-reporter format-coverage --input-type gocov out
- ./cc-test-reporter upload-coverage
The script runs test successfully in all my packages, and the output of CI/CD shows that all tests in different packages ran, but uploaded report into codeclimate only shows there is only one file with test-coverage and that is the last test package, instead of showing all.
I mixed the solution with another answer in the same stackoverflow link and finally create a bash file and ran it from my yaml file like this so the report output contain all package reports, this is my script:
go get github.com/axw/gocov/gocov
export CC_TEST_REPORTER_ID=My_ID
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
for pkg in $(go list ./... | grep -v vendor); do
go test -coverprofile=$(echo $pkg | tr / -).cover $pkg
done
echo "mode: set" > c.out
grep -h -v "^mode:" ./*.cover >> c.out
rm -f *.cover
./cc-test-reporter after-build
I've inherited a JS code base with Jasmine unit tests. The testing framework uses karma and instanbul-combine to get code coverage. It seems istanbul-combine isn't working with present node modules, and besides is no longer maintained: the recommended replacement is nyc. I'm having trouble replacing istanbul-combine with nyc in the Makefile.
Here's are my attempts at merging the data (not even trying to get a report yet):
#1
#for dir in $(shell ls -d coverage/*/); do \
echo "Merging $${dir}"; \
npx nyc merge $${dir} coverage-final.json; \
done
#2
npx nyc merge coverage coverage-final.json
#3
npx nyc merge --include coverage/*/ coverage-final.json
The coverage data is in coverage/*/coverage-final.json, but none of these attempts succeeds in mergeing it into the result file coverage-final.json.
With #1, I'm pretty sure it's only actually merging a single set of results into the result file. With #2, there's an error; but if I put that command in the shell CLI, nothing is put into the result file.
With #3, at least there's no error, but only one of the coverage files is merged.
Here's the original Makefile line that I'm replacing:
PATH=$(PROJECT_HOME)/bin:$$PATH node_modules/istanbul-combine/cli.js \
-d coverage/summary -r html \
coverage/*/coverage-final.json
I wrote a little script in the Makefile to copy the coverage-final.json files from the child directories of the coverage directory to the coverage directory itself, and then merge them into a coverage-final.json file in the main JS directory.
#cd coverage; \
for dir in $(dir */coverage-final.json); do \
fn="$${dir}coverage-final.json"; \
newName="$${dir::-1}.json"; \
echo "cp $${fn} $${newName}"; \
cp $$fn $$newName; \
done;
npx nyc merge coverage coverage-final.json
The new filenames of the individual coverage files are taken from the name of the directories from which they come.
I want my integration tests to run in parallel on Circleci.
I read this document https://circleci.com/blog/how-to-boost-build-time-with-test-parallelism/ and I setup my job like this
platform_component_test:
working_directory: *workspace_root
executor: ubuntu-machine
parallelism: 16
steps:
- prepare_workspace
- run:
name: 'Run Platform Component tests'
command:
./gradlew platform:componentTest -PtestFilter="`circleci tests glob "platform/src/componentTest/java/**/*.java"|circleci tests split`"
By looking at the UI, I see that each of the 16 containers that are spawn execute all the tests.
Am I missing something?
I ended up slightly modifying this and incorporating what I learned from here and here to build this:
- run:
name: Run tests in parallel
# Use "./gradlew test" instead if tests are not run in parallel
command: |
cd module-with-tests-to-run/src/test/kotlin
# Get list of classnames of tests that should run on this node
CLASSNAMES=$(circleci tests glob "**/**Test.kt" \
| cut -c 1- | sed 's#/#.#g' \
| sed 's/.\{3\}$//' \
| circleci tests split --split-by=timings --timings-type=classname)
cd ../../../..
# Format the arguments to "./gradlew test"
GRADLE_ARGS=$(echo $CLASSNAMES | awk '{for (i=1; i<=NF; i++) print "--tests",$i}')
echo "Prepared arguments for Gradle: $GRADLE_ARGS"
./gradlew clean module-with-tests-to-run:test $GRADLE_ARGS
note: I tried to get the formatting right but I might have goofed.
I'm iOS developer and
I've been playing with Gitlab lately trying to figure out if it's better/more convenient than redmine+jenkins+HockeyApp. Gitlab seems to be quite cool except for I cannot figure out how to upload my ad-hoc iOS build to HockeyApp (or TestFlight). Is it even possible?
Thanks
Yep, this is definitely possible. I'd strongly recommend using the fastlane Ruby gem.
They even have docs for using it with GitLab CI. You can use pilot specifically to upload the build to TestFlight.
Hopefully that helps :)
I ended up with the following configuration:
add deploy.sh file:
#!/bin/bash
echo "deploy to hockeyapp"
HOCKEYAPP_APP_NAME="MyApp.iOS.ipa"
HOCKEYAPP_TOKEN="MyTOKEN"
HOCKEYAPP_ID="MYAPPID"
function buildNotes {
# We need an initial bullet point for our list of commit logs
echo -n "* "
# Get the latest app uploads
curl -H "X-HockeyAppToken: $HOCKEYAPP_TOKEN" \
"https://rink.hockeyapp.net/api/2/apps/$HOCKEYAPP_ID/app_versions?page=1" | \
# Put every property on a separate line
sed 's/,/\n/g' | \
# Remove all the quotation marks
sed 's/"//g' | \
# Look at only the notes properties
grep notes | \
# Look at the first one, i.e. the latest app upload
head -n 1 | \
# Find the commit information at the bottom of the notes
sed -n 's/.*(commit:\([^)]*\)).*/\1/p' | \
# Let's find all the logs since that commit
xargs -I '{}' git log {}..HEAD --pretty=format:'%h %s' --no-merges | \
# Add a star to each newline to make the list
sed ':a;N;$!ba;s/\n/\n* /g'
# The end of the revision log must have the latest commit
# This is so later we can do the above again
echo
echo -n "* (commit:"
git rev-parse HEAD | xargs echo -n
echo -n ')'
}
function deployAppFlavor () {
echo "executeCurlCommand"
curl -F "status=2" \
-F "notify=1" \
-F "notes=<release_notes" \
-F "notes_type=0" \
-F "ipa=#src/build/MyApp.iOS.ipa/$1" \
-H "X-HockeyAppToken: $2"\
"https://rink.hockeyapp.net/api/2/apps/$3/app_versions/upload"
}
function deployApp {
buildNotes > release_notes
deployAppFlavor $HOCKEYAPP_APP_NAME $HOCKEYAPP_TOKEN $HOCKEYAPP_ID
}
deployApp
and then update yml file:
build_project:
stage: build
script:
- xcodebuild clean -workspace MyApp.iOS.xcworkspace -scheme MyApp.iOS -quiet
- xcodebuild build -workspace MyApp.iOS.xcworkspace -scheme MyApp.iOS -destination 'platform=iOS Simulator,name=iPhone 6s' | xcpretty -s > -quiet
archive_project:
stage: archive
script:
- xcodebuild clean archive -archivePath "build/MyApp.iOS.xcarchive" -workspace "MyApp.iOS.xcworkspace" -scheme MyApp.iOS -quiet
- xcodebuild -exportArchive -archivePath "build/MyApp.IOS.xcarchive" -exportPath "build/MyApp.iOS.ipa" -exportOptionsPlist "export.plist" -quiet
artifacts:
paths:
- src/build/MyApp.iOS.ipa
deploy:
before_script:
- chmod +x ./scripts/deploy.sh
stage: deploy
script:
- ./scripts/deploy.sh