When using typescript and vitest, the only thing you need to add is beforeAll
in your test file.
npm install baserun
yarn add baserun
import { baserun } from "baserun";
import { describe, beforeAll } from "vitest";
describe("My Test Suite", () => {
beforeAll(async () => {
await baserun.init();
});
});
npm run vitest test_module.spec.ts
Running multiple tests
It’s often helpful to exercise the same test over multiple examples. To do this, we suggest doing a simple for loop to autogenerate your tests and for larger numbers of examples you can read from a file or other data structure.
import { baserun } from "baserun";
const examples = [
{ place: "Paris", expected: "Eiffel Tower" },
{ place: "Rome", expected: "Colosseum" },
];
describe("Baserun end-to-end", () => {
beforeAll(async () => {
await baserun.init();
});
for (const { place, expected } of examples) {
it(`should suggest the ${expected}`, async () => {
await baserun.trace(async () => {
const chatCompletion = await openai.chat.completions.create({
model: "gpt-3.5-turbo",
temperature: 0.7,
messages: [
{
role: "user",
content: `What are three activities to do in ${place}?`,
},
],
});
expect(chatCompletion.choices[0].message!.content!).toContain(expected);
return chatCompletion;
})();
});
}
});
Baserun lets you compare test results and debug each step side by side. We consider the full path of the describe and it names of the jest test as a unique identifier for the test. In the example above, two tests would be run and identified by ("Baserun end-to-end", "should suggest the Eiffel Tower")
and ("Baserun end-to-end", "should suggest the Colosseum")