test(lsp): use named tmpdir import to avoid node:os mock leak
Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
import { afterEach, beforeEach, describe, expect, it, mock, spyOn } from "bun:test"
|
import { afterEach, beforeEach, describe, expect, it, mock, spyOn } from "bun:test"
|
||||||
import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from "fs"
|
import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from "fs"
|
||||||
|
import { tmpdir } from "os"
|
||||||
import { join } from "path"
|
import { join } from "path"
|
||||||
import os from "os"
|
|
||||||
|
|
||||||
import * as configModule from "./config"
|
import * as configModule from "./config"
|
||||||
import { lspManager } from "./lsp-server"
|
import { lspManager } from "./lsp-server"
|
||||||
@@ -40,7 +40,7 @@ describe("directory diagnostics", () => {
|
|||||||
priority: 1,
|
priority: 1,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
spyOn(lspManager, "getClient").mockImplementation(getClientMock)
|
spyOn(lspManager, "getClient").mockImplementation(getClientMock as never)
|
||||||
spyOn(lspManager, "releaseClient").mockImplementation(releaseClientMock)
|
spyOn(lspManager, "releaseClient").mockImplementation(releaseClientMock)
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -50,7 +50,7 @@ describe("directory diagnostics", () => {
|
|||||||
|
|
||||||
describe("isDirectoryPath", () => {
|
describe("isDirectoryPath", () => {
|
||||||
it("returns true for existing directory", () => {
|
it("returns true for existing directory", () => {
|
||||||
const tmp = mkdtempSync(join(os.tmpdir(), "omo-isdir-"))
|
const tmp = mkdtempSync(join(tmpdir(), "omo-isdir-"))
|
||||||
try {
|
try {
|
||||||
expect(isDirectoryPath(tmp)).toBe(true)
|
expect(isDirectoryPath(tmp)).toBe(true)
|
||||||
} finally {
|
} finally {
|
||||||
@@ -59,7 +59,7 @@ describe("directory diagnostics", () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it("returns false for existing file", () => {
|
it("returns false for existing file", () => {
|
||||||
const tmp = mkdtempSync(join(os.tmpdir(), "omo-isdir-file-"))
|
const tmp = mkdtempSync(join(tmpdir(), "omo-isdir-file-"))
|
||||||
try {
|
try {
|
||||||
const file = join(tmp, "test.txt")
|
const file = join(tmp, "test.txt")
|
||||||
writeFileSync(file, "content")
|
writeFileSync(file, "content")
|
||||||
@@ -70,14 +70,14 @@ describe("directory diagnostics", () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it("returns false for non-existent path", () => {
|
it("returns false for non-existent path", () => {
|
||||||
const nonExistent = join(os.tmpdir(), "omo-nonexistent-" + Date.now())
|
const nonExistent = join(tmpdir(), "omo-nonexistent-" + Date.now())
|
||||||
expect(isDirectoryPath(nonExistent)).toBe(false)
|
expect(isDirectoryPath(nonExistent)).toBe(false)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe("aggregateDiagnosticsForDirectory", () => {
|
describe("aggregateDiagnosticsForDirectory", () => {
|
||||||
it("throws error when extension does not start with dot", async () => {
|
it("throws error when extension does not start with dot", async () => {
|
||||||
const tmp = mkdtempSync(join(os.tmpdir(), "omo-aggr-ext-"))
|
const tmp = mkdtempSync(join(tmpdir(), "omo-aggr-ext-"))
|
||||||
try {
|
try {
|
||||||
await expect(aggregateDiagnosticsForDirectory(tmp, "ts")).rejects.toThrow(
|
await expect(aggregateDiagnosticsForDirectory(tmp, "ts")).rejects.toThrow(
|
||||||
'Extension must start with a dot (e.g., ".ts", not "ts")'
|
'Extension must start with a dot (e.g., ".ts", not "ts")'
|
||||||
@@ -88,14 +88,14 @@ describe("directory diagnostics", () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it("throws error when directory does not exist", async () => {
|
it("throws error when directory does not exist", async () => {
|
||||||
const nonExistent = join(os.tmpdir(), "omo-nonexistent-dir-" + Date.now())
|
const nonExistent = join(tmpdir(), "omo-nonexistent-dir-" + Date.now())
|
||||||
await expect(aggregateDiagnosticsForDirectory(nonExistent, ".ts")).rejects.toThrow(
|
await expect(aggregateDiagnosticsForDirectory(nonExistent, ".ts")).rejects.toThrow(
|
||||||
"Directory does not exist"
|
"Directory does not exist"
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
it("#given diagnostics from multiple files #when aggregating directory diagnostics #then each entry includes the source file path", async () => {
|
it("#given diagnostics from multiple files #when aggregating directory diagnostics #then each entry includes the source file path", async () => {
|
||||||
const tmp = mkdtempSync(join(os.tmpdir(), "omo-aggr-files-"))
|
const tmp = mkdtempSync(join(tmpdir(), "omo-aggr-files-"))
|
||||||
try {
|
try {
|
||||||
const firstFile = join(tmp, "first.ts")
|
const firstFile = join(tmp, "first.ts")
|
||||||
const secondFile = join(tmp, "second.ts")
|
const secondFile = join(tmp, "second.ts")
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { afterEach, beforeEach, describe, expect, it } from "bun:test"
|
import { afterEach, beforeEach, describe, expect, it } from "bun:test"
|
||||||
import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from "fs"
|
import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from "fs"
|
||||||
|
import { tmpdir } from "os"
|
||||||
import { join } from "path"
|
import { join } from "path"
|
||||||
import os from "os"
|
|
||||||
|
|
||||||
import { inferExtensionFromDirectory } from "./infer-extension"
|
import { inferExtensionFromDirectory } from "./infer-extension"
|
||||||
|
|
||||||
@@ -9,7 +9,7 @@ describe("inferExtensionFromDirectory", () => {
|
|||||||
let tmpDir: string
|
let tmpDir: string
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
tmpDir = mkdtempSync(join(os.tmpdir(), "omo-infer-ext-"))
|
tmpDir = mkdtempSync(join(tmpdir(), "omo-infer-ext-"))
|
||||||
})
|
})
|
||||||
|
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
|
|||||||
@@ -1,14 +1,14 @@
|
|||||||
import { describe, expect, it } from "bun:test"
|
import { describe, expect, it } from "bun:test"
|
||||||
import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from "fs"
|
import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from "fs"
|
||||||
|
import { tmpdir } from "os"
|
||||||
import { join } from "path"
|
import { join } from "path"
|
||||||
import os from "os"
|
|
||||||
|
|
||||||
import { findWorkspaceRoot } from "./lsp-client-wrapper"
|
import { findWorkspaceRoot } from "./lsp-client-wrapper"
|
||||||
|
|
||||||
describe("lsp utils", () => {
|
describe("lsp utils", () => {
|
||||||
describe("findWorkspaceRoot", () => {
|
describe("findWorkspaceRoot", () => {
|
||||||
it("returns an existing directory even when the file path points to a non-existent nested path", () => {
|
it("returns an existing directory even when the file path points to a non-existent nested path", () => {
|
||||||
const tmp = mkdtempSync(join(os.tmpdir(), "omo-lsp-root-"))
|
const tmp = mkdtempSync(join(tmpdir(), "omo-lsp-root-"))
|
||||||
try {
|
try {
|
||||||
// Add a marker so the function can discover the workspace root.
|
// Add a marker so the function can discover the workspace root.
|
||||||
writeFileSync(join(tmp, "package.json"), "{}")
|
writeFileSync(join(tmp, "package.json"), "{}")
|
||||||
@@ -23,7 +23,7 @@ describe("lsp utils", () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it("prefers the nearest marker directory when markers exist above the file", () => {
|
it("prefers the nearest marker directory when markers exist above the file", () => {
|
||||||
const tmp = mkdtempSync(join(os.tmpdir(), "omo-lsp-marker-"))
|
const tmp = mkdtempSync(join(tmpdir(), "omo-lsp-marker-"))
|
||||||
try {
|
try {
|
||||||
const repo = join(tmp, "repo")
|
const repo = join(tmp, "repo")
|
||||||
const src = join(repo, "src")
|
const src = join(repo, "src")
|
||||||
|
|||||||
Reference in New Issue
Block a user