Skip to content

Commit

Permalink
chore: backtrace
Browse files Browse the repository at this point in the history
  • Loading branch information
h-a-n-a committed Sep 4, 2023
1 parent 7d991da commit 9ea75c6
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions packages/rspack/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,33 @@ process.on("unhandledRejection", (err, origin) => {
console.error(err.message, err.stack, process.exitCode);
});

["log", "warn", "error"].forEach(methodName => {
const originalMethod = console[methodName];
console[methodName] = (...args) => {
let initiator = "unknown place";
try {
throw new Error();
} catch (e) {
if (typeof e.stack === "string") {
let isFirst = true;
for (const line of e.stack.split("\n")) {
const matches = line.match(/^\s+at\s+(.*)/);
if (matches) {
if (!isFirst) {
// first line - current function
// second line - caller (what we are looking for)
initiator = matches[1];
break;
}
isFirst = false;
}
}
}
}
originalMethod.apply(console, [...args, "\n", ` at ${initiator}`]);
};
});

/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */
const config = {
testEnvironment: "../../scripts/test/patch-node-env.cjs",
Expand Down

0 comments on commit 9ea75c6

Please sign in to comment.