5

I have something strange happening when attempting to generate a combined coverage report on a Jenkins pipeline job.

I have an Nx powered Angular monorepo and am generating coverage reports across all the libs and projects contained within.

I have put together the following script to run the tests and then use nyc for the merge and report operations.

const { execSync } = require('child_process');
const packageJSON = require("../package.json");

const EXCLUDE_UNIT_TEST = packageJSON.buildData.excludeUnitTest;
 
const run = (commands) => {
  commands.forEach((command) => execSync(command, { stdio: 'inherit' }));
};
 
run([
  `rm -rf coverage`,
  `npx nx run-many --target=test --all --maxWorkers=4 --exclude=${EXCLUDE_UNIT_TEST} --coverage=true`,
  `npx copyfiles -f 'coverage/**/*coverage.json' coverage/project-parts`,
  `npx nyc merge coverage/project-parts coverage/nyc/combined.json`,
  `npx nyc report --reporter html-spa --reporter lcov -t coverage/nyc --report-dir coverage/combined`
]);

This works perfectly fine for me locally, I see a single HTML report (both lcov format and the html-spa report) for all of my libs/projects.

But when the same script is executed on a node on our Jenkins (we use EC2 slave plugin), the HTML reports are empty.

stage('Gate 2 - Test') {
    steps {
        echo "GATE 2 - Test"
        ansiColor('xterm') {
            sh 'npm run tests:all'
        }
    }
    post {
        success {
            publishHTML (target : [allowMissing: false,
                alwaysLinkToLastBuild: false,
                keepAll: false,
                reportDir: 'coverage/combined',
                reportFiles: 'index.html',
                reportName: 'Magma Code Coverage',
                reportTitles: 'Coverage Report'])
        }
    }
}

enter image description here

I do see the output I would expect from the copyfiles and nyc merge commands in the generated workspace when the build job is run on Jenkins and these files are not empty, there is plenty of content in these detailing the various coverage info.

The final combined file that nyc merge generates is over 20Mb.

enter image description here

It's just the nyc report command that appears to be the problem.

Digging into the build logs on Jenkins, I don't see any errors during the HTML publish step either.

enter image description here

Has anyone come across similar problems with unexpected coverage results using nyc on CI vs Local environments?

Are there any debugging/verbose output flags I can use with the nyc commands that can help me to troubleshoot the problem?

mindparse
  • 6,115
  • 27
  • 90
  • 191

1 Answers1

0

I think that the differeence in outputs is due to differences in the environments, such as differences in the versions of the tools or environment variables.

try the --all flag to the nyc report command to ensure that all files are included in the report, and --verbose flag to get more detailed output. Also try using a different reporter to generate the report, or to try running the report command separately from the merge command to see if that does anything. Also good to check if there are any permission issues with the directory where the reports are generated.

Goran
  • 191
  • 1
  • 6