Skip to content

Commit

Permalink
feat(reporter ✨): merge watch reporter into default reporter (#492)
Browse files Browse the repository at this point in the history
  • Loading branch information
phenomnomnominal authored Feb 14, 2021
1 parent 23ed82c commit f92c5cd
Show file tree
Hide file tree
Showing 89 changed files with 1,606 additions and 2,243 deletions.
5 changes: 3 additions & 2 deletions goldens/api/@betterer/betterer.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export declare type BettererConfig = {
silent: boolean;
tsconfigPath: string | null;
update: boolean;
watch: boolean;
};

export declare type BettererConfigFilters = ReadonlyArray<RegExp>;
Expand Down Expand Up @@ -127,8 +128,8 @@ export declare type BettererReporter = {
contextStart?(context: BettererContext, lifecycle: Promise<BettererSummaries>): Promise<void> | void;
contextEnd?(context: BettererContext, summary: BettererSummaries): Promise<void> | void;
contextError?(context: BettererContext, error: BettererError): Promise<void> | void;
runsStart?(runs: BettererRuns, files: BettererFilePaths): Promise<void> | void;
runsEnd?(summary: BettererSummary, files: BettererFilePaths): Promise<void> | void;
runsStart?(runs: BettererRuns, filePaths: BettererFilePaths): Promise<void> | void;
runsEnd?(summary: BettererSummary, filePaths: BettererFilePaths): Promise<void> | void;
runStart?(run: BettererRun, lifecycle: Promise<void>): Promise<void> | void;
runEnd?(run: BettererRun): Promise<void> | void;
runError?(run: BettererRun, error: BettererError): Promise<void> | void;
Expand Down
13 changes: 0 additions & 13 deletions goldens/api/@betterer/logger.d.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,3 @@
export declare class BettererConsoleLogger implements BettererLogger {
debug: BettererLogMessage;
error: BettererLogMessage;
info: BettererLogMessage;
progress: BettererLogMessage;
success: BettererLogMessage;
warn: BettererLogMessage;
constructor();
code(codeInfo: BettererLoggerCodeInfo): Promise<void>;
}

export declare const BettererErrorLog: FC<BettererErrorLogProps>;

export declare type BettererErrorLogProps = {
Expand Down Expand Up @@ -81,5 +70,3 @@ export declare type BettererTasksState = {
export declare type BettererTasksStatusUpdate = (state: BettererTasksState) => string;

export declare function diffΔ<T>(expected: T, result: T): string | null;

export declare const LOGO = "\n \\ | / _ _ _ \n '-.ooo.-' | |__ ___| |_| |_ ___ _ __ ___ _ __ \n---ooooo--- | '_ \\/ _ \\ __| __/ _ \\ '__/ _ \\ '__|\n .-'ooo'-. | |_)| __/ |_| || __/ | | __/ | \n / | \\ |_.__/\\___|\\__|\\__\\___|_| \\___|_| \n ";
30 changes: 1 addition & 29 deletions goldens/api/@betterer/reporter.d.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1 @@
export declare function quoteΔ(str: string): string;

export declare const reporter: import("@betterer/betterer").BettererReporter;

export declare function testBetterΔ(context: string): string;

export declare function testCheckedΔ(context: string): string;

export declare function testCompleteΔ(context: string, isNew?: boolean): string;

export declare function testExpiredΔ(context: string): string;

export declare function testFailedΔ(context: string): string;

export declare function testNewΔ(context: string): string;

export declare function testObsoleteΔ(context: string): string;

export declare function testRunningΔ(context: string): string;

export declare function testSameΔ(context: string): string;

export declare function testSkippedΔ(context: string): string;

export declare function testUpdatedΔ(context: string): string;

export declare function testWorseΔ(context: string): string;

export declare function updateInstructionsΔ(): string;
export declare const reporter: BettererReporter;
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@
"eslint-plugin-jest": "^24.0.1",
"eslint-plugin-prettier": "^3.1.4",
"husky": "^4.3.0",
"ink": "^3.0.7",
"jest": "^26.5.3",
"fs-extra": "^9.0.1",
"graceful-fs": "^4.2.3",
Expand Down
1 change: 0 additions & 1 deletion packages/betterer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
"@betterer/errors": "^3.1.1",
"@betterer/logger": "^3.1.1",
"@betterer/reporter": "^3.1.2",
"@betterer/watch-reporter": "^3.1.2",
"@phenomnomnominal/debug": "^0.2.5",
"callsite": "^1.0.0",
"chokidar": "^3.3.1",
Expand Down
2 changes: 1 addition & 1 deletion packages/betterer/src/config/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export async function createConfig(partialConfig: BettererConfigPartial = {}): P
silent: partialConfig.silent || false,
tsconfigPath: partialConfig.tsconfigPath || null,
update: (partialConfig as BettererStartConfigPartial).update || false,
watch: partialConfig.watch
watch: partialConfig.watch || false
};

validateConfig(relativeConfig);
Expand Down
1 change: 1 addition & 0 deletions packages/betterer/src/config/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export type BettererConfig = {
silent: boolean;
tsconfigPath: string | null;
update: boolean;
watch: boolean;
};

export type BettererBaseConfigPartial = Partial<{
Expand Down
1 change: 1 addition & 0 deletions packages/betterer/src/context/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ export class BettererContextΩ implements BettererContext {
}

private _initFilters(): void {
// read `filters` here so that it can be updated by watch mode:
const { filters } = this.config;
if (filters.length) {
Object.keys(this._tests).forEach((name) => {
Expand Down
2 changes: 1 addition & 1 deletion packages/betterer/src/reporters/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export { BettererReporterΩ } from './reporter';
export { loadReporters, DEFAULT_REPORTER, WATCH_REPORTER } from './loader';
export { loadReporters, DEFAULT_REPORTER } from './loader';
export { BettererReporter, BettererReporterModule } from './types';
1 change: 0 additions & 1 deletion packages/betterer/src/reporters/loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { BettererReporterΩ } from './reporter';
import { BettererReporter, BettererReporterModule } from './types';

export const DEFAULT_REPORTER = '@betterer/reporter';
export const WATCH_REPORTER = '@betterer/watch-reporter';

const HOOK_NAMES = Object.getOwnPropertyNames(BettererReporterΩ.prototype) as ReadonlyArray<keyof BettererReporter>;

Expand Down
4 changes: 2 additions & 2 deletions packages/betterer/src/reporters/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ export type BettererReporter = {
contextStart?(context: BettererContext, lifecycle: Promise<BettererSummaries>): Promise<void> | void;
contextEnd?(context: BettererContext, summary: BettererSummaries): Promise<void> | void;
contextError?(context: BettererContext, error: BettererError): Promise<void> | void;
runsStart?(runs: BettererRuns, files: BettererFilePaths): Promise<void> | void;
runsEnd?(summary: BettererSummary, files: BettererFilePaths): Promise<void> | void;
runsStart?(runs: BettererRuns, filePaths: BettererFilePaths): Promise<void> | void;
runsEnd?(summary: BettererSummary, filePaths: BettererFilePaths): Promise<void> | void;
runStart?(run: BettererRun, lifecycle: Promise<void>): Promise<void> | void;
runEnd?(run: BettererRun): Promise<void> | void;
runError?(run: BettererRun, error: BettererError): Promise<void> | void;
Expand Down
1 change: 1 addition & 0 deletions packages/betterer/src/results/results.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { parse } from './parser';
import { print } from './printer';
import { BettererResultΩ } from './result';
import { BettererResult, BettererResultValue } from './types';

const RESULTS_HEADER = `// BETTERER RESULTS V2.`;

export class BettererResults {
Expand Down
5 changes: 2 additions & 3 deletions packages/betterer/src/runner/runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import assert from 'assert';
import { BettererConfigPartial, createConfig } from '../config';
import { BettererContextΩ, BettererRun, BettererRunΩ, BettererSummary } from '../context';
import { registerExtensions } from '../register';
import { DEFAULT_REPORTER, WATCH_REPORTER, loadReporters } from '../reporters';
import { DEFAULT_REPORTER, loadReporters } from '../reporters';
import { BettererResultΩ } from '../results';
import { normalisedPath } from '../utils';
import { BettererFilePaths, BettererRunHandler, BettererRunner, BettererRunnerJobs } from './types';
Expand All @@ -18,8 +18,7 @@ export class BettererRunnerΩ implements BettererRunner {

public async start(partialConfig: BettererConfigPartial = {}): Promise<BettererContextΩ> {
let config = null;
const reporterName = partialConfig.watch ? WATCH_REPORTER : DEFAULT_REPORTER;
let reporter = loadReporters([reporterName]);
let reporter = loadReporters([DEFAULT_REPORTER]);
try {
config = await createConfig(partialConfig);
registerExtensions(config);
Expand Down
1 change: 1 addition & 0 deletions packages/betterer/src/runner/watcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export class BettererWatcherΩ implements BettererRunner {
ignoreInitial: true,
ignored: (itemPath: string) => {
const isGitIgnored = globby.gitignore.sync();
// read `ignores` here so that it can be updated by watch mode:
const { ignores } = contextΩ.config;
const watchIgnores = [...ignores, GIT_DIRECTORY].map((ignore) => path.join(cwd, ignore));
return (
Expand Down
1 change: 0 additions & 1 deletion packages/betterer/src/test/test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { BettererResultValue } from '../results';
import { createTestConfig } from './config';

import { BettererTestBase, BettererTestConfig, BettererTestConfigPartial } from './types';

const IS_BETTERER_TEST = 'isBettererTest';
Expand Down
33 changes: 17 additions & 16 deletions packages/fixture/src/logging.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,15 @@ const PROJECT_REGEXP = new RegExp(normalisePaths(process.cwd()), 'g');
const STACK_TRACK_LINE_REGEXP = /\s+at\s+/;

export function createFixtureLogs(options: FixtureOptions = {}): FixtureLogs {
const logs: Array<string> = [];
const snapshotLogs: Array<string> = [];
const log = (...messages: Array<string>): void => {
if (options.logStack) {
try {
throw new Error();
} catch (e) {
logs.push((e as Error).stack || '');
}
}
const previousLength = snapshotLogs.length;

// Do some magic to sort out the logs for snapshots. This mucks up the snapshot of the printed logo,
// but that hardly matters...
messages.forEach((message) => {
if (!isString(message)) {
logs.push(message);
snapshotLogs.push(message);
return;
}
message = replaceAnsi(message);
Expand All @@ -40,24 +34,31 @@ export function createFixtureLogs(options: FixtureOptions = {}): FixtureLogs {
if (trimmed.length === 0) {
return;
}
logs.push(message);
const [previous] = snapshotLogs.slice(-1);
if (message !== previous) {
snapshotLogs.push(message);
}
});

if (options.logStack && snapshotLogs.length !== previousLength) {
try {
throw new Error();
} catch (e) {
snapshotLogs.push((e as Error).stack || '');
}
}
};

jest.spyOn(console, 'log').mockImplementation(log);
jest.spyOn(console, 'error').mockImplementation((message: string) => {
const [firstLine] = message.split('\n');
log(firstLine);
});
jest.spyOn(process.stdout, 'write').mockImplementation((message: string | Uint8Array): boolean => {
if (message) {
log(message.toString());
}
return true;
});
process.stdout.columns = 1000;
process.stdout.rows = 20;

return logs as FixtureLogs;
return snapshotLogs as FixtureLogs;
}

function isString(message: unknown): message is string {
Expand Down
2 changes: 1 addition & 1 deletion packages/logger/src/code.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@ export function code(codeInfo: BettererLoggerCodeInfo): string {
line: endLocation.line + 1,
column: endLocation.column + 1
};
return `\n // ${filePath}\n${codeFrameColumns(fileText, { start, end }, options)}\n`;
return `\n ${filePath}\n${codeFrameColumns(fileText, { start, end }, options)}\n`;
}
17 changes: 10 additions & 7 deletions packages/logger/src/components/logo.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import { Box, Text } from 'ink';
import React, { FC } from 'react';

import { LOGO } from '../logo';
import { Text } from 'ink';

const LOGO = `
\\ | / _ _ _
'-.ooo.-' | |__ ___| |_| |_ ___ _ __ ___ _ __
---ooooo--- | '_ \\/ _ \\ __| __/ _ \\ '__/ _ \\ '__|
.-'ooo'-. | |_)| __/ |_| || __/ | | __/ |
/ | \\ |_.__/\\___|\\__|\\__\\___|_| \\___|_|
`;

export const BettererLogo: FC = function BettererLogo() {
return (
<Box flexDirection="column">
<Text color="yellowBright">{LOGO}</Text>
</Box>
);
return <Text color="yellowBright">{LOGO}</Text>;
};
1 change: 0 additions & 1 deletion packages/logger/src/components/tasks/types.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { ForegroundColor } from 'chalk';

import { BettererLogger } from '../../types';

import { BettererTasksState } from './useTasksState';

export type BettererTasksStatusUpdate = (state: BettererTasksState) => string;
Expand Down
48 changes: 0 additions & 48 deletions packages/logger/src/console-logger.ts

This file was deleted.

2 changes: 0 additions & 2 deletions packages/logger/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
export { BettererConsoleLogger } from './console-logger';
export { diffΔ } from './diff';
export { LOGO } from './logo';
export {
BettererErrorLog,
BettererErrorLogProps,
Expand Down
7 changes: 0 additions & 7 deletions packages/logger/src/logo.ts

This file was deleted.

2 changes: 2 additions & 0 deletions packages/reporter/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
"@betterer/betterer": "^3.1.2",
"@betterer/errors": "^3.1.1",
"@betterer/logger": "^3.1.1",
"ink": "^3.0.7",
"ink-text-input": "^4.0.1",
"tslib": "^2.0.3"
}
}
11 changes: 8 additions & 3 deletions packages/reporter/src/components/Error.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import React, { FC, useEffect } from 'react';

import { BettererError } from '@betterer/errors';
import { BettererErrorLog } from '@betterer/logger';
import { useApp } from 'ink';
import { BettererErrorLog, BettererLogo } from '@betterer/logger';
import { Box, useApp } from 'ink';

export type ErrorProps = {
error: BettererError;
Expand All @@ -14,5 +14,10 @@ export const Error: FC<ErrorProps> = function Error({ error }) {
setImmediate(() => app.exit());
}, [app]);

return <BettererErrorLog error={error} />;
return (
<Box flexDirection="column" paddingBottom={1}>
<BettererLogo></BettererLogo>
<BettererErrorLog error={error} />
</Box>
);
};
Loading

0 comments on commit f92c5cd

Please sign in to comment.