diff --git a/lib/CleanConsoleReporter.ts b/lib/CleanConsoleReporter.ts index 6cc11c6..0cb17ad 100644 --- a/lib/CleanConsoleReporter.ts +++ b/lib/CleanConsoleReporter.ts @@ -38,8 +38,7 @@ export class CleanConsoleReporter extends DefaultReporter { console: this.filterOutKnownMessages(result.console), }; - DefaultReporter.prototype.printTestFileHeader.call(this, testPath, config, - filteredResult); + super.printTestFileHeader(testPath, config, filteredResult); } filterOutKnownMessages(consoleBuffer: LogEntry[] = []) { @@ -47,12 +46,10 @@ export class CleanConsoleReporter extends DefaultReporter { const retain: LogEntry[] = []; for (const frame of consoleBuffer) { - const {type, message} = frame; - // Check if this a known type message - const [key, keep] = getLogGroupKey(rules, message, type); + const [key, keep] = getLogGroupKey(rules, frame); if (key) { - this.groupMessageByKey(type, key); + this.groupMessageByKey(frame.type, key); if (keep) { retain.push(frame); } diff --git a/lib/getLogGroupKey.ts b/lib/getLogGroupKey.ts index dd76ac7..7c22a3f 100644 --- a/lib/getLogGroupKey.ts +++ b/lib/getLogGroupKey.ts @@ -1,8 +1,9 @@ /* global module */ import {Group, Matcher, Rule} from "./types"; import {LogType} from "@jest/console"; +import {LogEntry} from "@jest/console/build/types"; -export const matchWith = (matcher: Matcher, message: string, type: LogType, origin) => { +export const matchWith = (matcher: Matcher, message: string, type: LogType, origin: string) => { if (matcher instanceof RegExp) { return matcher.test(message); } @@ -40,7 +41,7 @@ const formatMessage = (formatter: Group, message: string, type: LogType, matcher return message; }; -const getLogGroupKey = (rules: Rule[], { message, type, origin }) => { +export const getLogGroupKey = (rules: Rule[], { message, type, origin }: LogEntry): [string | null, boolean] | [] => { for (let { match: matcher, group: formatter, keep = false } of rules) { if (matchWith(matcher, message, type, origin)) { return [formatMessage(formatter, message, type, matcher), keep]; diff --git a/lib/types.ts b/lib/types.ts index 60d91cf..0c09920 100644 --- a/lib/types.ts +++ b/lib/types.ts @@ -1,6 +1,6 @@ import {LogType} from "@jest/console"; -export type Matcher = RegExp | string | ((message: string, type: LogType) => boolean) +export type Matcher = RegExp | string | ((message: string, type: LogType, origin: string) => boolean) export type Group = string | null | ((message: string, type: LogType, matcher: Matcher) => string | null)