(layer: Layer.Layer<Fs.FileSystem, E>, options: TestLayerOptions = {})
| 24 | Effect.runPromise(Effect.provide(self, layer)) |
| 25 | |
| 26 | export const testLayer = <E>(layer: Layer.Layer<Fs.FileSystem, E>, options: TestLayerOptions = {}) => { |
| 27 | const runPromise = runWith(layer) |
| 28 | |
| 29 | it("readFile", () => |
| 30 | runPromise(Effect.gen(function*() { |
| 31 | const fs = yield* Fs.FileSystem |
| 32 | const data = yield* fs.readFile(`${__dirname}/fixtures/text.txt`) |
| 33 | const text = new TextDecoder().decode(data) |
| 34 | expect(text.trim()).toEqual("lorem ipsum dolar sit amet") |
| 35 | }))) |
| 36 | |
| 37 | it("makeTempDirectory", () => |
| 38 | runPromise(Effect.gen(function*() { |
| 39 | const fs = yield* Fs.FileSystem |
| 40 | let dir = "" |
| 41 | yield* Effect.scoped(Effect.gen(function*() { |
| 42 | dir = yield* fs.makeTempDirectory() |
| 43 | const stat = yield* fs.stat(dir) |
| 44 | expect(stat.type).toEqual("Directory") |
| 45 | })) |
| 46 | const stat = yield* fs.stat(dir) |
| 47 | expect(stat.type).toEqual("Directory") |
| 48 | }))) |
| 49 | |
| 50 | it("makeTempDirectoryScoped", () => |
| 51 | runPromise(Effect.gen(function*() { |
| 52 | const fs = yield* Fs.FileSystem |
| 53 | let dir = "" |
| 54 | yield* Effect.scoped( |
| 55 | Effect.gen(function*() { |
| 56 | dir = yield* fs.makeTempDirectoryScoped() |
| 57 | const stat = yield* fs.stat(dir) |
| 58 | expect(stat.type).toEqual("Directory") |
| 59 | }) |
| 60 | ) |
| 61 | const error = yield* Effect.flip(fs.stat(dir)) |
| 62 | assert(error.reason._tag === "NotFound") |
| 63 | }))) |
| 64 | |
| 65 | it("makeTempDirectoryScoped tolerates an already removed directory", () => |
| 66 | runPromise(Effect.gen(function*() { |
| 67 | const fs = yield* Fs.FileSystem |
| 68 | const result = yield* Effect.scoped(Effect.gen(function*() { |
| 69 | const dir = yield* fs.makeTempDirectoryScoped() |
| 70 | yield* fs.remove(dir, { recursive: true }) |
| 71 | return "body succeeded" |
| 72 | })) |
| 73 | expect(result).toEqual("body succeeded") |
| 74 | }))) |
| 75 | |
| 76 | it("lstat does not follow symbolic links", () => |
| 77 | runPromise(Effect.scoped(Effect.gen(function*() { |
| 78 | const fs = yield* Fs.FileSystem |
| 79 | const directory = yield* fs.makeTempDirectoryScoped() |
| 80 | const link = `${directory}/link` |
| 81 | yield* fs.writeFileString(`${directory}/target`, "") |
| 82 | yield* fs.symlink(`${directory}/target`, link) |
| 83 | expect((yield* fs.stat(link)).type).toEqual("File") |
no test coverage detected