Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(editor): check if workspace configuration is updated #7403

Merged
merged 5 commits into from
Nov 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions editors/vscode/.vscode-test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ import { defineConfig } from '@vscode/test-cli';

export default defineConfig({
files: 'out/**/*.spec.js',
workspaceFolder: './test_workspace',
});
20 changes: 10 additions & 10 deletions editors/vscode/client/Config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ export class Config implements ConfigInterface {
return this._runTrigger;
}

set runTrigger(value: Trigger) {
updateRunTrigger(value: Trigger): PromiseLike<void> {
this._runTrigger = value;
workspace
return workspace
.getConfiguration(Config._namespace)
.update('lint.run', value);
}
Expand All @@ -38,9 +38,9 @@ export class Config implements ConfigInterface {
return this._enable;
}

set enable(value: boolean) {
updateEnable(value: boolean): PromiseLike<void> {
this._enable = value;
workspace
return workspace
.getConfiguration(Config._namespace)
.update('enable', value);
}
Expand All @@ -49,9 +49,9 @@ export class Config implements ConfigInterface {
return this._trace;
}

set trace(value: TraceLevel) {
updateTrace(value: TraceLevel): PromiseLike<void> {
this._trace = value;
workspace
return workspace
.getConfiguration(Config._namespace)
.update('trace.server', value);
}
Expand All @@ -60,9 +60,9 @@ export class Config implements ConfigInterface {
return this._configPath;
}

set configPath(value: string) {
updateConfigPath(value: string): PromiseLike<void> {
this._configPath = value;
workspace
return workspace
.getConfiguration(Config._namespace)
.update('configPath', value);
}
Expand All @@ -71,9 +71,9 @@ export class Config implements ConfigInterface {
return this._binPath;
}

set binPath(value: string | undefined) {
updateBinPath(value: string | undefined): PromiseLike<void> {
this._binPath = value;
workspace
return workspace
.getConfiguration(Config._namespace)
.update('path.server', value);
}
Expand Down
28 changes: 28 additions & 0 deletions editors/vscode/client/config.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
import { strictEqual } from 'assert';
import { workspace } from 'vscode';
import { Config } from './Config.js';

suite('Config', () => {
setup(async () => {
const wsConfig = workspace.getConfiguration('oxc');
const keys = ['lint.run', 'enable', 'trace.server', 'configPath', 'path.server'];

await Promise.all(keys.map(key => wsConfig.update(key, undefined)));
});

test('default values on initialization', () => {
const config = new Config();

Expand All @@ -11,4 +19,24 @@ suite('Config', () => {
strictEqual(config.configPath, '.eslintrc');
strictEqual(config.binPath, '');
});

test('updating values updates the workspace configuration', async () => {
const config = new Config();

await Promise.all([
config.updateRunTrigger('onSave'),
config.updateEnable(false),
config.updateTrace('messages'),
config.updateConfigPath('./somewhere'),
config.updateBinPath('./binary'),
]);

const wsConfig = workspace.getConfiguration('oxc');

strictEqual(wsConfig.get('lint.run'), 'onSave');
strictEqual(wsConfig.get('enable'), false);
strictEqual(wsConfig.get('trace.server'), 'messages');
strictEqual(wsConfig.get('configPath'), './somewhere');
strictEqual(wsConfig.get('path.server'), './binary');
});
});
2 changes: 1 addition & 1 deletion editors/vscode/client/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export async function activate(context: ExtensionContext) {
const toggleEnable = commands.registerCommand(
OxcCommands.ToggleEnable,
() => {
configService.config.enable = !configService.config.enable;
configService.config.updateEnable(!configService.config.enable);
},
);

Expand Down
2 changes: 2 additions & 0 deletions editors/vscode/test_workspace/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
**
!.gitignore
Loading