From 1d796afef2e9022f5328781b4bb21afd46fd15be Mon Sep 17 00:00:00 2001 From: Alejandro Santiago Date: Wed, 15 Mar 2023 16:10:14 +0000 Subject: [PATCH 1/2] feat: include better error logging --- index.js | 24 +++++++++++++++++++++-- index.test.js | 54 +++++++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 74 insertions(+), 4 deletions(-) diff --git a/index.js b/index.js index f29a0ad..5670c52 100644 --- a/index.js +++ b/index.js @@ -79,8 +79,28 @@ function shouldCalculateCoverageForFile(fileName, excludedFiles) { } function canParse(path) { - if (fs.existsSync(path) && fs.readFileSync(path).length === 0) { - core.setFailed('lcov is empty!'); + if (!fs.existsSync(path)) { + core.setFailed( + `❌ Failed to find an lcov file at ${path}. +Make sure to generate an lcov file before running VeryGoodCoverage and set the \ +path input to the correct location. + +For example: + uses: VeryGoodOpenSource/very_good_coverage@v2 + with: + path: 'my_project/coverage/lcov.info' +` + ); + return false; + } + + if (fs.readFileSync(path).length === 0) { + core.setFailed( + `❌ Found an empty lcov file at "${path}". +An empty lcov file was found but with no coverage data. This might be because \ +you have no test files or your tests are not generating any coverage data. +` + ); return false; } diff --git a/index.test.js b/index.test.js index 87f0dab..d8aec99 100644 --- a/index.test.js +++ b/index.test.js @@ -22,8 +22,58 @@ test('empty LCOV throws an error', () => { } catch (err) { expect(err).toBeDefined(); - const errorMessage = err.stdout.toString(); - expect(errorMessage).toContain('lcov is empty!'); + const errorMessage = err.stdout.toString().replace(/%0A/g, '\n'); + expect(errorMessage).toContain( + `❌ Found an empty lcov file at "${lcovPath}". +An empty lcov file was found but with no coverage data. This might be because \ +you have no test files or your tests are not generating any coverage data. +` + ); + } +}); + +test('non-existent LCOV throws an error', () => { + const lcovPath = './fixtures/not-found.info'; + process.env['INPUT_PATH'] = lcovPath; + const ip = path.join(__dirname, 'index.js'); + try { + cp.execSync(`node ${ip}`, { env: process.env }); + fail('this code should fail'); + } catch (err) { + expect(err).toBeDefined(); + + const errorMessage = err.stdout.toString().replace(/%0A/g, '\n'); + expect(errorMessage).toContain( + `❌ Failed to find an lcov file at ${lcovPath}. +Make sure to generate an lcov file before running VeryGoodCoverage and set the \ +path input to the correct location. + +For example: + uses: VeryGoodOpenSource/very_good_coverage@v2 + with: + path: 'my_project/coverage/lcov.info' +` + ); + } +}); + +test('empty LCOV throws an error', () => { + const lcovPath = './fixtures/lcov.empty.info'; + process.env['INPUT_PATH'] = lcovPath; + const ip = path.join(__dirname, 'index.js'); + try { + cp.execSync(`node ${ip}`, { env: process.env }); + fail('this code should fail'); + } catch (err) { + expect(err).toBeDefined(); + + const errorMessage = err.stdout.toString().replace(/%0A/g, '\n'); + expect(errorMessage).toContain( + `❌ Found an empty lcov file at "${lcovPath}". +An empty lcov file was found but with no coverage data. This might be because \ +you have no test files or your tests are not generating any coverage data. +` + ); } }); From bf53a708976574aaee915c5b45a795658707ea9f Mon Sep 17 00:00:00 2001 From: Alejandro Santiago Date: Wed, 15 Mar 2023 16:46:18 +0000 Subject: [PATCH 2/2] chore: removed redundant test --- index.test.js | 20 -------------------- 1 file changed, 20 deletions(-) diff --git a/index.test.js b/index.test.js index d8aec99..31bcbeb 100644 --- a/index.test.js +++ b/index.test.js @@ -57,26 +57,6 @@ For example: } }); -test('empty LCOV throws an error', () => { - const lcovPath = './fixtures/lcov.empty.info'; - process.env['INPUT_PATH'] = lcovPath; - const ip = path.join(__dirname, 'index.js'); - try { - cp.execSync(`node ${ip}`, { env: process.env }); - fail('this code should fail'); - } catch (err) { - expect(err).toBeDefined(); - - const errorMessage = err.stdout.toString().replace(/%0A/g, '\n'); - expect(errorMessage).toContain( - `❌ Found an empty lcov file at "${lcovPath}". -An empty lcov file was found but with no coverage data. This might be because \ -you have no test files or your tests are not generating any coverage data. -` - ); - } -}); - test('invalid LCOV format throws an error', () => { const lcovPath = './fixtures/lcov.error.info'; process.env['INPUT_PATH'] = lcovPath;