72 lines
2.0 KiB
TypeScript
72 lines
2.0 KiB
TypeScript
/**
|
|
* Code review tools tests
|
|
*/
|
|
|
|
import { describe, test, expect, beforeEach } from "bun:test";
|
|
import { registerCodeReviewTools } from "../../../../src/tools/programming/codeReview.js";
|
|
import { callTool } from "../../../helpers/tool-helper.js";
|
|
|
|
describe("Code Review Tools", () => {
|
|
beforeEach(() => {
|
|
registerCodeReviewTools();
|
|
});
|
|
|
|
test("should review code and find issues", async () => {
|
|
const result = await callTool("code_review", {
|
|
code: "let x: any = 1;",
|
|
language: "typescript",
|
|
});
|
|
|
|
expect(result.content[0].text).toContain("Code Review");
|
|
expect(result.content[0].text).toContain("any");
|
|
});
|
|
|
|
test("should suggest improvements", async () => {
|
|
const result = await callTool("code_review", {
|
|
code: "console.log('test');",
|
|
language: "javascript",
|
|
});
|
|
|
|
expect(result.content[0].text).toContain("Suggestions");
|
|
expect(result.content[0].text).toContain("console.log");
|
|
});
|
|
|
|
test("should detect var usage", async () => {
|
|
const result = await callTool("code_review", {
|
|
code: "var x = 1;",
|
|
language: "javascript",
|
|
});
|
|
|
|
expect(result.content[0].text).toContain("var");
|
|
});
|
|
|
|
test("should provide optimization suggestions", async () => {
|
|
const result = await callTool("code_optimize", {
|
|
code: "if (x == 1) { }",
|
|
language: "javascript",
|
|
});
|
|
|
|
expect(result.content[0].text).toContain("Optimization");
|
|
expect(result.content[0].text).toContain("===");
|
|
});
|
|
|
|
test("should suggest Vue optimizations", async () => {
|
|
const result = await callTool("code_optimize", {
|
|
code: "<div v-for='item in items'>",
|
|
language: "vue",
|
|
});
|
|
|
|
expect(result.content[0].text).toContain("Optimization");
|
|
expect(result.content[0].text).toContain(":key");
|
|
});
|
|
|
|
test("should handle code with no issues", async () => {
|
|
const result = await callTool("code_review", {
|
|
code: "const x: number = 1;",
|
|
language: "typescript",
|
|
});
|
|
|
|
expect(result.content[0].text).toContain("Code Review");
|
|
});
|
|
});
|