Skip to content

Commit

Permalink
Merge pull request #127 from paambaati/error-msg-fix
Browse files Browse the repository at this point in the history
Fix silently failing tests
  • Loading branch information
paambaati authored Mar 4, 2020
2 parents 857b291 + c38bc65 commit b0b612a
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
58 changes: 53 additions & 5 deletions test/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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 = '';
Expand All @@ -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(
Expand All @@ -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();
Expand Down

0 comments on commit b0b612a

Please sign in to comment.