From e63d34a5b4fb040a4cb63d4db15c87d4128e7c4c Mon Sep 17 00:00:00 2001 From: Moshe Atlow Date: Thu, 1 Feb 2024 14:34:53 +0200 Subject: [PATCH] feat: add location to notify (#111) --- packages/github/index.js | 24 +++++++++++++++++------- packages/github/tests/output-esm.js | 12 +----------- packages/github/tests/output.js | 4 ++-- packages/junit/tests/output-esm.js | 29 +---------------------------- 4 files changed, 21 insertions(+), 48 deletions(-) diff --git a/packages/github/index.js b/packages/github/index.js index 073631b..f5060be 100644 --- a/packages/github/index.js +++ b/packages/github/index.js @@ -43,6 +43,21 @@ const DIAGNOSTIC_VALUES = { duration_ms: (value) => `${Number(value).toFixed(3)}ms`, }; +function extractLocation(data) { + let { line, column, file } = data; + const error = data.details?.error; + file = getFilePath(file); + + if (error) { + const errorLocation = parseStack(error, file); + file = getFilePath(errorLocation?.file ?? file) ?? file; + line = errorLocation?.line ?? line; + column = errorLocation?.column ?? column; + } + + return { file, startLine: line, startColumn: column }; +} + module.exports = async function githubReporter(source) { if (!process.env.GITHUB_ACTIONS) { // eslint-disable-next-line no-unused-vars @@ -67,13 +82,8 @@ module.exports = async function githubReporter(source) { // no need to re-annotate the file itself break; } - let filePath = getFilePath(event.data.file); - const location = parseStack(error, filePath); - filePath = getFilePath(location?.file ?? filePath) ?? filePath; core.error(util.inspect(error, { colors: false, breakLength: Infinity }), { - file: filePath, - startLine: location?.line, - startColumn: location?.column, + ...extractLocation(event.data), title: event.data.name, }); counter.fail += 1; @@ -82,7 +92,7 @@ module.exports = async function githubReporter(source) { if (event.data.nesting === 0) { diagnostics.push(event.data.message); } else { - core.notice(event.data.message, { file: getFilePath(event.data.file) }); + core.notice(event.data.message, extractLocation(event.data)); } break; default: diff --git a/packages/github/tests/output-esm.js b/packages/github/tests/output-esm.js index 0a70bfd..945accc 100644 --- a/packages/github/tests/output-esm.js +++ b/packages/github/tests/output-esm.js @@ -2,7 +2,7 @@ module.exports = { stdout: `::debug::starting to run should fail -:error title=should fail,file=tests/example.mjs,line=5,col=3::\\[Error \\[ERR_TEST_FAILURE\\]: false == true\\] {%0A code: 'ERR_TEST_FAILURE',%0A failureType: 'testCodeFailure',%0A cause: AssertionError \\[ERR_ASSERTION\\]: false == true%0A at TestContext. \\(file:///.*/example.mjs:5:3\\)%0A.* {%0A generatedMessage: true,%0A code: 'ERR_ASSERTION',%0A actual: false,%0A expected: true,%0A operator: '=='%0A }%0A} +::error title=should fail,file=tests/example.mjs,line=5,col=3::\\[Error \\[ERR_TEST_FAILURE\\]: The expression evaluated to a falsy value:%0A%0A assert\\(false\\)%0A\\] {%0A code: 'ERR_TEST_FAILURE',%0A failureType: 'testCodeFailure',%0A cause: AssertionError \\[ERR_ASSERTION\\]: The expression evaluated to a falsy value:%0A %0A assert\\(false\\)%0A %0A at TestContext. \\(file:///.*/example.mjs:5:3\\)%0A.* {%0A generatedMessage: true,%0A code: 'ERR_ASSERTION',%0A actual: false,%0A expected: true,%0A operator: '=='%0A }%0A} ::debug::starting to run should pass ::debug::completed running should pass ::group::Test results \\(1 passed, 1 failed\\) @@ -21,16 +21,6 @@ module.exports = { ::group::Test results \\(1 passed, 1 failed\\) ::notice::Total Tests: 2%0ASuites 📂: 0%0APassed ✅: 1%0AFailed ❌: 1%0ACanceled 🚫: 0%0ASkipped ⏭️: 0%0ATodo 📝: 0%0ADuration 🕐: .*ms ::endgroup:: -`, - }, - 21: { - stdout: `::debug::starting to run should fail -::error title=should fail,file=tests/example.mjs,line=5,col=3::\\[Error \\[ERR_TEST_FAILURE\\]: The expression evaluated to a falsy value:%0A%0A assert\\(false\\)%0A\\] {%0A code: 'ERR_TEST_FAILURE',%0A failureType: 'testCodeFailure',%0A cause: AssertionError \\[ERR_ASSERTION\\]: The expression evaluated to a falsy value:%0A %0A assert\\(false\\)%0A %0A at TestContext. \\(file:///.*/example.mjs:5:3\\)%0A.* {%0A generatedMessage: true,%0A code: 'ERR_ASSERTION',%0A actual: false,%0A expected: true,%0A operator: '=='%0A }%0A} -::debug::starting to run should pass -::debug::completed running should pass -::group::Test results \\(1 passed, 1 failed\\) -::notice::Total Tests: 2%0ASuites 📂: 0%0APassed ✅: 1%0AFailed ❌: 1%0ACanceled 🚫: 0%0ASkipped ⏭️: 0%0ATodo 📝: 0%0ADuration 🕐: .*ms -::endgroup:: `, }, }, diff --git a/packages/github/tests/output.js b/packages/github/tests/output.js index 8dcb006..914d7a2 100644 --- a/packages/github/tests/output.js +++ b/packages/github/tests/output.js @@ -8,7 +8,7 @@ module.exports = { ::error title=fails,file=tests/example.js,line=9,col=11::\\[Error \\[ERR_TEST_FAILURE\\]: this is an error\\] {%0A code: 'ERR_TEST_FAILURE',%0A failureType: 'testCodeFailure',%0A cause: Error: this is an error%0A at TestContext. (.*/example.js:9:11).*%0A} ::debug::starting to run is a diagnostic ::debug::completed running is a diagnostic -::notice file=tests/example.js::this is a diagnostic +::notice file=tests/example.js,line=11,col=3::this is a diagnostic ::debug::starting to run should fail ::error title=should fail,file=tests/example.js,line=12,col=31::\\[Error \\[ERR_TEST_FAILURE\\]: The expression evaluated to a falsy value:%0A%0A assert\\(false\\)%0A\\] {%0A code: 'ERR_TEST_FAILURE',%0A failureType: 'testCodeFailure',%0A cause: AssertionError \\[ERR_ASSERTION\\]: The expression evaluated to a falsy value:%0A %0A assert\\(false\\)%0A %0A at TestContext. (.*/example.js:12:31).* ::debug::starting to run more tests @@ -35,7 +35,7 @@ module.exports = { ::error title=fails,file=tests/example.js,line=9,col=11::\\[Error \\[ERR_TEST_FAILURE\\]: this is an error\\] {%0A failureType: 'testCodeFailure',%0A cause: Error: this is an error%0A at TestContext. (.*/example.js:9:11).* code: 'ERR_TEST_FAILURE'%0A} ::debug::starting to run is a diagnostic ::debug::completed running is a diagnostic -::notice file=tests/example.js::this is a diagnostic +::notice file=tests/example.js,line=11,col=3::this is a diagnostic ::debug::starting to run should fail ::error title=should fail,file=tests/example.js,line=12,col=31::\\[Error \\[ERR_TEST_FAILURE\\]: The expression evaluated to a falsy value:%0A%0A assert\\(false\\)%0A\\] {%0A failureType: 'testCodeFailure',%0A cause: AssertionError \\[ERR_ASSERTION\\]: The expression evaluated to a falsy value:%0A %0A assert\\(false\\)%0A %0A at TestContext. (.*/example.js:12:31).* ::debug::starting to run more tests diff --git a/packages/junit/tests/output-esm.js b/packages/junit/tests/output-esm.js index 637293a..8e9753f 100644 --- a/packages/junit/tests/output-esm.js +++ b/packages/junit/tests/output-esm.js @@ -3,33 +3,6 @@ module.exports = { stdout: `<\\?xml version="1.0" encoding="utf-8"\\?> -\t -\t\t -\\[Error \\[ERR_TEST_FAILURE\\]: false == true\\] { - code: 'ERR_TEST_FAILURE', - failureType: 'testCodeFailure', - cause: AssertionError \\[ERR_ASSERTION\\]: false == true - at TestContext.*/example.mjs:5:3\\) - at .* - at .* - at .* - at .* { - generatedMessage: true, - code: 'ERR_ASSERTION', - actual: false, - expected: true, - operator: '==' - } -} -\t\t -\t -\t - -`, - overrides: { - 21: { - stdout: `<\\?xml version="1.0" encoding="utf-8"\\?> - \t \t\t \\[Error \\[ERR_TEST_FAILURE\\]: The expression evaluated to a falsy value: @@ -59,7 +32,7 @@ module.exports = { \t `, - }, + overrides: { 18: { stdout: `<\\?xml version="1.0" encoding="utf-8"\\?>