Skip to content

Commit ecc7f8a

Browse files
committed
Fix log location for Jest 26
1 parent ddbabdc commit ecc7f8a

File tree

4 files changed

+26
-1
lines changed

4 files changed

+26
-1
lines changed

fixtures/console-log.expected.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
2+
<DESCRIBE::>group 1
3+
4+
<IT::>test 1
5+
6+
<PASSED::>Test Passed
7+
8+
<COMPLETEDIN::>2
9+
10+
<COMPLETEDIN::>
11+
12+
<LOG::console.log at add (/fixtures/console-log.js:2:11)>1 1

fixtures/console-log.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
const add = (a, b) => {
2+
console.log(a, b);
3+
return a + b;
4+
};
5+
6+
describe("group 1", () => {
7+
test("test 1", () => {
8+
expect(add(1, 1)).toBe(2);
9+
});
10+
});

jest.config.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
module.exports = {
22
preset: "ts-jest",
3+
// Required to capture console.log
4+
verbose: false,
35
testEnvironment: "node",
46
};

src/codewars-reporter.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,8 @@ function _showConsoleOutput(cs: ConsoleBuffer | undefined, rootDir: string) {
171171
if (/^<(?:LOG|TAB|PROP|OUT|SWAP|TAG):(?:[A-Z]*):(?:[^>]*)>/.test(message)) {
172172
console.log(message);
173173
} else {
174-
const from = c.origin.replace(rootDir, "").replace(/^\//, "");
174+
// LogEntry.origin is a stack trace in Jest 26, use the first line.
175+
const from = c.origin.split("\n")[0].trim().replace(rootDir, "");
175176
console.log(`\n<LOG::console.${c.type} ${from}>${escapeLF(message)}`);
176177
}
177178
}

0 commit comments

Comments
 (0)