Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

GitService.test.ts

59 lines2.0 KB

1import * as NodeServices from "@effect/platform-node/NodeServices";
2import { it, assert } from "@effect/vitest";
3import { Effect, Layer, Schema } from "effect";
4​
5import { GitCommandError } from "../Errors.ts";
6import { GitServiceLive } from "./GitService.ts";
7import { GitService } from "../Services/GitService.ts";
8​
9const layer = it.layer(Layer.provideMerge(GitServiceLive, NodeServices.layer));
10​
11layer("GitServiceLive", (it) => {
12 it.effect("runGit executes successful git commands", () =>
13 Effect.gen(function* () {
14 const gitService = yield* GitService;
15 const result = yield* gitService.execute({
16 operation: "GitProcess.test.version",
17 cwd: process.cwd(),
18 args: ["--version"],
19 });
20​
21 assert.equal(result.code, 0);
22 assert.ok(result.stdout.toLowerCase().includes("git version"));
23 }),
24 );
25​
26 it.effect("runGit can return non-zero exit codes when allowed", () =>
27 Effect.gen(function* () {
28 const gitService = yield* GitService;
29 const result = yield* gitService.execute({
30 operation: "GitProcess.test.allowNonZero",
31 cwd: process.cwd(),
32 args: ["rev-parse", "--verify", "__definitely_missing_ref__"],
33 allowNonZeroExit: true,
34 });
35​
36 assert.notEqual(result.code, 0);
37 }),
38 );
39​
40 it.effect("runGit fails with GitCommandError when non-zero exits are not allowed", () =>
41 Effect.gen(function* () {
42 const gitService = yield* GitService;
43 const result = yield* Effect.result(
44 gitService.execute({
45 operation: "GitProcess.test.failOnNonZero",
46 cwd: process.cwd(),
47 args: ["rev-parse", "--verify", "__definitely_missing_ref__"],
48 }),
49 );
50​
51 assert.equal(result._tag, "Failure");
52 if (result._tag === "Failure") {
53 assert.ok(Schema.is(GitCommandError)(result.failure));
54 assert.equal(result.failure.operation, "GitProcess.test.failOnNonZero");
55 assert.equal(result.failure.command, "git rev-parse --verify __definitely_missing_ref__");
56 }
57 }),
58 );
59});