Skip to content

Commit 91802d8

Browse files
authored
Basic reporter to output scores with each eval (#12)
1 parent 21f01ad commit 91802d8

3 files changed

Lines changed: 35 additions & 4 deletions

File tree

package.json

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,17 @@
55
"types": "./dist/index.d.ts",
66
"main": "./dist/index.js",
77
"module": "./dist/index.mjs",
8-
"files": [
9-
"dist"
10-
],
8+
"files": ["dist"],
119
"exports": {
1210
".": {
1311
"types": "./dist/index.d.ts",
1412
"require": "./dist/index.js",
1513
"import": "./dist/index.mjs"
14+
},
15+
"./reporter": {
16+
"types": "./dist/reporter.d.ts",
17+
"require": "./dist/reporter.js",
18+
"import": "./dist/reporter.mjs"
1619
}
1720
},
1821
"scripts": {
@@ -37,6 +40,7 @@
3740
"homepage": "https://github.com/getsentry/vitest-evals#readme",
3841
"description": "",
3942
"peerDependencies": {
43+
"tinyrainbow": "*",
4044
"vitest": "*"
4145
},
4246
"devDependencies": {
@@ -46,6 +50,7 @@
4650
"lint-staged": "^15.5.0",
4751
"simple-git-hooks": "^2.12.1",
4852
"tsup": "^8.4.0",
53+
"tinyrainbow": "*",
4954
"typescript": "^5.8.3",
5055
"vitest": "*"
5156
},

src/reporter.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// import type { RunnerTask, RunnerTestFile } from "vitest";
2+
import { DefaultReporter } from "vitest/reporters";
3+
import c from "tinyrainbow";
4+
5+
export default class DefaultEvalReporter extends DefaultReporter {
6+
protected override printTestCase(moduleState: any, test: any): void {
7+
const meta = test.meta();
8+
const testResult = test.result();
9+
10+
if (!meta.eval || testResult.state === "failed") {
11+
super.printTestCase(moduleState, test);
12+
return;
13+
}
14+
15+
const padding = this.getTestIndentation(test.task);
16+
const colorFn =
17+
meta.eval.avgScore < 0.5
18+
? c.red
19+
: meta.eval.avgScore < 0.75
20+
? c.yellow
21+
: c.green;
22+
this.log(
23+
`${padding} ${this.getTestName(test.task, c.dim(" > "))} [${colorFn(meta.eval.avgScore.toFixed(2))}]`,
24+
);
25+
}
26+
}

tsup.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { defineConfig } from "tsup";
22

33
export default defineConfig({
4-
entry: ["src/index.ts"],
4+
entry: ["src/**/*.ts"],
55
format: ["cjs", "esm"], // Build for commonJS and ESmodules
66
dts: true, // Generate declaration file (.d.ts)
77
splitting: false,

0 commit comments

Comments
 (0)