Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests: use assertIncludes instead of assertTrue where applicable #4381

Merged
merged 2 commits into from
Jan 31, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions packages/effect/test/Cache.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { describe, it } from "@effect/vitest"
import { Cache, Effect } from "effect"
import { Cache, Effect, TestClock } from "effect"
import { strictEqual } from "effect/test/util"
import * as TestClock from "effect/TestClock"

describe("Cache", () => {
it.effect("should not increment cache hits on expired entries", () =>
33 changes: 22 additions & 11 deletions packages/effect/test/Cause.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,20 @@
import { describe, it } from "@effect/vitest"
import { Array as Arr, Cause, Effect, Equal, FastCheck as fc, FiberId, Hash, Option, Predicate } from "effect"
import { NodeInspectSymbol } from "effect/Inspectable"
import {
Array as Arr,
Cause,
Effect,
Equal,
FastCheck as fc,
FiberId,
Hash,
Inspectable,
Option,
Predicate
} from "effect"
import * as internal from "effect/internal/cause"
import {
assertFalse,
assertIncludes,
assertLeft,
assertNone,
assertRight,
@@ -26,13 +37,13 @@ describe("Cause", () => {
it("correctly implements toString() and the NodeInspectSymbol", () => {
// Referenced line to be included in the string output
const ex = new Cause.InterruptedException("my message")
assertTrue(ex.toString().includes("InterruptedException: my message"))
assertIncludes(ex.toString(), "InterruptedException: my message")

// In Node.js environments, ensure the 'inspect' method includes line information
if (typeof window === "undefined") {
// eslint-disable-next-line @typescript-eslint/no-var-requires
const { inspect } = require("node:util")
assertTrue(inspect(ex).includes("Cause.test.ts:28")) // <= reference to the line above
assertIncludes(inspect(ex), "Cause.test.ts:39") // <= reference to the line above
}
})
})
@@ -98,7 +109,7 @@ describe("Cause", () => {
describe("toJSON / [NodeInspectSymbol]", () => {
const expectJSON = (cause: Cause.Cause<unknown>, expected: unknown) => {
deepStrictEqual(cause.toJSON(), expected)
deepStrictEqual(cause[NodeInspectSymbol](), expected)
deepStrictEqual(cause[Inspectable.NodeInspectSymbol](), expected)
}

it("Empty", () => {
@@ -213,12 +224,12 @@ describe("Cause", () => {

it("Fail", () => {
strictEqual(String(Cause.fail("my failure")), `Error: my failure`)
assertTrue(String(Cause.fail(new Error("my failure"))).includes(`Error: my failure`))
assertIncludes(String(Cause.fail(new Error("my failure"))), "Error: my failure")
})

it("Die", () => {
strictEqual(String(Cause.die("die message")), `Error: die message`)
assertTrue(String(Cause.die(new Error("die message"))).includes(`Error: die message`))
assertIncludes(String(Cause.die(new Error("die message"))), "Error: die message")
})

it("Interrupt", () => {
@@ -236,8 +247,8 @@ describe("Cause", () => {
`Error: failure 1\nError: failure 2`
)
const actual = String(Cause.sequential(Cause.fail(new Error("failure 1")), Cause.fail(new Error("failure 2"))))
assertTrue(actual.includes("Error: failure 1"))
assertTrue(actual.includes("Error: failure 2"))
assertIncludes(actual, "Error: failure 1")
assertIncludes(actual, "Error: failure 2")
})

it("Parallel", () => {
@@ -248,8 +259,8 @@ describe("Cause", () => {
const actual = String(
String(Cause.parallel(Cause.fail(new Error("failure 1")), Cause.fail(new Error("failure 2"))))
)
assertTrue(actual.includes("Error: failure 1"))
assertTrue(actual.includes("Error: failure 2"))
assertIncludes(actual, "Error: failure 1")
assertIncludes(actual, "Error: failure 2")
})
})

8 changes: 4 additions & 4 deletions packages/effect/test/Chunk.test.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { describe, it } from "@effect/vitest"
import {
Array as RA,
Array as Arr,
Chunk,
Either,
Equal,
FastCheck as fc,
identity,
Number as N,
Number as Num,
Option,
Order,
pipe,
@@ -181,7 +181,7 @@ describe("Chunk", () => {

it("gives back a readonly array", () => {
doesNotThrow(() => Chunk.toReadonlyArray(chunk))
deepStrictEqual(Chunk.toReadonlyArray(chunk), RA.reverse(RA.range(0, len - 1)))
deepStrictEqual(Chunk.toReadonlyArray(chunk), Arr.reverse(Arr.range(0, len - 1)))
})
})

@@ -855,7 +855,7 @@ describe("Chunk", () => {
})

it("getEquivalence", () => {
const equivalence = Chunk.getEquivalence(N.Equivalence)
const equivalence = Chunk.getEquivalence(Num.Equivalence)
assertTrue(equivalence(Chunk.empty(), Chunk.empty()))
assertTrue(equivalence(Chunk.make(1, 2, 3), Chunk.make(1, 2, 3)))
assertFalse(equivalence(Chunk.make(1, 2, 3), Chunk.make(1, 2)))
22 changes: 11 additions & 11 deletions packages/effect/test/Effect/cause-rendering.test.ts
Original file line number Diff line number Diff line change
@@ -37,8 +37,8 @@ describe("Effect", () => {
).pipe(Effect.catchTag("E2", (e) => Effect.die(e)))
const cause = yield* (Effect.flip(Effect.sandbox(effect)))
const rendered = Cause.pretty(cause)
assertTrue(rendered.includes("spanA"))
assertTrue(rendered.includes("spanB"))
assertIncludes(rendered, "spanA")
assertIncludes(rendered, "spanB")
const obj = Option.getOrThrow(Cause.failureOption(cause))
assertTrue(obj instanceof E1)
assertFalse(err === obj)
@@ -62,8 +62,8 @@ describe("Effect", () => {
).pipe(Effect.catchAll((e) => Effect.fail(e)))
const cause = yield* (Effect.flip(Effect.sandbox(effect)))
const rendered = Cause.pretty(cause)
assertTrue(rendered.includes("spanA"))
assertTrue(rendered.includes("spanB"))
assertIncludes(rendered, "spanA")
assertIncludes(rendered, "spanB")
}))
it.effect("catchTags should not invalidate traces", () =>
Effect.gen(function*() {
@@ -83,8 +83,8 @@ describe("Effect", () => {
).pipe(Effect.catchTags({ E2: (e) => Effect.die(e) }))
const cause = yield* (Effect.flip(Effect.sandbox(effect)))
const rendered = Cause.pretty(cause)
assertTrue(rendered.includes("spanA"))
assertTrue(rendered.includes("spanB"))
assertIncludes(rendered, "spanA")
assertIncludes(rendered, "spanB")
}))
it.effect("shows line where error was created", () =>
Effect.gen(function*() {
@@ -96,7 +96,7 @@ describe("Effect", () => {
Effect.flip
)
const pretty = Cause.pretty(cause)
assertTrue(pretty.includes("cause-rendering.test.ts"))
assertIncludes(pretty, "cause-rendering.test.ts")
}))

it.effect("functionWithSpan PrettyError stack", () =>
@@ -129,7 +129,7 @@ describe("Effect", () => {
Effect.flip
)
const prettyErrors = Cause.prettyErrors(cause)
assertTrue(prettyErrors[0].stack?.includes("at fn-0 "))
assertIncludes(prettyErrors[0].stack, "at fn-0 ")
}))

// ENABLE TO TEST EXPECT OUTPUT
@@ -159,7 +159,7 @@ message
Effect.flip
)
const pretty = Cause.pretty(cause, { renderErrorCause: true })
assertTrue(pretty.includes("[cause]: Error: child"))
assertIncludes(pretty, "[cause]: Error: child")
}))

it.effect("pretty nested cause", () =>
@@ -171,7 +171,7 @@ message
Effect.flip
)
const pretty = Cause.pretty(cause, { renderErrorCause: true })
assertTrue(pretty.includes("[cause]: Error: child"))
assertTrue(pretty.includes("[cause]: Error: child2"))
assertIncludes(pretty, "[cause]: Error: child")
assertIncludes(pretty, "[cause]: Error: child2")
}))
})
6 changes: 3 additions & 3 deletions packages/effect/test/Effect/error.test.ts
Original file line number Diff line number Diff line change
@@ -9,11 +9,11 @@ describe("Effect", () => {
Effect.gen(function*() {
const cause = yield* (Effect.flip(Effect.sandbox(Effect.withSpan("A")(new TestError()))))
const log = Cause.pretty(cause)
assertTrue(log.includes("TestError"))
assertIncludes(log, "TestError")
if (typeof window === "undefined") {
assertIncludes(log.replaceAll("\\", "/"), "test/Effect/error.test.ts:10:77")
}
assertTrue(log.includes("at A"))
assertIncludes(log, "at A")
}))

it.effect("tryPromise", () =>
@@ -86,7 +86,7 @@ describe("Effect", () => {
class MessageError extends Data.TaggedError("MessageError")<{
cause: unknown
}> {}
assertTrue(inspect(new MessageError({ cause: new Error("boom") })).includes("[cause]: Error: boom"))
assertIncludes(inspect(new MessageError({ cause: new Error("boom") })), "[cause]: Error: boom")
})
}

33 changes: 18 additions & 15 deletions packages/effect/test/Fiber.test.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
import { describe, it } from "@effect/vitest"
import * as Array from "effect/Array"
import * as Chunk from "effect/Chunk"
import * as Deferred from "effect/Deferred"
import * as Effect from "effect/Effect"
import * as Exit from "effect/Exit"
import * as Fiber from "effect/Fiber"
import * as FiberId from "effect/FiberId"
import * as FiberRef from "effect/FiberRef"
import * as FiberStatus from "effect/FiberStatus"
import { constVoid, pipe } from "effect/Function"
import * as HashSet from "effect/HashSet"
import * as Queue from "effect/Queue"
import * as Ref from "effect/Ref"
import {
Array,
Chunk,
Deferred,
Effect,
Exit,
Fiber,
FiberId,
FiberRef,
FiberStatus,
Function as Fun,
HashSet,
pipe,
Queue,
Ref
} from "effect"
import { assertTrue, deepStrictEqual, strictEqual } from "effect/test/util"
import { withLatch } from "effect/test/utils/latch"

@@ -29,7 +32,7 @@ describe("Fiber", () => {
Effect.flatMap((status) =>
FiberStatus.isSuspended(status)
? Effect.succeed(status.blockingOn)
: Effect.failSync(constVoid)
: Effect.failSync(Fun.constVoid)
),
Effect.eventually
)
@@ -53,7 +56,7 @@ describe("Fiber", () => {
const child = yield* withLatch((release) =>
FiberRef.set(fiberRef, update).pipe(Effect.zipRight(release), Effect.fork)
)
yield* pipe(child, Fiber.map(constVoid), Fiber.inheritAll)
yield* pipe(child, Fiber.map(Fun.constVoid), Fiber.inheritAll)
const result = yield* FiberRef.get(fiberRef)
strictEqual(result, update)
}))
34 changes: 19 additions & 15 deletions packages/effect/test/FiberRef.test.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
import { describe, it } from "@effect/vitest"
import * as Chunk from "effect/Chunk"
import * as Clock from "effect/Clock"
import * as Deferred from "effect/Deferred"
import * as Duration from "effect/Duration"
import * as Effect from "effect/Effect"
import * as Fiber from "effect/Fiber"
import * as FiberRef from "effect/FiberRef"
import { constant, constTrue, identity, pipe } from "effect/Function"
import * as Option from "effect/Option"
import * as Runtime from "effect/Runtime"
import { assertTrue, strictEqual } from "effect/test/util"
import {
Chunk,
Clock,
Deferred,
Duration,
Effect,
Fiber,
FiberRef,
Function as Fun,
identity,
Option,
pipe,
Runtime
} from "effect"
import { assertIncludes, assertTrue, strictEqual } from "effect/test/util"

const initial = "initial"
const update = "update"
@@ -228,13 +232,13 @@ describe("FiberRef", () => {
Effect.orElse(() => Effect.void)
)
const result = yield* FiberRef.get(fiberRef)
assertTrue(result.includes(initial))
assertIncludes(result, initial)
}))
it.scoped("the value of all fibers in inherited when running many effects with collectAllPar", () =>
Effect.gen(function*() {
const n = 1000
const fiberRef = yield* FiberRef.make(0, {
fork: constant(0),
fork: Fun.constant(0),
join: (a, b) => a + b
})
yield* Effect.all(Array.from({ length: n }, () => FiberRef.update(fiberRef, (n) => n + 1)), {
@@ -335,7 +339,7 @@ describe("FiberRef", () => {
}))
it.scoped("fork patch is applied when a fiber is unsafely run", () =>
Effect.gen(function*() {
const fiberRef = yield* FiberRef.make<boolean>(true, { fork: constTrue })
const fiberRef = yield* FiberRef.make<boolean>(true, { fork: Fun.constTrue })
const deferred = yield* Deferred.make<boolean>()
const runtime: Runtime.Runtime<never> = yield* Effect.runtime<never>().pipe(Effect.locally(fiberRef, false))
yield* Effect.sync(() => FiberRef.get(fiberRef).pipe(Effect.intoDeferred(deferred), Runtime.runCallback(runtime)))
@@ -344,7 +348,7 @@ describe("FiberRef", () => {
}))
it.scoped("fork patch is applied when a fiber is unsafely forked", () =>
Effect.gen(function*() {
const fiberRef = yield* FiberRef.make<boolean>(true, { fork: constTrue })
const fiberRef = yield* FiberRef.make<boolean>(true, { fork: Fun.constTrue })
const deferred = yield* Deferred.make<boolean>()
const runtime: Runtime.Runtime<never> = yield* Effect.locally(Effect.runtime<never>(), fiberRef, false)
const fiber = yield* Effect.sync(() =>
13 changes: 1 addition & 12 deletions packages/effect/test/FiberRefs.test.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,5 @@
import { describe, it } from "@effect/vitest"
import * as Cause from "effect/Cause"
import * as Effect from "effect/Effect"
import * as Exit from "effect/Exit"
import * as Fiber from "effect/Fiber"
import * as FiberId from "effect/FiberId"
import * as FiberRef from "effect/FiberRef"
import * as FiberRefs from "effect/FiberRefs"
import { pipe } from "effect/Function"
import * as HashMap from "effect/HashMap"
import * as Option from "effect/Option"
import * as Queue from "effect/Queue"
import * as Scope from "effect/Scope"
import { Cause, Effect, Exit, Fiber, FiberId, FiberRef, FiberRefs, HashMap, Option, pipe, Queue, Scope } from "effect"
import { assertTrue, deepStrictEqual, strictEqual } from "effect/test/util"

describe("FiberRefs", () => {
2 changes: 1 addition & 1 deletion packages/effect/test/GlobalValue.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { describe, it } from "@effect/vitest"
import * as G from "effect/GlobalValue"
import { GlobalValue as G } from "effect"
import { strictEqual } from "effect/test/util"

const a = G.globalValue("id", () => ({}))
7 changes: 1 addition & 6 deletions packages/effect/test/Hash.test.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
import { describe, it } from "@effect/vitest"
import * as Equal from "effect/Equal"
import { absurd, identity } from "effect/Function"
import * as Hash from "effect/Hash"
import * as HashSet from "effect/HashSet"
import * as Option from "effect/Option"
import { absurd, Equal, Hash, HashSet, identity, Option, Utils } from "effect"
import { assertFalse, assertTrue, strictEqual } from "effect/test/util"
import * as Utils from "effect/Utils"

describe("Hash", () => {
it("structural", () => {
6 changes: 1 addition & 5 deletions packages/effect/test/HashMap.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
import { describe, it } from "@effect/vitest"
import * as Equal from "effect/Equal"
import { pipe } from "effect/Function"
import * as Hash from "effect/Hash"
import * as HM from "effect/HashMap"
import * as Option from "effect/Option"
import { Equal, Hash, HashMap as HM, Option, pipe } from "effect"
import { assertFalse, assertNone, assertSome, assertTrue, deepStrictEqual, strictEqual, throws } from "effect/test/util"

class Key implements Equal.Equal {
5 changes: 1 addition & 4 deletions packages/effect/test/HashSet.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
import { describe, it } from "@effect/vitest"
import * as Equal from "effect/Equal"
import { pipe } from "effect/Function"
import * as Hash from "effect/Hash"
import * as HashSet from "effect/HashSet"
import { Equal, Hash, HashSet, pipe } from "effect"
import { assertFalse, assertTrue, deepStrictEqual, strictEqual } from "effect/test/util"

class Value implements Equal.Equal {
Loading