Skip to content

Commit

Permalink
feat: allow toggling tags
Browse files Browse the repository at this point in the history
  • Loading branch information
tstelzer committed Apr 22, 2024
1 parent 93e9133 commit 4cdc90b
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 7 deletions.
8 changes: 8 additions & 0 deletions workspace/cli/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# @creative-introvert/prediction-testing-cli

## 0.0.4

### Patch Changes

- Feat: Allow toggling tags.
- Updated dependencies
- @creative-introvert/prediction-testing@0.0.7

## 0.0.3

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion workspace/cli/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@creative-introvert/prediction-testing-cli",
"version": "0.0.3",
"version": "0.0.4",
"type": "module",
"license": "MIT",
"sideEffects": [],
Expand Down
5 changes: 5 additions & 0 deletions workspace/cli/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export type Config<I = unknown, O = unknown, T = unknown> = {
showInput?: undefined | ((input: I) => string);
showExpected?: undefined | ((expected: T) => string);
showResult?: undefined | ((result: O, expected: T) => string);
showTags?: undefined | boolean;
isResultNil?: undefined | ((result: O) => boolean);
};

Expand Down Expand Up @@ -65,6 +66,7 @@ const summarize = Command.make('summarize', {labels}, ({labels}) =>
showExpected,
showResult,
displayConfig,
showTags,
} = yield* _(Config);

const filterLabel = createFilterLabel(labels);
Expand Down Expand Up @@ -92,6 +94,7 @@ const summarize = Command.make('summarize', {labels}, ({labels}) =>
showExpected,
showResult,
displayConfig,
showTags,
}),
'',
PT.Show.stats({testRun}),
Expand All @@ -116,6 +119,7 @@ const diff = Command.make('diff', {ci}, ({ci}) =>
showExpected,
showResult,
displayConfig,
showTags,
} = yield* _(Config);

const previousTestRun = yield* _(readPreviousTestRun);
Expand Down Expand Up @@ -157,6 +161,7 @@ const diff = Command.make('diff', {ci}, ({ci}) =>
showExpected,
showResult,
displayConfig,
showTags,
}),
'',
PT.Show.diff({
Expand Down
6 changes: 6 additions & 0 deletions workspace/core/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# @creative-introvert/prediction-testing

## 0.0.7

### Patch Changes

- Feat: Allow toggling tags.

## 0.0.6

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion workspace/core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@creative-introvert/prediction-testing",
"version": "0.0.6",
"version": "0.0.7",
"type": "module",
"license": "MIT",
"sideEffects": [],
Expand Down
21 changes: 16 additions & 5 deletions workspace/core/src/Show.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ export const summary = <I, O, T>({
showInput = showValue,
showExpected = showValue,
showResult = showValue,
showTags = true,
}: {
testRun: Test._TestRun<I, O, T>;
previousTestRun?: P.O.Option<Test._TestRun<I, O, T>>;
Expand All @@ -183,6 +184,7 @@ export const summary = <I, O, T>({
showInput?: ((input: I) => string) | undefined;
showExpected?: ((expected: T) => string) | undefined;
showResult?: ((result: O, expected: T) => string) | undefined;
showTags?: boolean | undefined;
}): string => {
const cfg = {...DisplayConfig.default(), ...displayConfig};

Expand All @@ -191,6 +193,8 @@ export const summary = <I, O, T>({
const ids = testRun.testResultIds;
const rows = Rows.empty<I, O, T>();

const _columns = showTags ? columns : columns.filter(s => s !== 'tags');

for (let i = 0; i < ids.length; i++) {
const id = ids[i];

Expand Down Expand Up @@ -230,13 +234,13 @@ export const summary = <I, O, T>({

rows.widths = getWidths({
display,
columns,
columns: _columns,
previousWidths: rows.widths,
});
}

const _headers = createHeaders({
columns,
columns: _columns,
widths: rows.widths,
});

Expand All @@ -255,8 +259,15 @@ export const summary = <I, O, T>({
_ => _.result,
).pipe(P.O.isSome);

const row: string[] = [
colors.gray.italic(display.tags.padEnd(rows.widths.tags)),
const row: string[] = (
showTags
? [
colors.gray.italic(
display.tags.padEnd(rows.widths.tags),
),
]
: []
).concat([
_colorLabel(
testResult.label,
!display.hasPrevious,
Expand All @@ -280,7 +291,7 @@ export const summary = <I, O, T>({
),
}),
),
];
]);

const prev = i > 0 ? xs[i - 1] : undefined;
if (prev?.testResult.id !== testResult.id) {
Expand Down
8 changes: 8 additions & 0 deletions workspace/examples/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@

### Patch Changes

- Updated dependencies
- @creative-introvert/prediction-testing@0.0.7
- @creative-introvert/prediction-testing-cli@0.0.4

## null

### Patch Changes

- Updated dependencies
- @creative-introvert/prediction-testing-cli@0.0.3

Expand Down
1 change: 1 addition & 0 deletions workspace/examples/src/with-cli/simple.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ void CLI.run({
{input: 4, expected: 5},
],
},
showTags: false,
testSuiteName: 'simple',
// Currently, test results are written to the file-system.
// This will be replaced by an SQLite backend soon™.
Expand Down

0 comments on commit 4cdc90b

Please sign in to comment.