Skip to content

Commit

Permalink
feat(betterer ✨): allow configuration of default reporter
Browse files Browse the repository at this point in the history
  • Loading branch information
PatrickElfert committed Aug 6, 2022
1 parent e4bfabd commit 0304a1d
Show file tree
Hide file tree
Showing 8 changed files with 87 additions and 8 deletions.
19 changes: 17 additions & 2 deletions goldens/api/betterer.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,10 @@ export namespace betterer {
// Warning: (ae-incompatible-release-tags) The symbol "BettererConfig" is marked as @public, but its signature references "BettererConfigBase" which is marked as @internal
// Warning: (ae-incompatible-release-tags) The symbol "BettererConfig" is marked as @public, but its signature references "BettererConfigStart" which is marked as @internal
// Warning: (ae-incompatible-release-tags) The symbol "BettererConfig" is marked as @public, but its signature references "BettererConfigWatch" which is marked as @internal
// Warning: (ae-incompatible-release-tags) The symbol "BettererConfig" is marked as @public, but its signature references "BettererConfigDefaultReporter" which is marked as @internal
//
// @public
export interface BettererConfig extends BettererConfigBase, BettererConfigStart, BettererConfigWatch {
export interface BettererConfig extends BettererConfigBase, BettererConfigStart, BettererConfigWatch, BettererConfigDefaultReporter {
}

// @internal
Expand All @@ -47,6 +48,12 @@ export interface BettererConfigBase {
workers: number;
}

// @internal
export interface BettererConfigDefaultReporter {
clearConsole: boolean;
showLogo: boolean;
}

// @public
export type BettererConfigExcludes = ReadonlyArray<RegExp>;

Expand Down Expand Up @@ -225,7 +232,7 @@ export interface BettererFileTestResultSummary {
export type BettererFileTestResultSummaryDetails = Record<string, BettererFileIssues>;

// @internal
export interface BettererOptionsBase {
export interface BettererOptionsBase extends BettererOptionsDefaultReporter {
cache?: boolean;
cachePath?: string;
configPaths?: BettererOptionsPaths;
Expand All @@ -238,6 +245,14 @@ export interface BettererOptionsBase {
workers?: number | boolean;
}

// Warning: (tsdoc-escape-right-brace) The "}" character should be escaped using a backslash to avoid confusion with a TSDoc inline tag
//
// @public
export interface BettererOptionsDefaultReporter {
clearConsole?: boolean;
showLogo?: boolean;
}

// @public
export type BettererOptionsExcludes = Array<string | RegExp> | string | RegExp;

Expand Down
17 changes: 16 additions & 1 deletion packages/betterer/src/config/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
BettererConfigMerge,
BettererConfigStart,
BettererConfigWatch,
BettererOptionsDefaultReporter,
BettererOptionsBase,
BettererOptionsMerge,
BettererOptionsOverride,
Expand All @@ -33,8 +34,9 @@ export async function createConfig(
const baseConfig = await createBaseConfig(options as BettererOptionsBase, tsconfigPath, versionControl);
const startConfig = createStartConfig(options as BettererOptionsStart);
const watchConfig = createWatchConfig(options as BettererOptionsWatch);
const defaultReporterConfig = createDefaultReporterConfig(options as BettererOptionsDefaultReporter);

const config = { ...baseConfig, ...startConfig, ...watchConfig };
const config = { ...baseConfig, ...startConfig, ...watchConfig, ...defaultReporterConfig };

modeConfig(config);

Expand Down Expand Up @@ -174,6 +176,19 @@ function createWatchConfig(options: BettererOptionsWatch): BettererConfigWatch {
};
}

function createDefaultReporterConfig(options: BettererOptionsDefaultReporter) {
const clearConsole = options.clearConsole ?? true;
const showLogo = options.showLogo ?? true;

validateBool({ clearConsole });
validateBool({ showLogo });

return {
clearConsole,
showLogo
};
}

function modeConfig(config: BettererConfig) {
// CI mode:
if (config.ci) {
Expand Down
2 changes: 2 additions & 0 deletions packages/betterer/src/config/public.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export {
BettererConfig,
BettererConfigBase,
BettererConfigDefaultReporter,
BettererConfigStart,
BettererConfigWatch,
BettererConfigExcludes,
Expand All @@ -20,6 +21,7 @@ export {
BettererOptionsResults,
BettererOptionsRunner,
BettererOptionsStartBase,
BettererOptionsDefaultReporter,
BettererOptionsStartCI,
BettererOptionsStartDefault,
BettererOptionsStartPrecommit,
Expand Down
44 changes: 42 additions & 2 deletions packages/betterer/src/config/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,11 @@ export type BettererConfigPaths = ReadonlyArray<string>;
/**
* @public Full validated config object for **Betterer**.
*/
export interface BettererConfig extends BettererConfigBase, BettererConfigStart, BettererConfigWatch {}
export interface BettererConfig
extends BettererConfigBase,
BettererConfigStart,
BettererConfigWatch,
BettererConfigDefaultReporter {}

export type BettererWorkerRunConfig = Omit<BettererConfig, 'reporter'>;

Expand Down Expand Up @@ -174,6 +178,25 @@ export interface BettererConfigMerge {
resultsPath: string;
}

/**
* @internal This could change at any point! Please don't use!
*
* Configuration for the **Betterer** default reporter.
*/
export interface BettererConfigDefaultReporter {
/**
* When `true`, the betterer logo will be shown.
* @defaultValue `true`
*/
showLogo: boolean;

/**
* When `true`, the console is cleared before each suite.
* @defaultValue `true`
*/
clearConsole: boolean;
}

/**
* @public A path to a {@link https://phenomnomnominal.github.io/betterer/docs/test-definition-file | test definition file }
* containing **Betterer** tests, or an array of them.
Expand Down Expand Up @@ -286,7 +309,7 @@ export interface BettererOptionsMerge {
*
* Base options for **Betterer** all running modes.
*/
export interface BettererOptionsBase {
export interface BettererOptionsBase extends BettererOptionsDefaultReporter {
/**
* When `true`, caching will be enabled for {@link @betterer/betterer#BettererFileTest | `BettererFileTest`s}.
* Betterer will only check files that have changes since the last test run. **Betterer** will
Expand Down Expand Up @@ -341,6 +364,7 @@ export interface BettererOptionsBase {
* The `tsconfigPath` should be relative to the `cwd`.
* @defaultValue `null`
*/

tsconfigPath?: string;
/**
* The number of {@link https://nodejs.org/api/worker_threads.html | worker threads } to use when
Expand Down Expand Up @@ -514,3 +538,19 @@ export interface BettererOptionsOverride {
*/
reporters?: BettererOptionsReporters;
}
/**
* @public Options for the **Betterer** default reporter }
*/
export interface BettererOptionsDefaultReporter {
/**
* When `true`, the betterer logo will be shown in the default reporter.
* @defaultValue `true`
*/
showLogo?: boolean;

/**
* When `true`, the console is cleared before each suite.
* @defaultValue `true`
*/
clearConsole?: boolean;
}
2 changes: 2 additions & 0 deletions packages/betterer/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export { betterer, merge, results, runner, watch } from './betterer';
export {
BettererConfig,
BettererConfigBase,
BettererConfigDefaultReporter,
BettererConfigStart,
BettererConfigWatch,
BettererConfigExcludes,
Expand All @@ -27,6 +28,7 @@ export {
BettererOptionsResults,
BettererOptionsRunner,
BettererOptionsStartBase,
BettererOptionsDefaultReporter,
BettererOptionsStartCI,
BettererOptionsStartDefault,
BettererOptionsStartPrecommit,
Expand Down
4 changes: 3 additions & 1 deletion packages/betterer/src/run/worker-run-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ export function createWorkerRunConfig(config: BettererConfig): BettererWorkerRun
update: config.update,
versionControlPath: config.versionControlPath,
watch: config.watch,
workers: config.workers
workers: config.workers,
showLogo: config.showLogo,
clearConsole: config.clearConsole
};
}
2 changes: 1 addition & 1 deletion packages/reporter/src/components/Reporter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export const Reporter: FC<BettererReporterState> = function Reporter(props: Bett

return (
<Box flexDirection="column">
<BettererLogo />
{context.config.showLogo ? <BettererLogo /> : null}
<ReporterComponent {...props} />
</Box>
);
Expand Down
5 changes: 4 additions & 1 deletion packages/reporter/src/reporter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,11 @@ function createReporter(): BettererReporter {
render(action?: BettererReporterAction, done?: () => void): void {
const state = dispatch(action);
// eslint-disable-next-line no-console
console.clear();
const component = <Reporter {...state} done={done} />;
if (context.config.clearConsole) {
// eslint-disable-next-line no-console
console.clear();
}
if (!app) {
app = render(component, RENDER_OPTIONS);
} else {
Expand Down

0 comments on commit 0304a1d

Please sign in to comment.