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 21b460d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 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
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::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

0 comments on commit 21b460d

Please sign in to comment.