Skip to content

Commit

Permalink
feat: add location to notify
Browse files Browse the repository at this point in the history
  • Loading branch information
MoLow committed Feb 1, 2024
1 parent 3537ebf commit 3c05119
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 48 deletions.
24 changes: 17 additions & 7 deletions packages/github/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
Expand All @@ -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:
Expand Down
12 changes: 1 addition & 11 deletions packages/github/tests/output-esm.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.<anonymous> \\(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.<anonymous> \\(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\\)
Expand All @@ -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.<anonymous> \\(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::
`,
},
},
Expand Down
4 changes: 2 additions & 2 deletions packages/github/tests/output.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.<anonymous> (.*/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.<anonymous> (.*/example.js:12:31).*
::debug::starting to run more tests
Expand All @@ -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.<anonymous> (.*/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.<anonymous> (.*/example.js:12:31).*
::debug::starting to run more tests
Expand Down
29 changes: 1 addition & 28 deletions packages/junit/tests/output-esm.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,6 @@
module.exports = {
stdout: `<\\?xml version="1.0" encoding="utf-8"\\?>
<testsuites>
\t<testcase name="should fail" time=".*" classname="test" failure="false == true">
\t\t<failure type="testCodeFailure" message="false == true">
\\[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</failure>
\t</testcase>
\t<testcase name="should pass" time=".*" classname="test"/>
</testsuites>
`,
overrides: {
21: {
stdout: `<\\?xml version="1.0" encoding="utf-8"\\?>
<testsuites>
\t<testcase name="should fail" time=".*" classname="test" failure="The expression evaluated to a falsy value: assert\\(false\\)">
\t\t<failure type="testCodeFailure" message="The expression evaluated to a falsy value: assert\\(false\\)">
\\[Error \\[ERR_TEST_FAILURE\\]: The expression evaluated to a falsy value:
Expand Down Expand Up @@ -59,7 +32,7 @@ module.exports = {
\t<testcase name="should pass" time=".*" classname="test"/>
</testsuites>
`,
},
overrides: {
18: {
stdout: `<\\?xml version="1.0" encoding="utf-8"\\?>
<testsuites>
Expand Down

0 comments on commit 3c05119

Please sign in to comment.