From 65b8d74eb8e261aaeb33df9f662156c9d38fccd1 Mon Sep 17 00:00:00 2001 From: Sysix <3897725+Sysix@users.noreply.github.com> Date: Sat, 22 Nov 2025 21:33:24 +0000 Subject: [PATCH] test(vscode): testsetup for `oxfmt --lsp` server (#15883) --- .github/workflows/ci_vscode.yml | 5 +++++ editors/vscode/.vscode-test.mjs | 17 +++++++++++++++++ editors/vscode/package.json | 2 ++ editors/vscode/tests/code_actions.spec.ts | 5 +++++ editors/vscode/tests/commands.spec.ts | 12 ++++++++++-- .../vscode/tests/e2e_server_formatter.spec.ts | 10 +++++++--- editors/vscode/tests/e2e_server_linter.spec.ts | 5 +++++ 7 files changed, 51 insertions(+), 5 deletions(-) diff --git a/.github/workflows/ci_vscode.yml b/.github/workflows/ci_vscode.yml index 3c7d763fe2ef4..ab6614321b3c0 100644 --- a/.github/workflows/ci_vscode.yml +++ b/.github/workflows/ci_vscode.yml @@ -18,6 +18,7 @@ on: - "pnpm-lock.yaml" - "crates/oxc_language_server/**" - "apps/oxlint/src/lsp.rs" + - "apps/oxfmt/src/lsp/**" - "editors/vscode/**" - ".github/workflows/ci_vscode.yml" @@ -50,6 +51,10 @@ jobs: working-directory: editors/vscode run: pnpm run oxlint:build:debug + - name: Build oxfmt (with napi) + working-directory: editors/vscode + run: pnpm run oxfmt:build:debug + - name: Compile VSCode working-directory: editors/vscode run: pnpm run compile diff --git a/editors/vscode/.vscode-test.mjs b/editors/vscode/.vscode-test.mjs index 0d2113a46c052..a68d36de5b35f 100644 --- a/editors/vscode/.vscode-test.mjs +++ b/editors/vscode/.vscode-test.mjs @@ -65,5 +65,22 @@ export default defineConfig({ timeout: 10_000, }, }, + // Oxfmt --lsp tests + { + files: 'out/**/*.spec.js', + workspaceFolder: './test_workspace', + launchArgs: [ + // This disables all extensions except the one being tested + '--disable-extensions', + ], + env: { + SINGLE_FOLDER_WORKSPACE: 'true', + SERVER_PATH_DEV: path.resolve(import.meta.dirname, `../../apps/oxfmt/dist/cli.js`), + SKIP_LINTER_TEST: 'true', + }, + mocha: { + timeout: 10_000, + }, + }, ], }); diff --git a/editors/vscode/package.json b/editors/vscode/package.json index 43b50edc9e3a5..37076c996e374 100644 --- a/editors/vscode/package.json +++ b/editors/vscode/package.json @@ -245,6 +245,8 @@ "install-extension": "code --install-extension oxc_language_server.vsix --force", "oxlint:build:debug": "pnpm -C ../../apps/oxlint build-napi-test && pnpm -C ../../apps/oxlint build-js", "oxlint:build:release": "pnpm -C ../../apps/oxlint build-napi && pnpm -C ../../apps/oxlint build-js", + "oxfmt:build:debug": "pnpm -C ../../apps/oxfmt build-napi-test && pnpm -C ../../apps/oxfmt build-js", + "oxfmt:build:release": "pnpm -C ../../apps/oxfmt build-napi && pnpm -C ../../apps/oxfmt build-js", "server:build:debug": "cross-env CARGO_TARGET_DIR=./target cargo build -p oxc_language_server", "server:build:release": "cross-env CARGO_TARGET_DIR=./target cargo build -p oxc_language_server --release", "test": "cross-env TEST=true pnpm run compile && vscode-test", diff --git a/editors/vscode/tests/code_actions.spec.ts b/editors/vscode/tests/code_actions.spec.ts index 371199512d3d2..99d3440b7e153 100644 --- a/editors/vscode/tests/code_actions.spec.ts +++ b/editors/vscode/tests/code_actions.spec.ts @@ -35,6 +35,11 @@ teardown(async () => { }); suite('code actions', () => { + // Skip tests if linter tests are disabled + if (process.env.SKIP_LINTER_TEST === 'true') { + return; + } + // flaky test for multi workspace mode testSingleFolderMode('listed code actions', async () => { await loadFixture('debugger'); diff --git a/editors/vscode/tests/commands.spec.ts b/editors/vscode/tests/commands.spec.ts index 1acb80946e9a8..1358c0c899d0b 100644 --- a/editors/vscode/tests/commands.spec.ts +++ b/editors/vscode/tests/commands.spec.ts @@ -31,12 +31,16 @@ suite('commands', () => { testSingleFolderMode('listed commands', async () => { const oxcCommands = (await commands.getCommands(true)).filter(x => x.startsWith('oxc.')); + const extraCommands = process.env.SKIP_LINTER_TEST === 'true' ? [] : [ + 'oxc.fixAll', + ]; + deepStrictEqual([ 'oxc.restartServer', 'oxc.showOutputChannel', 'oxc.toggleEnable', - 'oxc.applyAllFixesFile', - 'oxc.fixAll', + 'oxc.applyAllFixesFile', // TODO: only if linter tests are enabled + ...extraCommands, ], oxcCommands); }); @@ -67,6 +71,10 @@ suite('commands', () => { }); test('oxc.fixAll', async () => { + // Skip tests if linter tests are disabled + if (process.env.SKIP_LINTER_TEST === 'true') { + return; + } const edit = new WorkspaceEdit(); edit.createFile(fileUri, { contents: Buffer.from('/* 😊 */debugger;'), diff --git a/editors/vscode/tests/e2e_server_formatter.spec.ts b/editors/vscode/tests/e2e_server_formatter.spec.ts index 8c39cd76ea0dc..7ffc82412d9f9 100644 --- a/editors/vscode/tests/e2e_server_formatter.spec.ts +++ b/editors/vscode/tests/e2e_server_formatter.spec.ts @@ -14,6 +14,9 @@ import { suiteSetup(async () => { await activateExtension(); + await workspace.getConfiguration('oxc').update('fmt.experimental', true); + await workspace.getConfiguration('editor').update('defaultFormatter', 'oxc.oxc-vscode'); + await workspace.saveAll(); }); teardown(async () => { @@ -32,6 +35,7 @@ suite('E2E Server Formatter', () => { test('formats code with `oxc.fmt.experimental`', async () => { await workspace.getConfiguration('oxc').update('fmt.experimental', true); await workspace.getConfiguration('editor').update('defaultFormatter', 'oxc.oxc-vscode'); + await workspace.saveAll(); await loadFixture('formatting'); await sleep(500); @@ -49,16 +53,16 @@ suite('E2E Server Formatter', () => { test('formats code with `oxc.fmt.configPath`', async () => { await loadFixture('formatting_with_config'); - await workspace.getConfiguration('oxc').update('fmt.experimental', true); - await workspace.getConfiguration('oxc').update('fmt.configPath', './fixtures/formatter.json'); await workspace.getConfiguration('editor').update('defaultFormatter', 'oxc.oxc-vscode'); + await workspace.getConfiguration('oxc').update('fmt.configPath', './fixtures/formatter.json'); + await workspace.saveAll(); - await sleep(500); // wait for the server to pick up the new config const fileUri = Uri.joinPath(fixturesWorkspaceUri(), 'fixtures', 'formatting.ts'); const document = await workspace.openTextDocument(fileUri); await window.showTextDocument(document); + await sleep(500); // wait for the server to pick up the new config await commands.executeCommand('editor.action.formatDocument'); await workspace.saveAll(); const content = await workspace.fs.readFile(fileUri); diff --git a/editors/vscode/tests/e2e_server_linter.spec.ts b/editors/vscode/tests/e2e_server_linter.spec.ts index aa6d9d0480ad4..49125061d62e1 100644 --- a/editors/vscode/tests/e2e_server_linter.spec.ts +++ b/editors/vscode/tests/e2e_server_linter.spec.ts @@ -43,6 +43,11 @@ teardown(async () => { suite('E2E Server Linter', () => { + // Skip tests if linter tests are disabled + if (process.env.SKIP_LINTER_TEST === 'true') { + return; + } + test('simple debugger statement', async () => { await loadFixture('debugger'); const diagnostics = await getDiagnostics('debugger.js');