Skip to content

Instantly share code, notes, and snippets.

@benbenbenbenbenben
Created March 8, 2024 15:42
Show Gist options
  • Save benbenbenbenbenben/af3ea0ada5eb2d24b432544f7c5a16da to your computer and use it in GitHub Desktop.
Save benbenbenbenbenben/af3ea0ada5eb2d24b432544f7c5a16da to your computer and use it in GitHub Desktop.
// exploring vitest behaviour with --pool=forks vs --pool=threads
// spoiler alert: same module, same behaviour - server is only created *once*
import { describe, expect, it } from "vitest";
const server = {
a: 0
}
describe("some module", () => {
it.each([
{ foo: 1, bar: 2, sum: 3 },
{ foo: 3, bar: 4, sum: 7 },
])(
"testing with foo=$foo and bar=$bar, sum=$sum",
async ({ foo, bar, sum }) => {
server.a += foo + bar
expect(server.a).toBe(sum)
})
})
describe("another module", () => {
it.each([
{ foo: 1, bar: 2, sum: 3 },
{ foo: 3, bar: 4, sum: 7 },
])(
"testing with foo=$foo and bar=$bar, sum=$sum",
async ({ foo, bar, sum }) => {
server.a += foo + bar
expect(server.a).toBe(sum)
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment