From 0d4b9f4ba6fabea1a2f42ffd64ad4e1785c8c908 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Raphael=20von=20der=20Gr=C3=BCn?= Date: Wed, 13 Jun 2018 16:09:03 +0200 Subject: [PATCH] Fix output and exit code for Java tests This fixes the following issues: * run_java_unit_tests.js always has exit code of 0 thus never failing the npm tests. * "Tests completed successfully" is printed after failing to create the Gradle wrapper and never running the tests. * Gradle errors are printed twice --- test/run_java_unit_tests.js | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/test/run_java_unit_tests.js b/test/run_java_unit_tests.js index 9e585a66..f26641c1 100644 --- a/test/run_java_unit_tests.js +++ b/test/run_java_unit_tests.js @@ -37,11 +37,15 @@ if (!needs_gradlew_built) { } needs_gradlew_built.then(function () { + console.log('Gradle wrapper is ready. Running tests now.'); return superspawn.spawn(path.join(__dirname, 'gradlew'), ['test'], {stdio: 'inherit'}); -}, function (err) { - console.error('There was an error building the gradlew file:', err); }).then(function () { console.log('Tests completed successfully.'); -}).fail(function (err) { - console.error('Tests failed!', err); +}); + +process.on('unhandledRejection', err => { + // If err has a stderr property, we have seen the message already + if (!('stderr' in err)) console.error(err.message); + console.error('JAVA UNIT TESTS FAILED!'); + process.exitCode = err.code || 1; });