Skip to content

Commit ffec86b

Browse files
committed
test(oxfmt/lsp): define type OxfmtLSPConfig for initializationOptions (#18351)
1 parent fe7f835 commit ffec86b

2 files changed

Lines changed: 17 additions & 13 deletions

File tree

apps/oxfmt/test/lsp/format/format.test.ts

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { join } from "node:path";
2-
import { pathToFileURL } from "node:url";
32
import fs from "node:fs/promises";
43
import { describe, expect, it } from "vitest";
54
import { formatFixture } from "../utils";
@@ -82,14 +81,9 @@ describe("LSP formatting", () => {
8281
FIXTURES_DIR,
8382
"custom_config_path/semicolons-as-needed.ts",
8483
"typescript",
85-
[
86-
{
87-
workspaceUri: pathToFileURL(join(FIXTURES_DIR, "custom_config_path")).href,
88-
options: {
89-
"fmt.configPath": "./format.json",
90-
},
91-
},
92-
],
84+
{
85+
"fmt.configPath": "./format.json",
86+
},
9387
),
9488
).toMatchSnapshot();
9589
});

apps/oxfmt/test/lsp/utils.ts

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ export async function formatFixture(
8686
fixturesDir: string,
8787
fixturePath: string,
8888
languageId: string,
89-
initializationOptions?: unknown,
89+
initializationOptions?: OxfmtLSPConfig,
9090
): Promise<string> {
9191
const filePath = join(fixturesDir, fixturePath);
9292
const dirPath = dirname(filePath);
@@ -97,7 +97,12 @@ export async function formatFixture(
9797

9898
await client.initialize(
9999
[{ uri: pathToFileURL(dirPath).href, name: "test" }],
100-
initializationOptions,
100+
[
101+
{
102+
workspaceUri: pathToFileURL(dirPath).href,
103+
options: initializationOptions,
104+
},
105+
],
101106
);
102107
await client.didOpen(fileUri, languageId, content);
103108

@@ -118,8 +123,8 @@ export async function formatFixtureAfterConfigChange(
118123
fixturesDir: string,
119124
fixturePath: string,
120125
languageId: string,
121-
initializationOptions: unknown,
122-
configurationChangeOptions: unknown,
126+
initializationOptions: OxfmtLSPConfig,
127+
configurationChangeOptions: OxfmtLSPConfig,
123128
): Promise<string> {
124129
const filePath = join(fixturesDir, fixturePath);
125130
const dirPath = dirname(filePath);
@@ -165,6 +170,11 @@ ${formatted2}
165170

166171
// ---
167172

173+
// aligned with https://github.com/oxc-project/oxc/blob/7e6c15baaebf206ab540191da0e4e103e4fabf06/apps/oxfmt/src/lsp/options.rs
174+
type OxfmtLSPConfig = {
175+
"fmt.configPath"?: string | null;
176+
};
177+
168178
function applyEdits(content: string, edits: TextEdit[] | null, languageId: string): string | null {
169179
if (edits === null || edits.length === 0) return null;
170180
const doc = TextDocument.create("file:///test", languageId, 1, content);

0 commit comments

Comments
 (0)