From bb2c6772d9795b729fac4755907b892777538d58 Mon Sep 17 00:00:00 2001 From: GP Date: Wed, 4 Mar 2020 12:14:08 +0530 Subject: [PATCH 1/2] main: Pass error message to @actions/core error(). This fixes #119. --- src/main.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.ts b/src/main.ts index c9b43358..3a5b4444 100644 --- a/src/main.ts +++ b/src/main.ts @@ -89,7 +89,7 @@ export function run( } debug('โœ… Coverage run completed...'); } catch (err) { - error(err); + error(err.message); setFailed('๐Ÿšจ Coverage run failed!'); return reject(err); } From c38bc6507ff93b09b157365d6900ce81a7a1b62d Mon Sep 17 00:00:00 2001 From: GP Date: Wed, 4 Mar 2020 12:15:12 +0530 Subject: [PATCH 2/2] tests: Add a test for the failure case, BUT... it won't work now - even though the test itself passes, tape exits with error code 1. This needs more time to debug. --- test/main.test.ts | 58 +++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 53 insertions(+), 5 deletions(-) diff --git a/test/main.test.ts b/test/main.test.ts index 07fa1b1c..975ecac6 100644 --- a/test/main.test.ts +++ b/test/main.test.ts @@ -24,8 +24,8 @@ test('๐Ÿงช downloadToFile() should download the give URL and write to given file .get('/dummy-cc-reporter') .reply(200, () => { return toReadableStream(`#!/bin/bash - echo "hello" - `); +echo "hello" +`); }); await downloadToFile( 'http://localhost.test/dummy-cc-reporter', @@ -52,8 +52,8 @@ test('๐Ÿงช run() should run the CC reporter (happy path).', async t => { .get('/dummy-cc-reporter') .reply(200, () => { return toReadableStream(`#!/bin/bash - echo "$*" - `); // Dummy shell script that just echoes back all arguments. +echo "$*" +`); // Dummy shell script that just echoes back all arguments. }); let capturedOutput = ''; @@ -70,8 +70,9 @@ test('๐Ÿงช run() should run the CC reporter (happy path).', async t => { unhookIntercept(); } catch (err) { unhookIntercept(); - nock.cleanAll(); t.fail(err); + } finally { + nock.cleanAll(); } t.equal( @@ -94,6 +95,53 @@ after-build --exit-code 0 t.end(); }); +// TODO: @paambaati โ€” Figure out why this test itself passes but why tape fails with exit code 1. +test.skip('๐Ÿงช run() should exit cleanly when the coverage command fails.', async t => { + t.plan(1); + const COVERAGE_COMMAND = 'wololololo'; // Random command that doesn't exist (and so should fail). + const filePath = './test.sh'; + const mock = await nock('http://localhost.test') + .get('/dummy-cc-reporter') + .reply(200, () => { + return toReadableStream(`#!/bin/bash +echo "$*" +`); // Dummy shell script that just echoes back all arguments. + }); + + let capturedOutput = ''; + const unhookIntercept = intercept.default((text: string) => { + capturedOutput += text; + }); + + try { + await run( + 'http://localhost.test/dummy-cc-reporter', + filePath, + COVERAGE_COMMAND + ); + unhookIntercept(); + t.fail('Should throw an error.'); + } catch (err) { + unhookIntercept(); + t.equal( + capturedOutput, + `::debug::โ„น๏ธ Downloading CC Reporter from http://localhost.test/dummy-cc-reporter ... +::debug::โœ… CC Reporter downloaded... +[command]${DEFAULT_WORKDIR}/test.sh before-build +before-build +::debug::โœ… CC Reporter before-build checkin completed... +::error::Unable to locate executable file: ${COVERAGE_COMMAND}. Please verify either the file path exists or the file can be found within a directory specified by the PATH environment variable. Also check the file mode to verify the file is executable. +::error::๐Ÿšจ Coverage run failed! +`, + 'should fail correctly on wrong/invalid coverage command.' + ); + } finally { + unlinkSync(filePath); + nock.cleanAll(); + t.end(); + } +}); + test('๐Ÿ’ฃ teardown', t => { nock.restore(); nock.cleanAll();