Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 5b3bc0f

Browse files
committedMar 23, 2025·
test(editor): add oxc.fixAll command test
1 parent 5ff50e6 commit 5b3bc0f

File tree

4 files changed

+80
-2
lines changed

4 files changed

+80
-2
lines changed
 

‎.github/workflows/ci_vscode.yml

+4
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,10 @@ jobs:
6565
- uses: taiki-e/checkout-action@b13d20b7cda4e2f325ef19895128f7ff735c0b3d # v1.3.1
6666
- uses: ./.github/actions/pnpm
6767

68+
- name: Build
69+
working-directory: editors/vscode
70+
run: pnpm run build
71+
6872
- name: Test VSCode
6973
working-directory: editors/vscode
7074
run: xvfb-run -a pnpm run test

‎editors/vscode/client/config.spec.ts

+9-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { deepStrictEqual, strictEqual } from 'assert';
2-
import { workspace } from 'vscode';
2+
import { Uri, workspace, WorkspaceEdit } from 'vscode';
33
import { Config } from './Config.js';
44

55
suite('Config', () => {
@@ -10,6 +10,14 @@ suite('Config', () => {
1010
await Promise.all(keys.map(key => wsConfig.update(key, undefined)));
1111
});
1212

13+
suiteTeardown(async () => {
14+
const WORKSPACE_DIR = workspace.workspaceFolders![0].uri.toString();
15+
const file = Uri.parse(WORKSPACE_DIR + '/.vscode/settings.json');
16+
const edit = new WorkspaceEdit();
17+
edit.deleteFile(file);
18+
await workspace.applyEdit(edit);
19+
});
20+
1321
test('default values on initialization', () => {
1422
const config = new Config();
1523

+66
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
import { deepStrictEqual } from 'assert';
2+
import { commands, extensions, Uri, workspace, WorkspaceEdit } from 'vscode';
3+
4+
const WORKSPACE_DIR = workspace.workspaceFolders![0].uri.toString();
5+
const filePath = WORKSPACE_DIR + '/debugger.js';
6+
const fileUri = Uri.parse(filePath);
7+
8+
async function sleep(ms: number) {
9+
return new Promise(resolve => setTimeout(resolve, ms));
10+
}
11+
12+
suite('commands', () => {
13+
setup(async () => {
14+
try {
15+
const ext = extensions.getExtension('oxc.oxc-vscode')!;
16+
await ext.activate();
17+
await sleep(1000);
18+
} catch (e) {
19+
console.error(e);
20+
}
21+
});
22+
23+
suiteTeardown(async () => {
24+
const edit = new WorkspaceEdit();
25+
edit.deleteFile(fileUri);
26+
await workspace.applyEdit(edit);
27+
});
28+
29+
test('listed commands', async () => {
30+
const oxcCommands = (await commands.getCommands(true)).filter(x => x.startsWith('oxc.'));
31+
console.log('asdASD', oxcCommands);
32+
33+
deepStrictEqual([
34+
'oxc.restartServer',
35+
'oxc.showOutputChannel',
36+
'oxc.toggleEnable',
37+
'oxc.applyAllFixesFile',
38+
'oxc.fixAll',
39+
], oxcCommands);
40+
});
41+
42+
// ToDo: check why this is not working,
43+
// even with .gitignore deleted in th test_workspace
44+
//
45+
// test('oxc.fixAll', async () => {
46+
// const edit = new WorkspaceEdit();
47+
// edit.createFile(fileUri, {
48+
// contents: Buffer.from('/* 😊 */debugger;'),
49+
// });
50+
//
51+
// await workspace.applyEdit(edit);
52+
// await window.showTextDocument(fileUri);
53+
// await sleep(500);
54+
// await commands.executeCommand('oxc.fixAll', {
55+
// uri: fileUri.toString(),
56+
// });
57+
// await workspace.saveAll();
58+
// await sleep(1000);
59+
//
60+
// const content = await readFile(fileUri.fsPath, {
61+
// encoding: 'utf8',
62+
// });
63+
//
64+
// strictEqual(content, '/* 😊 */');
65+
// });
66+
});

‎editors/vscode/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@
146146
"server:build:debug": "cargo build -p oxc_language_server",
147147
"server:build:release": "cross-env CARGO_TARGET_DIR=./target cargo build -p oxc_language_server --release",
148148
"lint": "npx oxlint --config=oxlint.json --tsconfig=tsconfig.json",
149-
"test": "esbuild client/config.spec.ts --bundle --outfile=out/config.spec.js --external:vscode --format=cjs --platform=node --target=node16 --minify --sourcemap && vscode-test",
149+
"test": "esbuild client/*.spec.ts --bundle --outdir=out --external:vscode --format=cjs --platform=node --target=node16 --minify --sourcemap && vscode-test",
150150
"type-check": "tsc --noEmit"
151151
},
152152
"devDependencies": {

0 commit comments

Comments
 (0)
Please sign in to comment.