-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e2e9e57
commit 784b2fa
Showing
32 changed files
with
495 additions
and
157 deletions.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,29 @@ | ||
import { BettererReporterNames } from '../reporters'; | ||
|
||
export type BettererConfigPaths = ReadonlyArray<string>; | ||
export type BettererConfigFilters = ReadonlyArray<RegExp>; | ||
export type BettererConfigIgnore = ReadonlyArray<string>; | ||
|
||
export type BettererConfigPartial = Partial<{ | ||
configPaths: BettererConfigPaths | string; | ||
resultsPath: string; | ||
tsconfigPath: string; | ||
cwd: string; | ||
filters: BettererConfigFilters | ReadonlyArray<string> | string; | ||
ignores: BettererConfigIgnore | string; | ||
cwd: string; | ||
update: boolean; | ||
reporters: BettererReporterNames; | ||
resultsPath: string; | ||
silent: boolean; | ||
tsconfigPath: string; | ||
update: boolean; | ||
}>; | ||
|
||
export type BettererConfig = { | ||
configPaths: BettererConfigPaths; | ||
resultsPath: string; | ||
tsconfigPath: string | null; | ||
cwd: string; | ||
filters: BettererConfigFilters; | ||
ignores: BettererConfigIgnore; | ||
cwd: string; | ||
update: boolean; | ||
reporters: BettererReporterNames; | ||
resultsPath: string; | ||
silent: boolean; | ||
tsconfigPath: string | null; | ||
update: boolean; | ||
}; |
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 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 |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export { reporterParallel, reporterSerial } from './reporters'; | ||
export { BettererMultiReporter } from './reporter-multi'; | ||
export { loadReporters, DEFAULT_REPORTER, WATCH_REPORTER } from './loader'; | ||
export * from './types'; |
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,47 @@ | ||
import { COULDNT_LOAD_REPORTER, NO_REPORTER_LOADED, UNKNOWN_HOOK_NAME, HOOK_NOT_A_FUNCTION } from '../errors'; | ||
import { requireUncached } from '../require'; | ||
import { BettererMultiReporter } from './reporter-multi'; | ||
import { BettererReporterNames, BettererReporter, BettererReporterModule } from './types'; | ||
import { isFunction } from '../utils'; | ||
|
||
export const DEFAULT_REPORTER = '@betterer/reporter'; | ||
export const WATCH_REPORTER = '@betterer/watch-reporter'; | ||
|
||
const HOOK_NAMES: ReadonlyArray<keyof BettererReporter> = [ | ||
'contextStart', | ||
'contextEnd', | ||
'contextError', | ||
'runsStart', | ||
'runsEnd', | ||
'runStart', | ||
'runEnd' | ||
]; | ||
|
||
export function loadReporters(reporterNames: BettererReporterNames): BettererMultiReporter { | ||
const reporters: Array<BettererReporter> = reporterNames.map((name) => { | ||
try { | ||
const module: BettererReporterModule = requireUncached(name); | ||
if (!module || !module.reporter) { | ||
throw NO_REPORTER_LOADED(name); | ||
} | ||
validate(module.reporter); | ||
return module.reporter; | ||
} catch (e) { | ||
throw COULDNT_LOAD_REPORTER(name, e); | ||
} | ||
}); | ||
return new BettererMultiReporter(reporters); | ||
} | ||
|
||
function validate(result: unknown): asserts result is BettererReporter { | ||
const reporter = result as BettererReporter; | ||
Object.keys(reporter).forEach((key) => { | ||
const hookName = key as keyof BettererReporter; | ||
if (!HOOK_NAMES.includes(hookName)) { | ||
throw UNKNOWN_HOOK_NAME(hookName); | ||
} | ||
if (!isFunction(reporter[hookName])) { | ||
throw HOOK_NOT_A_FUNCTION(hookName); | ||
} | ||
}); | ||
} |
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,31 @@ | ||
import { BettererError } from '@betterer/errors'; | ||
|
||
import { BettererContext, BettererRun, BettererRuns, BettererStats } from '../context'; | ||
import { BettererFilePaths } from '../test'; | ||
import { BettererReporter } from './types'; | ||
|
||
export class BettererMultiReporter implements BettererReporter { | ||
constructor(private _reporters: Array<BettererReporter>) {} | ||
|
||
contextStart(context: BettererContext): void { | ||
this._reporters.forEach((r) => r.contextStart?.(context)); | ||
} | ||
contextEnd(context: BettererContext, stats: BettererStats): void { | ||
this._reporters.forEach((r) => r.contextEnd?.(context, stats)); | ||
} | ||
contextError(context: BettererContext, error: BettererError, printed: Array<string>): void { | ||
this._reporters.forEach((r) => r.contextError?.(context, error, printed)); | ||
} | ||
runsStart(runs: BettererRuns, files: BettererFilePaths): void { | ||
this._reporters.forEach((r) => r.runsStart?.(runs, files)); | ||
} | ||
runsEnd(runs: BettererRuns, files: BettererFilePaths): void { | ||
this._reporters.forEach((r) => r.runsEnd?.(runs, files)); | ||
} | ||
runStart(run: BettererRun): void { | ||
this._reporters.forEach((r) => r.runStart?.(run)); | ||
} | ||
runEnd(run: BettererRun): void { | ||
this._reporters.forEach((r) => r.runEnd?.(run)); | ||
} | ||
} |
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
Oops, something went wrong.