Repository: oxc-project/oxc
Pull request #9930: test(editor): add tests for listing all oxc commands
Author: login: Sysix
Labels: name: A-editor
description: Area - Editor and Language Server
name: C-test
description: Category - Testing. Code is missing test cases, or a PR is adding them
Created: 2025-03-20T20:39:36Z | Merged: 2025-03-23T13:45:24Z



Diff:
diff --git a/.github/workflows/ci_vscode.yml b/.github/workflows/ci_vscode.yml
index 99453e4d13dc0..f2bb27c3f51f8 100644
--- a/.github/workflows/ci_vscode.yml
+++ b/.github/workflows/ci_vscode.yml
@@ -65,6 +65,10 @@ jobs:
       - uses: taiki-e/checkout-action@b13d20b7cda4e2f325ef19895128f7ff735c0b3d # v1.3.1
       - uses: ./.github/actions/pnpm
 
+      - name: Build
+        working-directory: editors/vscode
+        run: pnpm run build
+
       - name: Test VSCode
         working-directory: editors/vscode
         run: xvfb-run -a pnpm run test
diff --git a/editors/vscode/client/config.spec.ts b/editors/vscode/client/config.spec.ts
index dc3557730d054..28d459359c33d 100644
--- a/editors/vscode/client/config.spec.ts
+++ b/editors/vscode/client/config.spec.ts
@@ -1,5 +1,5 @@
 import { deepStrictEqual, strictEqual } from 'assert';
-import { workspace } from 'vscode';
+import { Uri, workspace, WorkspaceEdit } from 'vscode';
 import { Config } from './Config.js';
 
 suite('Config', () => {
@@ -10,6 +10,14 @@ suite('Config', () => {
     await Promise.all(keys.map(key => wsConfig.update(key, undefined)));
   });
 
+  suiteTeardown(async () => {
+    const WORKSPACE_DIR = workspace.workspaceFolders![0].uri.toString();
+    const file = Uri.parse(WORKSPACE_DIR + '/.vscode/settings.json');
+    const edit = new WorkspaceEdit();
+    edit.deleteFile(file);
+    await workspace.applyEdit(edit);
+  });
+
   test('default values on initialization', () => {
     const config = new Config();
 
diff --git a/editors/vscode/client/extension.spec.ts b/editors/vscode/client/extension.spec.ts
new file mode 100644
index 0000000000000..2769d3d672499
--- /dev/null
+++ b/editors/vscode/client/extension.spec.ts
@@ -0,0 +1,56 @@
+import { deepStrictEqual } from 'assert';
+import { commands, extensions } from 'vscode';
+
+// const WORKSPACE_DIR = workspace.workspaceFolders![0].uri.toString();
+// const filePath = WORKSPACE_DIR + '/debugger.js';
+// const fileUri = Uri.parse(filePath);
+
+suite('commands', () => {
+  setup(async () => {
+    const ext = extensions.getExtension('oxc.oxc-vscode')!;
+    await ext.activate();
+  });
+
+  // suiteTeardown(async () => {
+  //   const edit = new WorkspaceEdit();
+  //   edit.deleteFile(fileUri);
+  //   await workspace.applyEdit(edit);
+  // });
+
+  test('listed commands', async () => {
+    const oxcCommands = (await commands.getCommands(true)).filter(x => x.startsWith('oxc.'));
+
+    deepStrictEqual([
+      'oxc.restartServer',
+      'oxc.showOutputChannel',
+      'oxc.toggleEnable',
+      'oxc.applyAllFixesFile',
+      'oxc.fixAll',
+    ], oxcCommands);
+  });
+
+  // ToDo: check why this is not working,
+  // even with .gitignore deleted in th test_workspace
+  //
+  // test('oxc.fixAll', async () => {
+  //   const edit = new WorkspaceEdit();
+  //   edit.createFile(fileUri, {
+  //     contents: Buffer.from('/* 😊 */debugger;'),
+  //   });
+  //
+  //   await workspace.applyEdit(edit);
+  //   await window.showTextDocument(fileUri);
+  //   await sleep(500);
+  //   await commands.executeCommand('oxc.fixAll', {
+  //     uri: fileUri.toString(),
+  //   });
+  //   await workspace.saveAll();
+  //   await sleep(1000);
+  //
+  //   const content = await readFile(fileUri.fsPath, {
+  //     encoding: 'utf8',
+  //   });
+  //
+  //  strictEqual(content, '/* 😊 */');
+  // });
+});
diff --git a/editors/vscode/package.json b/editors/vscode/package.json
index 95b0adefe9c70..2ce6d987baabe 100644
--- a/editors/vscode/package.json
+++ b/editors/vscode/package.json
@@ -146,7 +146,7 @@
     "server:build:debug": "cargo build -p oxc_language_server",
     "server:build:release": "cross-env CARGO_TARGET_DIR=./target cargo build -p oxc_language_server --release",
     "lint": "npx oxlint --config=oxlint.json --tsconfig=tsconfig.json",
-    "test": "esbuild client/config.spec.ts --bundle --outfile=out/config.spec.js --external:vscode --format=cjs --platform=node --target=node16 --minify --sourcemap && vscode-test",
+    "test": "esbuild client/*.spec.ts --bundle --outdir=out --external:vscode --format=cjs --platform=node --target=node16 --minify --sourcemap && vscode-test",
     "type-check": "tsc --noEmit"
   },
   "devDependencies": {


Reviews:
user: login: Sysix
state: COMMENTED
author_association: MEMBER
submitted_at: 2025-03-23T00:55:20Z
user: login: Boshen
state: COMMENTED
author_association: MEMBER
submitted_at: 2025-03-23T05:24:07Z

Review comments:
diff_hunk: @@ -65,6 +65,10 @@ jobs:
       - uses: taiki-e/checkout-action@b13d20b7cda4e2f325ef19895128f7ff735c0b3d # v1.3.1
       - uses: ./.github/actions/pnpm
 
+      - name: Build
+        working-directory: editors/vscode
+        run: pnpm run build
path: .github/workflows/ci_vscode.yml
user: login: Sysix
body: this will build the vscode and the langauge server and costs time in CI.
The goal is to create integrations tests between them. 
created_at: 2025-03-23T00:55:20Z
author_association: MEMBER
diff_hunk: @@ -65,6 +65,10 @@ jobs:
       - uses: taiki-e/checkout-action@b13d20b7cda4e2f325ef19895128f7ff735c0b3d # v1.3.1
       - uses: ./.github/actions/pnpm
 
+      - name: Build
+        working-directory: editors/vscode
+        run: pnpm run build
path: .github/workflows/ci_vscode.yml
user: login: Boshen
body: We'll need a follow up PR to combine all the compile + test jobs together to save resources. We have way too many jobs in this org, causing long queue of jobs.
created_at: 2025-03-23T05:24:07Z
author_association: MEMBER

PR comments:
user: login: Sysix
created_at: 2025-03-20T20:39:54Z
body: * **#9987** <a href="https://app.graphite.dev/github/pr/oxc-project/oxc/9987?utm_source=stack-comment-icon" target="_blank"><img src="https://static.graphite.dev/graphite-32x32-black.png" alt="Graphite" width="10px" height="10px"/></a>
* **#9986** <a href="https://app.graphite.dev/github/pr/oxc-project/oxc/9986?utm_source=stack-comment-icon" target="_blank"><img src="https://static.graphite.dev/graphite-32x32-black.png" alt="Graphite" width="10px" height="10px"/></a>
* **#9985** <a href="https://app.graphite.dev/github/pr/oxc-project/oxc/9985?utm_source=stack-comment-icon" target="_blank"><img src="https://static.graphite.dev/graphite-32x32-black.png" alt="Graphite" width="10px" height="10px"/></a>
* **#9930** <a href="https://app.graphite.dev/github/pr/oxc-project/oxc/9930?utm_source=stack-comment-icon" target="_blank"><img src="https://static.graphite.dev/graphite-32x32-black.png" alt="Graphite" width="10px" height="10px"/></a> 👈 <a href="https://app.graphite.dev/github/pr/oxc-project/oxc/9930?utm_source=stack-comment-view-in-graphite" target="_blank">(View in Graphite)</a>
* `main`
<hr />

## How to use the Graphite Merge Queue

Add either label to this PR to merge it via the merge queue:
- <kbd>0-merge</kbd> - adds this PR to the back of the merge queue
- <kbd>hotfix</kbd> - for urgent hot fixes, skip the queue and merge this PR next

You must have a Graphite account in order to use the merge queue. Sign up using [this link](https://app.graphite.dev/invite/github/oxc-project?ref=merge-queue-instructions-in-stack-comment&prId=9930).

<h2></h2>
<sub>

An organization admin has enabled the [Graphite Merge Queue](https://graphite.dev/docs/graphite-merge-queue) in this repository.

</sub>

<sub>

Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue.

</sub>

<h2></h2>

This stack of pull requests is managed by <a href="https://graphite.dev?utm-source=stack-comment"><b>Graphite</b></a>. Learn more about <a href="https://stacking.dev/?utm_source=stack-comment">stacking</a>.
<!-- Current dependencies on/for this PR: -->
author_association: MEMBER
user: login: Boshen
created_at: 2025-03-23T13:39:40Z
body: ### Merge activity

* **Mar 23, 9:39 AM EDT**: The merge label '0-merge' was detected. This PR will be added to the [Graphite merge queue](https://app.graphite.dev/merges?org=oxc-project&repo=oxc) once it meets the requirements.
* **Mar 23, 9:39 AM EDT**: A user added this pull request to the [Graphite merge queue](https://app.graphite.dev/merges?org=oxc-project&repo=oxc).
* **Mar 23, 9:45 AM EDT**: A user  merged this pull request with the [Graphite merge queue](https://app.graphite.dev/merges?org=oxc-project&repo=oxc).

author_association: MEMBER