test: add unit and integration test suite
Add 34 tests (27 unit, 7 integration) using node:test runner: Unit tests: - pickServer(), findRoot(), pathToUri(), uriToPath() - isLspCommand(), listCommands() - formatHover(), formatDefinition(), formatReferences(), formatDiagnostics() Integration tests: - daemon lifecycle (status/stop) on isolated socket - CLI --no-daemon queries (hover, documentSymbol, diagnostics) Supporting changes: - socketPath() honors PI_LSP_SOCKET_PATH env var for test isolation - test fixtures for valid and broken TypeScript files - npm test / test:unit / test:integration scripts
This commit is contained in:
34
test/unit/commands.test.ts
Normal file
34
test/unit/commands.test.ts
Normal file
@@ -0,0 +1,34 @@
|
||||
// Commands Unit Tests — isLspCommand(), listCommands().
|
||||
import { describe, it } from "node:test";
|
||||
import * as assert from "node:assert/strict";
|
||||
import { isLspCommand, listCommands } from "../../src/commands.ts";
|
||||
|
||||
describe("listCommands", () => {
|
||||
it("returns all known commands", () => {
|
||||
const cmds = listCommands();
|
||||
assert.ok(Array.isArray(cmds));
|
||||
assert.ok(cmds.includes("hover"));
|
||||
assert.ok(cmds.includes("definition"));
|
||||
assert.ok(cmds.includes("references"));
|
||||
assert.ok(cmds.includes("completion"));
|
||||
assert.ok(cmds.includes("documentSymbol"));
|
||||
assert.ok(cmds.includes("diagnostics"));
|
||||
});
|
||||
});
|
||||
|
||||
describe("isLspCommand", () => {
|
||||
it("returns true for known commands", () => {
|
||||
assert.strictEqual(isLspCommand("hover"), true);
|
||||
assert.strictEqual(isLspCommand("definition"), true);
|
||||
assert.strictEqual(isLspCommand("references"), true);
|
||||
assert.strictEqual(isLspCommand("completion"), true);
|
||||
assert.strictEqual(isLspCommand("documentSymbol"), true);
|
||||
assert.strictEqual(isLspCommand("diagnostics"), true);
|
||||
});
|
||||
|
||||
it("returns false for unknown strings", () => {
|
||||
assert.strictEqual(isLspCommand("format"), false);
|
||||
assert.strictEqual(isLspCommand(""), false);
|
||||
assert.strictEqual(isLspCommand("hover "), false);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user