-
Notifications
You must be signed in to change notification settings - Fork 455
Expand file tree
/
Copy pathdead-code.test.ts
More file actions
64 lines (60 loc) · 2.23 KB
/
Copy pathdead-code.test.ts
File metadata and controls
64 lines (60 loc) · 2.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import * as Effect from "effect/Effect";
import * as Exit from "effect/Exit";
import * as Stream from "effect/Stream";
import { describe, expect, it } from "vite-plus/test";
import type { Diagnostic } from "@react-doctor/core";
import { DeadCode } from "../../src/services/dead-code.js";
const sampleDiagnostic: Diagnostic = {
filePath: "src/UnusedFile.tsx",
plugin: "deslop",
rule: "unused-file",
severity: "warning",
message: "Unused file",
help: "Delete or import it.",
line: 0,
column: 0,
category: "Maintainability",
};
describe("DeadCode.layerOf", () => {
it("emits the supplied diagnostics as a stream", async () => {
const collected = await Effect.runPromise(
Effect.gen(function* () {
const deadCode = yield* DeadCode;
return yield* Stream.runCollect(deadCode.run({ rootDirectory: "/repo", userConfig: null }));
}).pipe(Effect.provide(DeadCode.layerOf([sampleDiagnostic, sampleDiagnostic]))),
);
const items = Array.from(collected);
expect(items).toHaveLength(2);
expect(items[0].rule).toBe("unused-file");
});
it("emits an empty stream when constructed with []", async () => {
const collected = await Effect.runPromise(
Effect.gen(function* () {
const deadCode = yield* DeadCode;
return yield* Stream.runCollect(deadCode.run({ rootDirectory: "/repo", userConfig: null }));
}).pipe(Effect.provide(DeadCode.layerOf([]))),
);
expect(Array.from(collected)).toEqual([]);
});
});
describe("DeadCode.layerNode", () => {
it("returns an empty stream when the directory has no package.json", async () => {
const exit = await Effect.runPromiseExit(
Effect.gen(function* () {
const deadCode = yield* DeadCode;
return yield* Stream.runCollect(
deadCode.run({
rootDirectory: "/this/path/should/not/exist/dead-code-test-12345",
userConfig: null,
}),
);
}).pipe(Effect.provide(DeadCode.layerNode)),
);
// checkDeadCode short-circuits to [] when package.json doesn't exist,
// so the stream completes successfully with no diagnostics.
expect(Exit.isSuccess(exit)).toBe(true);
if (Exit.isSuccess(exit)) {
expect(Array.from(exit.value)).toEqual([]);
}
});
});