-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdetectors.test.ts
More file actions
79 lines (66 loc) · 2.86 KB
/
Copy pathdetectors.test.ts
File metadata and controls
79 lines (66 loc) · 2.86 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import { describe, it, expect, beforeEach, afterEach } from "vitest";
import * as fs from "fs";
import * as path from "path";
import * as os from "os";
import { NodeDetector, PythonDetector, ArchitecturalScout } from "../src/detectors/project-scout.js";
describe("Detectors", () => {
let tmpDir: string;
beforeEach(() => {
tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), "refiner-test-"));
});
afterEach(() => {
fs.rmSync(tmpDir, { recursive: true, force: true });
});
describe("NodeDetector", () => {
it("should detect a TypeScript project with Prisma and Tailwind", async () => {
fs.writeFileSync(path.join(tmpDir, "package.json"), JSON.stringify({
dependencies: { react: "18.0.0", prisma: "5.0.0", tailwindcss: "3.0.0" },
devDependencies: { vitest: "1.0.0", typescript: "5.0.0" }
}));
fs.writeFileSync(path.join(tmpDir, "tsconfig.json"), "{}");
const ctx = await NodeDetector.detect(tmpDir);
expect(ctx.orm).toBe("Prisma");
expect(ctx.styling).toBe("Tailwind CSS");
});
it("should detect an Express project with Jest", async () => {
fs.writeFileSync(path.join(tmpDir, "package.json"), JSON.stringify({
dependencies: { express: "4.18.0" },
devDependencies: { jest: "29.0.0" }
}));
const ctx = await NodeDetector.detect(tmpDir);
expect(ctx.language).toBe("JavaScript");
expect(ctx.framework).toBe("Express");
expect(ctx.testing).toBe("Jest");
});
});
describe("PythonDetector", () => {
it("should detect a FastAPI project with Pytest", async () => {
fs.writeFileSync(path.join(tmpDir, "requirements.txt"), "fastapi\npytest");
const ctx = await PythonDetector.detect(tmpDir);
expect(ctx.language).toBe("Python");
expect(ctx.framework).toBe("FastAPI");
expect(ctx.testing).toBe("Pytest");
});
it("should detect Django from pyproject.toml", async () => {
fs.writeFileSync(path.join(tmpDir, "pyproject.toml"), '[tool.poetry.dependencies]\ndjango = "^4.0"');
const ctx = await PythonDetector.detect(tmpDir);
expect(ctx.framework).toBe("Django");
});
});
describe("ArchitecturalScout", () => {
it("should detect Clean Architecture / DDD", async () => {
fs.mkdirSync(path.join(tmpDir, "domain"));
fs.mkdirSync(path.join(tmpDir, "application"));
fs.mkdirSync(path.join(tmpDir, "infrastructure"));
const patterns = await ArchitecturalScout.detectPatterns(tmpDir);
expect(patterns).toContain("Clean Architecture / DDD");
});
it("should detect MVC", async () => {
fs.mkdirSync(path.join(tmpDir, "models"));
fs.mkdirSync(path.join(tmpDir, "views"));
fs.mkdirSync(path.join(tmpDir, "controllers"));
const patterns = await ArchitecturalScout.detectPatterns(tmpDir);
expect(patterns).toContain("MVC (Model-View-Controller)");
});
});
});