Skip to content

Commit

Permalink
test(editor): check if workspace configuration is updated
Browse files Browse the repository at this point in the history
  • Loading branch information
Sysix committed Nov 21, 2024
1 parent 0918e52 commit 0d29659
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 10 deletions.
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');
});
});

0 comments on commit 0d29659

Please sign in to comment.