From e150114be93e9b60f3375a252110e3c7dea32131 Mon Sep 17 00:00:00 2001 From: satoren Date: Thu, 19 Aug 2021 22:32:58 +0900 Subject: [PATCH] feat: improve anotation message --- src/features/showAnnotations.js | 20 +++++++++----------- tests/features/showAnnotations.test.js | 6 +++--- 2 files changed, 12 insertions(+), 14 deletions(-) diff --git a/src/features/showAnnotations.js b/src/features/showAnnotations.js index ae7051f..00b19e4 100644 --- a/src/features/showAnnotations.js +++ b/src/features/showAnnotations.js @@ -22,20 +22,18 @@ const showAnnotations = async (compareFileData) => { ); fileLinesWithChangedFiles.forEach(({ file, lines }) => { - const linesToDisplay = lines.map((line) => - Array.isArray(line) ? line.join("-") : line - ); + lines.forEach((line) => { + const linesWord = Array.isArray(line) ? "lines are" : "line is"; - const linesWord = linesToDisplay.length === 1 ? "line is" : "lines are"; + const formattedLines = Array.isArray(line) ? line.join("-") : line; - const formattedLines = linesToDisplay.join(", "); + const message = `file=${file}#L${formattedLines}::${formattedLines} ${linesWord} not covered with tests`; - const message = `file=${file}::${formattedLines} ${linesWord} not covered with tests`; - - // NOTE: consider an option to show lines directly by attaching 'line' param - // Need to fix the issue where we consider 'empty line' as covered line - // Empty lines should not interapt uncovered interval - core.info(`::${showAnnotationsInput} ${message}`); + // NOTE: consider an option to show lines directly by attaching 'line' param + // Need to fix the issue where we consider 'empty line' as covered line + // Empty lines should not interapt uncovered interval + core.info(`::${showAnnotationsInput} ${message}`); + }); }); } }; diff --git a/tests/features/showAnnotations.test.js b/tests/features/showAnnotations.test.js index 6172557..3cba113 100644 --- a/tests/features/showAnnotations.test.js +++ b/tests/features/showAnnotations.test.js @@ -79,7 +79,7 @@ describe("features/showAnnotations", () => { assert.isTrue(mergeFileLinesWithChangedFiles.calledOnce); assert.isTrue(info.calledTwice); assert.deepEqual(info.secondCall.args, [ - `::warning file=${filename}::${line} line is not covered with tests` + `::warning file=${filename}#L${line}::${line} line is not covered with tests` ]); }); @@ -111,9 +111,9 @@ describe("features/showAnnotations", () => { assert.isTrue(getChangedFiles.calledOnce); assert.isTrue(uncoveredFileLinesByFileNames.calledOnce); assert.isTrue(mergeFileLinesWithChangedFiles.calledOnce); - assert.isTrue(info.calledTwice); + assert.equal(info.callCount, 4); assert.deepEqual(info.secondCall.args, [ - `::warning file=${filename}::1-4, 8, 45-50 lines are not covered with tests` + `::warning file=${filename}#L1-4::1-4 lines are not covered with tests` ]); }); });