Skip to content

Commit

Permalink
produce nice test reports from mocha in jenkins (CAS-448)
Browse files Browse the repository at this point in the history
It makes use of xunit (standard xml test output).
  • Loading branch information
Jan Kryl committed Sep 17, 2020
1 parent 7e309f3 commit 90a0513
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 9 deletions.
10 changes: 10 additions & 0 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ pipeline {
steps {
sh 'nix-shell --run "./scripts/node-test.sh"'
}
post {
always {
junit '*-xunit-report.xml'
}
}
}
stage('nix tests') {
agent { label 'nixos-mayastor-kvm' }
Expand All @@ -38,6 +43,11 @@ pipeline {
steps {
sh 'nix-shell --run "./scripts/moac-test.sh"'
}
post {
always {
junit 'moac-xunit-report.xml'
}
}
}
}
}
Expand Down
31 changes: 31 additions & 0 deletions csi/moac/test/multi_reporter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Mocha does not support multiple reporters running at once. So we use this
// simple wrapper as suggested in:
// https://github.com/mochajs/mocha/pull/1360#issuecomment-407404831

const mocha = require('mocha');

function MultiReporter (runner, options) {
this.reports = [];
if (!options.reporterOptions.reporters) {
console.log('\nneeds --reporter-options reporters="SPACE_SEPARATED_MOCHA_REPORTS"');
return;
}
const self = this;
options.reporterOptions.reporters.split(' ').forEach(function (report) {
const ReportClass = mocha.reporters[report];
if (!ReportClass) {
console.log('\ninvalid report class available: ' + Object.keys(mocha.reporters).join(','));
return;
}
const reportInstance = new ReportClass(runner, options);
self.reports.push(reportInstance);
});
}

MultiReporter.prototype.epilogue = function () {
this.reports.forEach(function (reportInstance) {
reportInstance.epilogue();
});
};

exports = module.exports = MultiReporter;
31 changes: 31 additions & 0 deletions mayastor-test/multi_reporter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Mocha does not support multiple reporters running at once. So we use this
// simple wrapper as suggested in:
// https://github.com/mochajs/mocha/pull/1360#issuecomment-407404831

const mocha = require('mocha');

function MultiReporter (runner, options) {
this.reports = [];
if (!options.reporterOptions.reporters) {
console.log('\nneeds --reporter-options reporters="SPACE_SEPARATED_MOCHA_REPORTS"');
return;
}
const self = this;
options.reporterOptions.reporters.split(' ').forEach(function (report) {
const ReportClass = mocha.reporters[report];
if (!ReportClass) {
console.log('\ninvalid report class available: ' + Object.keys(mocha.reporters).join(','));
return;
}
const reportInstance = new ReportClass(runner, options);
self.reports.push(reportInstance);
});
}

MultiReporter.prototype.epilogue = function () {
this.reports.forEach(function (reportInstance) {
reportInstance.epilogue();
});
};

exports = module.exports = MultiReporter;
6 changes: 4 additions & 2 deletions scripts/moac-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,7 @@ cd csi/moac
npm install
npm run prepare
npm run compile
# TODO: Add XML output for jenkins
./node_modules/mocha/bin/mocha test/index.js

./node_modules/mocha/bin/mocha test/index.js \
--reporter test/multi_reporter.js \
--reporter-options reporters="xunit spec",output=../../moac-xunit-report.xml
13 changes: 6 additions & 7 deletions scripts/node-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@ export PATH=$PATH:${HOME}/.cargo/bin
cargo build --all
cd mayastor-test
npm install
./node_modules/mocha/bin/mocha test_cli.js
./node_modules/mocha/bin/mocha test_replica.js
./node_modules/mocha/bin/mocha test_nexus.js
./node_modules/mocha/bin/mocha test_csi.js
./node_modules/mocha/bin/mocha test_rebuild.js
./node_modules/mocha/bin/mocha test_snapshot.js
./node_modules/mocha/bin/mocha test_nats.js

for ts in cli replica nexus csi rebuild snapshot nats; do
./node_modules/mocha/bin/mocha test_${ts}.js \
--reporter ./multi_reporter.js \
--reporter-options reporters="xunit spec",output=../${ts}-xunit-report.xml
done

0 comments on commit 90a0513

Please sign in to comment.