Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/better show console #3

Merged
merged 1 commit into from
May 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -271,8 +271,3 @@ come with its own limitations.
Providing `prediction-testing` as a pure library is not as satisfying and
convenient as a dedicated binary, but is both simpler, and more easily
customizable.

## TODO

- sqlite backend
- Basic performance measurements.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"eslint-plugin-unicorn": "^51.0.1",
"eslint-plugin-unused-imports": "^3.1.0",
"prettier": "^3.2.5",
"tsx": "^4.7.1",
"tsx": "^4.7.3",
"typescript": "^5.4.5"
}
}
629 changes: 351 additions & 278 deletions pnpm-lock.yaml

Large diffs are not rendered by default.

11 changes: 11 additions & 0 deletions workspace/cli/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
# @creative-introvert/prediction-testing-cli

## 0.1.0

### Minor Changes

- Feat: Better Show.

### Patch Changes

- Updated dependencies
- @creative-introvert/[email protected]

## 0.0.4

### Patch Changes
Expand Down
16 changes: 8 additions & 8 deletions 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.4",
"version": "0.1.0",
"type": "module",
"license": "MIT",
"sideEffects": [],
Expand Down Expand Up @@ -30,22 +30,22 @@
},
"devDependencies": {
"@babel/cli": "^7.24.1",
"@babel/core": "^7.24.3",
"@babel/core": "^7.24.4",
"@babel/plugin-transform-export-namespace-from": "^7.24.1",
"@babel/plugin-transform-modules-commonjs": "^7.24.1",
"@creative-introvert/eslint-config": "^0.3.2",
"@creative-introvert/prettier-config": "^0.2.0",
"babel-plugin-annotate-pure-calls": "^0.4.0",
"ts-node": "^10.9.2",
"type-fest": "^4.14.0"
"type-fest": "^4.17.0"
},
"dependencies": {
"@creative-introvert/prediction-testing": "workspace:*",
"@effect/cli": "^0.36.6",
"@effect/platform": "^0.50.1",
"@effect/platform-node": "^0.47.1",
"@effect/schema": "^0.66.4",
"@effect/cli": "^0.36.14",
"@effect/platform": "^0.51.0",
"@effect/platform-node": "^0.48.0",
"@effect/schema": "^0.66.12",
"ansi-colors": "^4.1.3",
"effect": "3.0.3"
"effect": "3.1.0"
}
}
165 changes: 71 additions & 94 deletions workspace/cli/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,14 @@ import * as PT from '@creative-introvert/prediction-testing';
import * as P from './prelude.js';

export type Config<I = unknown, O = unknown, T = unknown> = {
testSuite: PT.TestSuite<I, O, T>;
testSuite: PT.Test.TestSuite<I, O, T>;
dirPath: string;
filePostfix: string;
testSuiteName: string;
displayConfig?: Partial<PT.Show.DisplayConfig> | undefined;
displayConfig?: Partial<PT.DisplayConfig.DisplayConfig> | undefined;
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 All @@ -39,67 +38,59 @@ const labels = Options.text('labels').pipe(

const createFilterLabel =
(maybeLables: P.O.Option<readonly PT.Classify.Label[]>) =>
(tr: PT.TestResult<unknown, unknown, unknown>) =>
(tr: PT.Test.TestResult<unknown, unknown, unknown>) =>
P.O.match(maybeLables, {
onNone: () => true,
onSome: labels => labels.includes(tr.label),
});

const TestRunSchema = P.Schema.parseJson(PT.TestRunSchema);
const TestRunSchema = P.Schema.parseJson(PT.Test.TestRunSchema);

const readPreviousTestRun = P.E.gen(function* (_) {
const {testSuiteName, dirPath, filePostfix} = yield* _(Config);
const fs = yield* _(P.FS.FileSystem);
return yield* _(
fs.readFileString(`${dirPath}/${testSuiteName}.${filePostfix}.json`),
P.E.flatMap(P.Schema.decodeUnknown(TestRunSchema)),
P.E.option,
);
const readPreviousTestRun = P.E.gen(function* () {
const {testSuiteName, dirPath, filePostfix} = yield* Config;
const fs = yield* P.FS.FileSystem;
return yield* fs
.readFileString(`${dirPath}/${testSuiteName}.${filePostfix}.json`)
.pipe(P.E.flatMap(P.Schema.decodeUnknown(TestRunSchema)), P.E.option);
});

const summarize = Command.make('summarize', {labels}, ({labels}) =>
P.E.gen(function* (_) {
P.E.gen(function* () {
const {
testSuite,
isResultNil,
showInput,
showExpected,
showResult,
displayConfig,
showTags,
} = yield* _(Config);
} = yield* Config;

const filterLabel = createFilterLabel(labels);
const previousTestRun = yield* _(readPreviousTestRun);
const testRun = yield* _(
PT.testAll(testSuite).pipe(
P.Stream.filter(filterLabel),
PT.runFoldEffect,
),
const previousTestRun = yield* readPreviousTestRun;
const testRun = yield* PT.Test.all(testSuite).pipe(
P.Stream.filter(filterLabel),
PT.Test.runFoldEffect,
);

if (testRun.testResultIds.length === 0) {
yield* _(P.Console.log('Nothing to show.'));
yield* P.Console.log('Nothing to show.');
return;
}

yield* _(
P.Console.log(
[
PT.Show.summary({
testRun,
previousTestRun,
isResultNil,
showInput,
showExpected,
showResult,
displayConfig,
showTags,
}),
'',
PT.Show.stats({testRun}),
].join('\n'),
),
yield* P.Console.log(
[
PT.Show.summarize({
testRun,
previousTestRun,
// isResultNil,
// showInput,
// showExpected,
// showResult,
displayConfig,
}),
'',
PT.Show.stats({testRun}),
].join('\n'),
);
}),
);
Expand All @@ -111,87 +102,73 @@ const ci = Options.boolean('ci').pipe(
);

const diff = Command.make('diff', {ci}, ({ci}) =>
P.E.gen(function* (_) {
P.E.gen(function* () {
const {
testSuite,
isResultNil,
showInput,
showExpected,
showResult,
displayConfig,
showTags,
} = yield* _(Config);

const previousTestRun = yield* _(readPreviousTestRun);

const testRun = yield* _(
PT.testAll(testSuite).pipe(
P.Stream.filter(next =>
P.pipe(
P.O.flatMap(previousTestRun, prevTestRun =>
P.O.fromNullable(
prevTestRun.testResultsById[next.id],
),
),
P.O.map(
prev =>
prev.label !== next.label ||
!isDeepStrictEqual(prev.result, next.result),
),
P.O.getOrElse(() => true),
} = yield* Config;

const previousTestRun = yield* readPreviousTestRun;

const testRun = yield* PT.Test.all(testSuite).pipe(
P.Stream.filter(next =>
P.pipe(
P.O.flatMap(previousTestRun, prevTestRun =>
P.O.fromNullable(prevTestRun.testResultsById[next.id]),
),
P.O.map(
prev =>
prev.label !== next.label ||
!isDeepStrictEqual(prev.result, next.result),
),
P.O.getOrElse(() => true),
),
PT.runFoldEffect,
),
PT.Test.runFoldEffect,
);

if (testRun.testResultIds.length === 0) {
yield* _(P.Console.log('Nothing to show.'));
yield* P.Console.log('Nothing to show.');
return;
}

yield* _(
P.Console.log(
[
PT.Show.summary({
testRun,
previousTestRun,
isResultNil,
showInput,
showExpected,
showResult,
displayConfig,
showTags,
}),
'',
PT.Show.diff({
testRun,
diff: PT.diff({testRun, previousTestRun}),
}),
].join('\n'),
),
yield* P.Console.log(
[
PT.Show.summarize({
testRun,
previousTestRun,
displayConfig,
}),
'',
PT.Show.diff({
diff: PT.Test.diff({testRun, previousTestRun}),
}),
].join('\n'),
);
if (ci) {
yield* _(P.E.die('Non-empty diff.'));
yield* P.E.die('Non-empty diff.');
}
}),
);

// FIXME: Either sqlite backend, csv, or use line-delimited JSON.
const write = Command.make('write', {}, () =>
P.E.gen(function* (_) {
const {testSuite, dirPath, testSuiteName, filePostfix} =
yield* _(Config);
const fs = yield* _(P.FS.FileSystem);
P.E.gen(function* () {
const {testSuite, dirPath, testSuiteName, filePostfix} = yield* Config;
const fs = yield* P.FS.FileSystem;

yield* _(fs.makeDirectory(dirPath, {recursive: true}));
yield* fs.makeDirectory(dirPath, {recursive: true});

const testRun = yield* _(PT.testAll(testSuite).pipe(PT.runFoldEffect));
const filePath = `${dirPath}/${testSuiteName}.${filePostfix}.json`;
yield* _(
fs.writeFileString(filePath, JSON.stringify(testRun, null, 2)),
const testRun = yield* PT.Test.all(testSuite).pipe(
PT.Test.runFoldEffect,
);
yield* _(P.Console.log(`Wrote to "${filePath}"`));
const filePath = `${dirPath}/${testSuiteName}.${filePostfix}.json`;
yield* fs.writeFileString(filePath, JSON.stringify(testRun, null, 2));
yield* P.Console.log(`Wrote to "${filePath}"`);
}),
);

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.1.0

### Minor Changes

- Feat: Better Show.

## 0.0.7

### Patch Changes
Expand Down
15 changes: 8 additions & 7 deletions 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.7",
"version": "0.1.0",
"type": "module",
"license": "MIT",
"sideEffects": [],
Expand Down Expand Up @@ -30,19 +30,20 @@
},
"devDependencies": {
"@babel/cli": "^7.24.1",
"@babel/core": "^7.24.3",
"@babel/core": "^7.24.4",
"@babel/plugin-transform-export-namespace-from": "^7.24.1",
"@babel/plugin-transform-modules-commonjs": "^7.24.1",
"@creative-introvert/eslint-config": "^0.3.2",
"@creative-introvert/prettier-config": "^0.2.0",
"babel-plugin-annotate-pure-calls": "^0.4.0",
"type-fest": "^4.14.0"
"type-fest": "^4.17.0"
},
"dependencies": {
"@effect/platform": "^0.50.1",
"@effect/platform-node": "^0.47.1",
"@effect/schema": "^0.66.4",
"@effect/platform": "^0.51.0",
"@effect/platform-node": "^0.48.0",
"@effect/schema": "^0.66.12",
"ansi-colors": "^4.1.3",
"effect": "3.0.3"
"effect": "3.1.0",
"jsondiffpatch": "^0.6.0"
}
}
Loading