reporter.js 1.2 KB

123456789101112131415161718192021222324252627
  1. /* eslint-disable import/no-extraneous-dependencies */
  2. // eslint-disable-next-line @typescript-eslint/ban-ts-comment
  3. // @ts-ignore Import throws an error in internal CJS build, but seems to work fine after build
  4. import { DefaultReporter } from "vitest/reporters";
  5. import { printReporterTable } from "../utils/jestlike/reporter.js";
  6. class LangSmithEvalReporter extends DefaultReporter {
  7. async onFinished(files, errors) {
  8. super.onFinished(files, errors);
  9. for (const file of files) {
  10. for (const task of file.tasks) {
  11. const testModule = this.ctx.state.getReportedEntity(task);
  12. const tests = [...testModule.children.allTests()].map((test) => {
  13. return {
  14. title: test.name,
  15. status: test.result()?.state ?? "skipped",
  16. duration: Math.round(test.diagnostic()?.duration ?? 0),
  17. };
  18. });
  19. const result = ["pass", "fail", "skip"].includes(task.result?.state ?? "")
  20. ? task.result?.state
  21. : "skip";
  22. await printReporterTable(task.name, tests, result);
  23. }
  24. }
  25. }
  26. }
  27. export default LangSmithEvalReporter;