Last active
October 7, 2021 21:51
-
-
Save ryparker/188849eb0f78f53316ef99bf6a4467d5 to your computer and use it in GitHub Desktop.
Create custom Jest reporters using this interface. Template repo available here: https://github.com/ryparker/jest-reporter-template
This file contains hidden or 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
import { | |
AggregatedResult, | |
Config, | |
Context, | |
Reporter, | |
ReporterOnStartOptions, | |
Test, | |
TestResult, | |
} from '@jest/reporters' | |
export default class JestReporter implements Reporter { | |
private _error?: Error | |
protected _globalConfig: Config.GlobalConfig | |
protected _options?: any | |
constructor(globalConfig: Config.GlobalConfig, options?: any) { | |
this._globalConfig = globalConfig | |
this._options = options | |
} | |
log(message: string): void { | |
console.log(`log arguments: ${JSON.stringify(arguments)}`) | |
} | |
onRunStart( | |
aggregatedResults: AggregatedResult, | |
options: ReporterOnStartOptions | |
): void { | |
console.log(`onRunStart arguments: ${JSON.stringify(arguments)}`) | |
} | |
onTestStart(test?: Test): void { | |
console.log(`onTestStart arguments: ${JSON.stringify(arguments)}`) | |
} | |
onTestResult( | |
test: Test, | |
testResult: TestResult, | |
aggregatedResults: AggregatedResult | |
): void { | |
console.log(`onTestResult arguments: ${JSON.stringify(arguments)}`) | |
} | |
onRunComplete( | |
test?: Set<Context>, | |
runResults?: AggregatedResult | |
): Promise<void> | void { | |
console.log(`onRunComplete arguments: ${JSON.stringify(arguments)}`) | |
} | |
getLastError(): Error | undefined { | |
return this._error | |
} | |
protected _setError(error: Error): void { | |
this._error = error | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment