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:
2026-04-30 10:36:54 -04:00
parent e131e0e8cd
commit aa7309b363
11 changed files with 698 additions and 2 deletions

12
test/fixtures/sample-broken.ts vendored Normal file
View File

@@ -0,0 +1,12 @@
// Broken Fixture — Intentional type errors for diagnostics testing.
/** This variable has a type mismatch — string assigned to number. */
export const brokenNumber: number = "not a number";
/** This function returns wrong type — string instead of boolean. */
export function brokenBoolean(): boolean {
return "yes";
}
/** This variable uses an undefined identifier. */
export const brokenReference = definitelyUndefined;

38
test/fixtures/sample.ts vendored Normal file
View File

@@ -0,0 +1,38 @@
// Sample Fixture — Minimal TypeScript file with known symbols for LSP testing.
// Used by integration tests to validate hover, definition, references, etc.
/**
* A sample class for testing LSP features.
* @example new SampleClass("hello")
*/
export class SampleClass {
public readonly name: string;
constructor(name: string) {
this.name = name;
}
/** Returns a greeting using the instance name. */
greet(): string {
return `Hello, ${this.name}!`;
}
}
/** A constant value for reference testing. */
export const SAMPLE_CONSTANT = 42;
/** Creates a new SampleClass with a default name. */
export function createSample(): SampleClass {
return new SampleClass("default");
}
// Internal helper — not exported, used to test definition lookups.
function internalHelper(value: number): string {
return String(value);
}
/** Uses the internal helper and constant for cross-reference testing. */
export function useInternal(): string {
const instance = createSample();
return internalHelper(SAMPLE_CONSTANT) + instance.greet();
}