-
Notifications
You must be signed in to change notification settings - Fork 13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
build: switch to using typescript #3
Open
yharaskrik
wants to merge
5
commits into
jevakallio:master
Choose a base branch
from
yharaskrik:jaybell/typescript-migration
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
188e45f
build: switch to using typescript
yharaskrik fcbb791
build: remove dist folder and update package.json
yharaskrik 3e99bdb
build: update imports for LogType
yharaskrik 53f9c68
chore: update gitignore
yharaskrik e7070ac
fix: resolve merge conflicts and update function calls
yharaskrik File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,3 +5,5 @@ build | |
coverage | ||
.DS_Store | ||
/package-lock.json | ||
dist/ | ||
.idea/ |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
/* global require module */ | ||
|
||
import { Options, Rule} from "./types"; | ||
import type {Config} from '@jest/types'; | ||
import type {AggregatedResult, TestResult} from '@jest/test-result'; | ||
|
||
import {DefaultReporter} from "@jest/reporters"; | ||
import {LogEntry, LogType} from "@jest/console/build/types"; | ||
import {ReporterOnStartOptions} from "@jest/reporters/build/types"; | ||
import {getLogGroupKey} from "./getLogGroupKey"; | ||
import {getLogGroupSummary} from "./getLogGroupSummary"; | ||
|
||
/** | ||
* Overrides Jest's default reporter to filter out known console messages, | ||
* and prints a summary at the end of the test run. | ||
*/ | ||
export class CleanConsoleReporter extends DefaultReporter { | ||
|
||
private readonly rules: Rule[]; | ||
private readonly levels: LogType[]; | ||
private readonly logs: Map<LogType, Map<string, number>>; | ||
private ignored: number; | ||
|
||
constructor(globalConfig: any, options: Options = {}) { | ||
super(globalConfig); | ||
this.rules = options.rules || []; | ||
this.levels = options.levels || ["error", "warn", "info", "debug", "log"]; | ||
this.logs = new Map<LogType, Map<string, number>>(); | ||
this.ignored = 0; | ||
} | ||
|
||
// Override DefaultReporter method | ||
printTestFileHeader(testPath: Config.Path, config: Config.ProjectConfig, | ||
result: TestResult) { | ||
// Strip out known console messages before passing to base implementation | ||
const filteredResult = { | ||
...result, | ||
console: this.filterOutKnownMessages(result.console), | ||
}; | ||
|
||
super.printTestFileHeader(testPath, config, filteredResult); | ||
} | ||
|
||
filterOutKnownMessages(consoleBuffer: LogEntry[] = []) { | ||
const rules = this.rules; | ||
const retain: LogEntry[] = []; | ||
|
||
for (const frame of consoleBuffer) { | ||
// Check if this a known type message | ||
const [key, keep] = getLogGroupKey(rules, frame); | ||
if (key) { | ||
this.groupMessageByKey(frame.type, key); | ||
if (keep) { | ||
retain.push(frame); | ||
} | ||
} else if (key === null) { | ||
this.ignored++; | ||
} else { | ||
retain.push(frame); | ||
} | ||
} | ||
|
||
// Based implementation expects undefined instead of empty array | ||
return retain.length ? retain : undefined; | ||
} | ||
|
||
groupMessageByKey(type: LogType, key: string): void { | ||
// this.logs : Map<string, Map<string, number>> | ||
let level = this.logs.get(type); | ||
if (!level) { | ||
this.logs.set(type, (level = new Map<string, number>())); | ||
} | ||
|
||
level.set(key, (level.get(key) || 0) + 1); | ||
} | ||
|
||
onRunStart(aggregatedResults: AggregatedResult, | ||
options: ReporterOnStartOptions): void { | ||
super.onRunStart(aggregatedResults, options); | ||
} | ||
|
||
onRunComplete() { | ||
const summary = getLogGroupSummary(this.logs, this.levels, this.ignored); | ||
if (summary) { | ||
summary.forEach(this.log); | ||
} | ||
|
||
super.onRunComplete(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
/* global require module */ | ||
export { CleanConsoleReporter } from './CleanConsoleReporter' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import {LogType} from "@jest/console"; | ||
|
||
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) | ||
|
||
export interface Rule { | ||
match: Matcher | ||
group: Group | ||
keep?: boolean | ||
} | ||
|
||
export interface Options { | ||
rules?: Rule[], | ||
levels?: LogType[] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
reaching into
build
is not supported, iftsc
supports package exports it'll actually fail from Jest 27.I'd be happy to merge a PR in Jest that exports the types you need to build this reporter in TS
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh that is good to know! I'll add it to my list of things to do today. Thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@SimenB jestjs/jest#11017