UNPKG

eval-genius

Version:

eval-genius enables evals of arbitrary async code. It is generally intended for making multiple assertions on outputs which are generated nondeterministically. These assertions can be used to score algorithms on their effectiveness.

2 lines (1 loc) 1.13 kB
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const l=n=>typeof n=="function"?n():n,S=async({vitest:n,concurrent:p,metadata:a,data:w,task:o,exporters:h})=>{const x=["run",Date.now(),a.label,Math.floor(Math.random()*1e5)].join("-"),y=await l(o.renderer.fields),r=[];for(const e of h)r.push(await e().start({title:a.name,fields:["runId",...y]}));const s=await l(w.values),c={};s.forEach(({name:e})=>{const t=c[e]||0;c[e]=t+1}),Object.entries(c).forEach(([e,t])=>{if(t>1)throw new Error(`[name="${e}"] was found [${t}] times in data. Each key should be unique.`)});let i=s.length;const g=async()=>{if(i--,i===0)for(const e of r)await e.flush()},{test:b,expect:m}=p?{test:n.test.concurrent,expect:new Proxy(n.expect,{get:(e,t)=>t==="soft"?e:e[t]})}:{test:n.test,expect:n.expect};for(const{name:e,input:t,expected:u,only:E}of s)b(e,{only:E},async({onTestFinished:j})=>{j(g);const f=await o.execute(t),d=await o.renderer.render({input:t,output:f,expected:u}),M=o.test(m,{input:t,output:f,expected:u,rendered:d});for(const P of r)await P.report({result:{runId:x,...d}});await M})};exports.genius=S;