| 1 | import { ApiDiffError, isApiDiffError } from "@effect/api-diff/Error" |
| 2 | import { isSnapshotExtractionError, SnapshotExtractionError } from "@effect/api-diff/Snapshot" |
| 3 | import { assert, describe, it } from "@effect/vitest" |
| 4 | import { vi } from "vitest" |
| 5 | import type * as ApiDiffErrorModule from "../src/Error.ts" |
| 6 | import type * as SnapshotModule from "../src/Snapshot.ts" |
| 7 | |
| 8 | describe("tagged errors", () => { |
| 9 | it("recognizes errors from a reloaded module copy", async () => { |
| 10 | vi.resetModules() |
| 11 | const ForeignApiDiffError = await vi.importActual<typeof ApiDiffErrorModule>("../src/Error.ts") |
| 12 | const ForeignSnapshot = await vi.importActual<typeof SnapshotModule>("../src/Snapshot.ts") |
| 13 | |
| 14 | const apiDiffError = new ForeignApiDiffError.ApiDiffError({ message: "boom" }) |
| 15 | assert.isFalse(apiDiffError instanceof ApiDiffError) |
| 16 | assert.isTrue(isApiDiffError(apiDiffError)) |
| 17 | |
| 18 | const snapshotError = new ForeignSnapshot.SnapshotExtractionError({ |
| 19 | message: "boom", |
| 20 | diagnostics: [] |
| 21 | }) |
| 22 | assert.isFalse(snapshotError instanceof SnapshotExtractionError) |
| 23 | assert.isTrue(isSnapshotExtractionError(snapshotError)) |
| 24 | }) |
| 25 | }) |