From 268cbeec745a0c823cf787a6de3d77e4f1200a1c Mon Sep 17 00:00:00 2001 From: Ali Ghassemi Date: Wed, 13 Dec 2017 09:05:09 -0800 Subject: [PATCH] Exit with non-zero if there is any parse error --- lib/converter.js | 3 ++- package.json | 2 +- test/bad/upstream-failure | 9 +++++++++ test/runner.js | 1 + 4 files changed, 13 insertions(+), 2 deletions(-) create mode 100644 test/bad/upstream-failure diff --git a/lib/converter.js b/lib/converter.js index 4418d30..7a4d5f3 100644 --- a/lib/converter.js +++ b/lib/converter.js @@ -82,6 +82,7 @@ function converter(options) { r.failures.forEach(function(fail) { if (fail.tapError) { var err = new Error('TAP parse error: ' + fail.tapError); + exitCode = 1; outStream.emit('error', err); } }); @@ -100,8 +101,8 @@ function converter(options) { var xmlString = serialize(testSuites); outStream.push(xmlString + '\n'); - outStream.emit('end'); result.exitCode = exitCode; + outStream.emit('end'); }); var result = duplexer(tapParser, outStream); diff --git a/package.json b/package.json index 0bed99a..ff73ef5 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "tap-xunit", - "version": "1.7.0", + "version": "2.0.0", "description": "TAP to xUnit XML converter.", "main": "lib/converter.js", "bin": { diff --git a/test/bad/upstream-failure b/test/bad/upstream-failure new file mode 100644 index 0000000..f0d9636 --- /dev/null +++ b/test/bad/upstream-failure @@ -0,0 +1,9 @@ +Error: beep + at [eval]:1:7 + at ContextifyScript.Script.runInThisContext (vm.js:50:33) + at Object.runInThisContext (vm.js:139:38) + at Object. ([eval]-wrapper:6:22) + at Module._compile (module.js:635:30) + at evalScript (bootstrap_node.js:462:27) + at startup (bootstrap_node.js:163:9) + at bootstrap_node.js:608:3 diff --git a/test/runner.js b/test/runner.js index 0ac9bb3..4cd74d8 100644 --- a/test/runner.js +++ b/test/runner.js @@ -83,6 +83,7 @@ function runBadInputTests() { }); xUnitStream.on('end', function() { assert.ok(numParseErrors > 0, 'had ' + numParseErrors + ' parse errors'); + assert.equals(tapToxUnitConverter.exitCode, 1, 'exitCode match'); assert.end(); }); });