I notice that vitest allows you to extend your test function with skipIf, only, each, etc:
import { assert, test } from 'vitest'
const isDev = process.env.NODE_ENV === 'development'
test.skipIf(isDev)('prod only test', () => {
// this test only runs in production
})
doing bindings for this i would expect test to be an opaque type, but then I’m looking for a way to make that object callable…I suppose i can use %raw but how would you do it?
type test
@module("vitest") external t: test = "test"
@send external skipIf: (test, bool) => test = "skipIf"
....
let call: (test, string, () => unit) => unit = %raw(`(a, b, c) => a(b, c)`)
I would still say that you can enforce an order, you can say that you should always use skipIf first and not after the functions that change the signature, like each. You’d have to define different each functions depending on the number of elements it has anyway.
type test = (string, unit => unit) => unit
@module("vitest") external test: test = "test"
@send external skipIf: (test, bool) => test = "skipIf"
@send
external each3: (
test,
array<('a, 'b, 'c)>,
) => (string, ('a, 'b, 'c) => unit) => unit = "each"
type expect<'a>
@module("vitest") external expect: 'a => expect<'a> = "expect"
@send external toBe: (expect<'a>, 'a) => unit = "toBe"
test("1+1 = 2", () => expect(1 + 1)->toBe(2))
skipIf(test, isDev)("1+1 = 2", () => expect(1 + 1)->toBe(2))
each3(test, [(1, 2, 3), (3, 4, 7)])("add(%i, %i) -> %i", (a, b, c) =>
expect(a + b)->toBe(c)
)
The only issue I could find comes from the fact there seems to be a bug with the fast pipe and uncurried mode, so you wouldn’t be able to pipe test to each3 or skipIf, which is definitely unfortunate, but hopefully can be fixed.