| 1 | import { loadAnnotations } from "@effect/api-diff/Annotations" |
| 2 | import * as NodeServices from "@effect/platform-node/NodeServices" |
| 3 | import { assert, describe, it } from "@effect/vitest" |
| 4 | import * as Effect from "effect/Effect" |
| 5 | import * as FileSystem from "effect/FileSystem" |
| 6 | import * as Path from "effect/Path" |
| 7 | |
| 8 | describe("migration annotations", () => { |
| 9 | it.effect("loads and merges YAML files", () => |
| 10 | Effect.gen(function*() { |
| 11 | const fs = yield* FileSystem.FileSystem |
| 12 | const path = yield* Path.Path |
| 13 | const root = yield* fs.makeTempDirectoryScoped({ prefix: "api-diff-annotations-" }) |
| 14 | yield* fs.writeFileString( |
| 15 | path.join(root, "Effect.yaml"), |
| 16 | [ |
| 17 | "effect/Effect#async:", |
| 18 | " replacement: Effect.callback", |
| 19 | " note: Rename the callback constructor.", |
| 20 | " example: Effect.callback((resume) => resume(Effect.void))", |
| 21 | "" |
| 22 | ].join("\n") |
| 23 | ) |
| 24 | yield* fs.writeFileString( |
| 25 | path.join(root, "Stream.yaml"), |
| 26 | [ |
| 27 | "effect/Stream#async:", |
| 28 | " replacement: Stream.callback", |
| 29 | " note: Rename the stream constructor.", |
| 30 | "" |
| 31 | ].join("\n") |
| 32 | ) |
| 33 | |
| 34 | const annotations = yield* loadAnnotations(root) |
| 35 | |
| 36 | assert.deepStrictEqual([...annotations], [ |
| 37 | ["effect/Effect#async", { |
| 38 | replacement: "Effect.callback", |
| 39 | note: "Rename the callback constructor.", |
| 40 | example: "Effect.callback((resume) => resume(Effect.void))" |
| 41 | }], |
| 42 | ["effect/Stream#async", { |
| 43 | replacement: "Stream.callback", |
| 44 | note: "Rename the stream constructor." |
| 45 | }] |
| 46 | ]) |
| 47 | }).pipe(Effect.provide(NodeServices.layer))) |
| 48 | |
| 49 | it.effect("treats a missing directory as no annotations", () => |
| 50 | Effect.gen(function*() { |
| 51 | const fs = yield* FileSystem.FileSystem |
| 52 | const path = yield* Path.Path |
| 53 | const root = yield* fs.makeTempDirectoryScoped({ prefix: "api-diff-annotations-" }) |
| 54 | |
| 55 | const annotations = yield* loadAnnotations(path.join(root, "missing")) |
| 56 | |
| 57 | assert.strictEqual(annotations.size, 0) |
| 58 | }).pipe(Effect.provide(NodeServices.layer))) |
| 59 | }) |