Skip to content

Commit

Permalink
add vitest runIf (#3376)
Browse files Browse the repository at this point in the history
  • Loading branch information
yasuaki640 authored Jul 29, 2024
1 parent f566fd1 commit 9f197e8
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/bright-items-lick.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@effect/vitest": patch
---

Add `it.{method}.runIf`.
1 change: 1 addition & 0 deletions packages/vitest/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export namespace Vitest {
export interface Tester<R> extends Vitest.Test<R> {
skip: Vitest.Test<R>
skipIf: (condition: unknown) => Vitest.Test<R>
runIf: (condition: unknown) => Vitest.Test<R>
only: Vitest.Test<R>
each: <T>(
cases: ReadonlyArray<T>
Expand Down
4 changes: 3 additions & 1 deletion packages/vitest/src/internal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,13 @@ const makeTester = <R>(
const skip: Vitest.Vitest.Tester<R>["only"] = (name, self, timeout) => V.it.skip(name, run(self), timeout)
const skipIf: Vitest.Vitest.Tester<R>["skipIf"] = (condition) => (name, self, timeout) =>
V.it.skipIf(condition)(name, run(self), timeout)
const runIf: Vitest.Vitest.Tester<R>["runIf"] = (condition) => (name, self, timeout) =>
V.it.runIf(condition)(name, run(self), timeout)
const only: Vitest.Vitest.Tester<R>["only"] = (name, self, timeout) => V.it.only(name, run(self), timeout)
const each: Vitest.Vitest.Tester<R>["each"] = (cases) => (name, self, timeout) =>
V.it.each(cases)(name, run(self), timeout)

return Object.assign(f, { skip, skipIf, only, each })
return Object.assign(f, { skip, skipIf, runIf, only, each })
}

/** @internal */
Expand Down
5 changes: 5 additions & 0 deletions packages/vitest/test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,8 @@ it.scopedLive.skip(

it.effect.skipIf(true)("effect skipIf (true)", () => Effect.die("skipped anyway"))
it.effect.skipIf(false)("effect skipIf (false)", () => Effect.sync(() => expect(1).toEqual(1)))

// runIf

it.effect.runIf(true)("effect runIf (true)", () => Effect.sync(() => expect(1).toEqual(1)))
it.effect.runIf(false)("effect runIf (false)", () => Effect.die("not run anyway"))

0 comments on commit 9f197e8

Please sign in to comment.