From a814ad2a7bdc5d08c4947666d61a4a7a638f1849 Mon Sep 17 00:00:00 2001
From: Doug Ayers <douglascayers@gmail.com>
Date: Sun, 1 Sep 2019 04:19:00 +0000
Subject: [PATCH] add test reports and code coverage

---
 Salesforce.gitlab-ci.yml | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/Salesforce.gitlab-ci.yml b/Salesforce.gitlab-ci.yml
index 24d0953..98f1a94 100644
--- a/Salesforce.gitlab-ci.yml
+++ b/Salesforce.gitlab-ci.yml
@@ -122,6 +122,11 @@ test-apex:
     - scratch_org_auth_url=$(cat SCRATCH_ORG_AUTH_URL.txt)
     - authenticate $scratch_org_username $scratch_org_auth_url
     - test_scratch_org $scratch_org_username
+  artifacts:
+    reports:
+      junit: tests/apex/*-junit.xml
+  coverage: '/name="testRunCoverage" value="([\d]+%)"/'
+
 
 
 ####################################################
@@ -374,13 +379,17 @@ deploy-production:
       npm init -y
     fi
 
+    # Make directory to output test results
+    # https://gitlab.com/help/ci/yaml/README.md#artifactsreports
+    mkdir -p ./tests/apex
+
     # Check if the scripts property in package.json contains key for "test:scratch"
     local scriptValue=$(jq -r '.scripts["test:scratch"]' < package.json)
 
     # If no "test:scratch" script property, then add one
     if [[ -z "$scriptValue" || $scriptValue == null ]]; then
       local tmp=$(mktemp)
-      jq '.scripts["test:scratch"]="sfdx force:apex:test:run --codecoverage --resultformat human --wait 10"' package.json > $tmp
+      jq '.scripts["test:scratch"]="sfdx force:apex:test:run --codecoverage --resultformat junit --wait 10 --outputdir ./tests/apex"' package.json > $tmp
       mv $tmp package.json
       echo "added test:scratch script property to package.json" >&2
       cat package.json >&2
-- 
GitLab