|
1 | 1 | import { describe, expect, spyOn, test } from "bun:test" |
2 | 2 | import path from "path" |
| 3 | +import fs from "fs/promises" |
3 | 4 | import * as Lsp from "../../src/lsp/index" |
| 5 | +import * as launch from "../../src/lsp/launch" |
4 | 6 | import { LSPServer } from "../../src/lsp/server" |
5 | 7 | import { Instance } from "../../src/project/instance" |
6 | 8 | import { tmpdir } from "../fixture/fixture" |
@@ -52,4 +54,80 @@ describe("lsp.spawn", () => { |
52 | 54 | await Instance.disposeAll() |
53 | 55 | } |
54 | 56 | }) |
| 57 | + |
| 58 | + test("spawns builtin Typescript LSP with correct arguments", async () => { |
| 59 | + await using tmp = await tmpdir() |
| 60 | + |
| 61 | + // Create dummy tsserver to satisfy Module.resolve |
| 62 | + const tsdk = path.join(tmp.path, "node_modules", "typescript", "lib") |
| 63 | + await fs.mkdir(tsdk, { recursive: true }) |
| 64 | + await fs.writeFile(path.join(tsdk, "tsserver.js"), "") |
| 65 | + |
| 66 | + const spawnSpy = spyOn(launch, "spawn").mockImplementation( |
| 67 | + () => |
| 68 | + ({ |
| 69 | + stdin: {}, |
| 70 | + stdout: {}, |
| 71 | + stderr: {}, |
| 72 | + on: () => {}, |
| 73 | + kill: () => {}, |
| 74 | + }) as any, |
| 75 | + ) |
| 76 | + |
| 77 | + try { |
| 78 | + await Instance.provide({ |
| 79 | + directory: tmp.path, |
| 80 | + fn: async () => { |
| 81 | + await LSPServer.Typescript.spawn(tmp.path) |
| 82 | + }, |
| 83 | + }) |
| 84 | + |
| 85 | + expect(spawnSpy).toHaveBeenCalled() |
| 86 | + const args = spawnSpy.mock.calls[0][1] as string[] |
| 87 | + |
| 88 | + expect(args).toContain("--tsserver-path") |
| 89 | + expect(args).toContain("--tsserver-log-verbosity") |
| 90 | + expect(args).toContain("off") |
| 91 | + } finally { |
| 92 | + spawnSpy.mockRestore() |
| 93 | + } |
| 94 | + }) |
| 95 | + |
| 96 | + test("spawns builtin Typescript LSP with --ignore-node-modules if no config is found", async () => { |
| 97 | + await using tmp = await tmpdir() |
| 98 | + |
| 99 | + // Create dummy tsserver to satisfy Module.resolve |
| 100 | + const tsdk = path.join(tmp.path, "node_modules", "typescript", "lib") |
| 101 | + await fs.mkdir(tsdk, { recursive: true }) |
| 102 | + await fs.writeFile(path.join(tsdk, "tsserver.js"), "") |
| 103 | + |
| 104 | + // NO tsconfig.json or jsconfig.json created here |
| 105 | + |
| 106 | + const spawnSpy = spyOn(launch, "spawn").mockImplementation( |
| 107 | + () => |
| 108 | + ({ |
| 109 | + stdin: {}, |
| 110 | + stdout: {}, |
| 111 | + stderr: {}, |
| 112 | + on: () => {}, |
| 113 | + kill: () => {}, |
| 114 | + }) as any, |
| 115 | + ) |
| 116 | + |
| 117 | + try { |
| 118 | + await Instance.provide({ |
| 119 | + directory: tmp.path, |
| 120 | + fn: async () => { |
| 121 | + await LSPServer.Typescript.spawn(tmp.path) |
| 122 | + }, |
| 123 | + }) |
| 124 | + |
| 125 | + expect(spawnSpy).toHaveBeenCalled() |
| 126 | + const args = spawnSpy.mock.calls[0][1] as string[] |
| 127 | + |
| 128 | + expect(args).toContain("--ignore-node-modules") |
| 129 | + } finally { |
| 130 | + spawnSpy.mockRestore() |
| 131 | + } |
| 132 | + }) |
55 | 133 | }) |
0 commit comments