Skip to content

Commit b6c682f

Browse files
committed
test(vscode): testsetup for oxfmt --lsp server
1 parent 54e8799 commit b6c682f

File tree

7 files changed

+51
-5
lines changed

7 files changed

+51
-5
lines changed

.github/workflows/ci_vscode.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ on:
1818
- "pnpm-lock.yaml"
1919
- "crates/oxc_language_server/**"
2020
- "apps/oxlint/src/lsp.rs"
21+
- "apps/oxfmt/src/lsp/**"
2122
- "editors/vscode/**"
2223
- ".github/workflows/ci_vscode.yml"
2324

@@ -50,6 +51,10 @@ jobs:
5051
working-directory: editors/vscode
5152
run: pnpm run oxlint:build:debug
5253

54+
- name: Build oxfmt (with napi)
55+
working-directory: editors/vscode
56+
run: pnpm run oxfmt:build:debug
57+
5358
- name: Compile VSCode
5459
working-directory: editors/vscode
5560
run: pnpm run compile

editors/vscode/.vscode-test.mjs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,5 +65,22 @@ export default defineConfig({
6565
timeout: 10_000,
6666
},
6767
},
68+
// Oxfmt --lsp tests
69+
{
70+
files: 'out/**/*.spec.js',
71+
workspaceFolder: './test_workspace',
72+
launchArgs: [
73+
// This disables all extensions except the one being tested
74+
'--disable-extensions',
75+
],
76+
env: {
77+
SINGLE_FOLDER_WORKSPACE: 'true',
78+
SERVER_PATH_DEV: path.resolve(import.meta.dirname, `../../apps/oxfmt/dist/cli.js`),
79+
SKIP_LINTER_TEST: 'true',
80+
},
81+
mocha: {
82+
timeout: 10_000,
83+
},
84+
},
6885
],
6986
});

editors/vscode/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,8 @@
245245
"install-extension": "code --install-extension oxc_language_server.vsix --force",
246246
"oxlint:build:debug": "pnpm -C ../../apps/oxlint build-napi-test && pnpm -C ../../apps/oxlint build-js",
247247
"oxlint:build:release": "pnpm -C ../../apps/oxlint build-napi && pnpm -C ../../apps/oxlint build-js",
248+
"oxfmt:build:debug": "pnpm -C ../../apps/oxfmt build-napi-test && pnpm -C ../../apps/oxfmt build-js",
249+
"oxfmt:build:release": "pnpm -C ../../apps/oxfmt build-napi && pnpm -C ../../apps/oxfmt build-js",
248250
"server:build:debug": "cross-env CARGO_TARGET_DIR=./target cargo build -p oxc_language_server",
249251
"server:build:release": "cross-env CARGO_TARGET_DIR=./target cargo build -p oxc_language_server --release",
250252
"test": "cross-env TEST=true pnpm run compile && vscode-test",

editors/vscode/tests/code_actions.spec.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@ teardown(async () => {
3535
});
3636

3737
suite('code actions', () => {
38+
// Skip tests if linter tests are disabled
39+
if (process.env.SKIP_LINTER_TEST === 'true') {
40+
return;
41+
}
42+
3843
// flaky test for multi workspace mode
3944
testSingleFolderMode('listed code actions', async () => {
4045
await loadFixture('debugger');

editors/vscode/tests/commands.spec.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,16 @@ suite('commands', () => {
3131
testSingleFolderMode('listed commands', async () => {
3232
const oxcCommands = (await commands.getCommands(true)).filter(x => x.startsWith('oxc.'));
3333

34+
const extraCommands = process.env.SKIP_LINTER_TEST === 'true' ? [] : [
35+
'oxc.fixAll',
36+
];
37+
3438
deepStrictEqual([
3539
'oxc.restartServer',
3640
'oxc.showOutputChannel',
3741
'oxc.toggleEnable',
38-
'oxc.applyAllFixesFile',
39-
'oxc.fixAll',
42+
'oxc.applyAllFixesFile', // TODO: only if linter tests are enabled
43+
...extraCommands,
4044
], oxcCommands);
4145
});
4246

@@ -67,6 +71,10 @@ suite('commands', () => {
6771
});
6872

6973
test('oxc.fixAll', async () => {
74+
// Skip tests if linter tests are disabled
75+
if (process.env.SKIP_LINTER_TEST === 'true') {
76+
return;
77+
}
7078
const edit = new WorkspaceEdit();
7179
edit.createFile(fileUri, {
7280
contents: Buffer.from('/* 😊 */debugger;'),

editors/vscode/tests/e2e_server_formatter.spec.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ import {
1414

1515
suiteSetup(async () => {
1616
await activateExtension();
17+
await workspace.getConfiguration('oxc').update('fmt.experimental', true);
18+
await workspace.getConfiguration('editor').update('defaultFormatter', 'oxc.oxc-vscode');
19+
await workspace.saveAll();
1720
});
1821

1922
teardown(async () => {
@@ -32,6 +35,7 @@ suite('E2E Server Formatter', () => {
3235
test('formats code with `oxc.fmt.experimental`', async () => {
3336
await workspace.getConfiguration('oxc').update('fmt.experimental', true);
3437
await workspace.getConfiguration('editor').update('defaultFormatter', 'oxc.oxc-vscode');
38+
await workspace.saveAll();
3539
await loadFixture('formatting');
3640

3741
await sleep(500);
@@ -49,16 +53,16 @@ suite('E2E Server Formatter', () => {
4953

5054
test('formats code with `oxc.fmt.configPath`', async () => {
5155
await loadFixture('formatting_with_config');
52-
5356
await workspace.getConfiguration('oxc').update('fmt.experimental', true);
54-
await workspace.getConfiguration('oxc').update('fmt.configPath', './fixtures/formatter.json');
5557
await workspace.getConfiguration('editor').update('defaultFormatter', 'oxc.oxc-vscode');
58+
await workspace.getConfiguration('oxc').update('fmt.configPath', './fixtures/formatter.json');
59+
await workspace.saveAll();
5660

57-
await sleep(500); // wait for the server to pick up the new config
5861
const fileUri = Uri.joinPath(fixturesWorkspaceUri(), 'fixtures', 'formatting.ts');
5962

6063
const document = await workspace.openTextDocument(fileUri);
6164
await window.showTextDocument(document);
65+
await sleep(500); // wait for the server to pick up the new config
6266
await commands.executeCommand('editor.action.formatDocument');
6367
await workspace.saveAll();
6468
const content = await workspace.fs.readFile(fileUri);

editors/vscode/tests/e2e_server_linter.spec.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,11 @@ teardown(async () => {
4343

4444

4545
suite('E2E Server Linter', () => {
46+
// Skip tests if linter tests are disabled
47+
if (process.env.SKIP_LINTER_TEST === 'true') {
48+
return;
49+
}
50+
4651
test('simple debugger statement', async () => {
4752
await loadFixture('debugger');
4853
const diagnostics = await getDiagnostics('debugger.js');

0 commit comments

Comments
 (0)