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

setter methods can not return anything (void), so that why I needed to
refactor them :)
This commit is contained in:
Alexander S. 2024-11-23 05:59:18 +01:00 committed by GitHub
parent 6c0d31b165
commit 779f4798e2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 42 additions and 11 deletions

View file

@ -2,4 +2,5 @@ import { defineConfig } from '@vscode/test-cli';
export default defineConfig({
files: 'out/**/*.spec.js',
workspaceFolder: './test_workspace',
});

View file

@ -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);
}
@ -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);
}
@ -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);
}
@ -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);
}
@ -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);
}

View file

@ -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();
@ -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');
});
});

View file

@ -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);
},
);

View file

@ -0,0 +1,2 @@
**
!.gitignore