Skip to content

Commit d5532c1

Browse files
committed
test(editor): add oxc.fixAll command test
1 parent 5ff50e6 commit d5532c1

File tree

4 files changed

+70
-2
lines changed

4 files changed

+70
-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

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import { deepStrictEqual } from 'assert';
2+
import { commands, extensions } 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+
suite('commands', () => {
9+
setup(async () => {
10+
const ext = extensions.getExtension('oxc.oxc-vscode')!;
11+
await ext.activate();
12+
});
13+
14+
// suiteTeardown(async () => {
15+
// const edit = new WorkspaceEdit();
16+
// edit.deleteFile(fileUri);
17+
// await workspace.applyEdit(edit);
18+
// });
19+
20+
test('listed commands', async () => {
21+
const oxcCommands = (await commands.getCommands(true)).filter(x => x.startsWith('oxc.'));
22+
23+
deepStrictEqual([
24+
'oxc.restartServer',
25+
'oxc.showOutputChannel',
26+
'oxc.toggleEnable',
27+
'oxc.applyAllFixesFile',
28+
'oxc.fixAll',
29+
], oxcCommands);
30+
});
31+
32+
// ToDo: check why this is not working,
33+
// even with .gitignore deleted in th test_workspace
34+
//
35+
// test('oxc.fixAll', async () => {
36+
// const edit = new WorkspaceEdit();
37+
// edit.createFile(fileUri, {
38+
// contents: Buffer.from('/* 😊 */debugger;'),
39+
// });
40+
//
41+
// await workspace.applyEdit(edit);
42+
// await window.showTextDocument(fileUri);
43+
// await sleep(500);
44+
// await commands.executeCommand('oxc.fixAll', {
45+
// uri: fileUri.toString(),
46+
// });
47+
// await workspace.saveAll();
48+
// await sleep(1000);
49+
//
50+
// const content = await readFile(fileUri.fsPath, {
51+
// encoding: 'utf8',
52+
// });
53+
//
54+
// strictEqual(content, '/* 😊 */');
55+
// });
56+
});

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)