mirror of
https://github.com/danbulant/oxc
synced 2026-05-24 12:21:58 +00:00
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:
parent
6c0d31b165
commit
779f4798e2
5 changed files with 42 additions and 11 deletions
|
|
@ -2,4 +2,5 @@ import { defineConfig } from '@vscode/test-cli';
|
||||||
|
|
||||||
export default defineConfig({
|
export default defineConfig({
|
||||||
files: 'out/**/*.spec.js',
|
files: 'out/**/*.spec.js',
|
||||||
|
workspaceFolder: './test_workspace',
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -27,9 +27,9 @@ export class Config implements ConfigInterface {
|
||||||
return this._runTrigger;
|
return this._runTrigger;
|
||||||
}
|
}
|
||||||
|
|
||||||
set runTrigger(value: Trigger) {
|
updateRunTrigger(value: Trigger): PromiseLike<void> {
|
||||||
this._runTrigger = value;
|
this._runTrigger = value;
|
||||||
workspace
|
return workspace
|
||||||
.getConfiguration(Config._namespace)
|
.getConfiguration(Config._namespace)
|
||||||
.update('lint.run', value);
|
.update('lint.run', value);
|
||||||
}
|
}
|
||||||
|
|
@ -38,9 +38,9 @@ export class Config implements ConfigInterface {
|
||||||
return this._enable;
|
return this._enable;
|
||||||
}
|
}
|
||||||
|
|
||||||
set enable(value: boolean) {
|
updateEnable(value: boolean): PromiseLike<void> {
|
||||||
this._enable = value;
|
this._enable = value;
|
||||||
workspace
|
return workspace
|
||||||
.getConfiguration(Config._namespace)
|
.getConfiguration(Config._namespace)
|
||||||
.update('enable', value);
|
.update('enable', value);
|
||||||
}
|
}
|
||||||
|
|
@ -49,9 +49,9 @@ export class Config implements ConfigInterface {
|
||||||
return this._trace;
|
return this._trace;
|
||||||
}
|
}
|
||||||
|
|
||||||
set trace(value: TraceLevel) {
|
updateTrace(value: TraceLevel): PromiseLike<void> {
|
||||||
this._trace = value;
|
this._trace = value;
|
||||||
workspace
|
return workspace
|
||||||
.getConfiguration(Config._namespace)
|
.getConfiguration(Config._namespace)
|
||||||
.update('trace.server', value);
|
.update('trace.server', value);
|
||||||
}
|
}
|
||||||
|
|
@ -60,9 +60,9 @@ export class Config implements ConfigInterface {
|
||||||
return this._configPath;
|
return this._configPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
set configPath(value: string) {
|
updateConfigPath(value: string): PromiseLike<void> {
|
||||||
this._configPath = value;
|
this._configPath = value;
|
||||||
workspace
|
return workspace
|
||||||
.getConfiguration(Config._namespace)
|
.getConfiguration(Config._namespace)
|
||||||
.update('configPath', value);
|
.update('configPath', value);
|
||||||
}
|
}
|
||||||
|
|
@ -71,9 +71,9 @@ export class Config implements ConfigInterface {
|
||||||
return this._binPath;
|
return this._binPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
set binPath(value: string | undefined) {
|
updateBinPath(value: string | undefined): PromiseLike<void> {
|
||||||
this._binPath = value;
|
this._binPath = value;
|
||||||
workspace
|
return workspace
|
||||||
.getConfiguration(Config._namespace)
|
.getConfiguration(Config._namespace)
|
||||||
.update('path.server', value);
|
.update('path.server', value);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,15 @@
|
||||||
import { strictEqual } from 'assert';
|
import { strictEqual } from 'assert';
|
||||||
|
import { workspace } from 'vscode';
|
||||||
import { Config } from './Config.js';
|
import { Config } from './Config.js';
|
||||||
|
|
||||||
suite('Config', () => {
|
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', () => {
|
test('default values on initialization', () => {
|
||||||
const config = new Config();
|
const config = new Config();
|
||||||
|
|
||||||
|
|
@ -11,4 +19,24 @@ suite('Config', () => {
|
||||||
strictEqual(config.configPath, '.eslintrc');
|
strictEqual(config.configPath, '.eslintrc');
|
||||||
strictEqual(config.binPath, '');
|
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');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -58,7 +58,7 @@ export async function activate(context: ExtensionContext) {
|
||||||
const toggleEnable = commands.registerCommand(
|
const toggleEnable = commands.registerCommand(
|
||||||
OxcCommands.ToggleEnable,
|
OxcCommands.ToggleEnable,
|
||||||
() => {
|
() => {
|
||||||
configService.config.enable = !configService.config.enable;
|
configService.config.updateEnable(!configService.config.enable);
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
||||||
2
editors/vscode/test_workspace/.gitignore
vendored
Normal file
2
editors/vscode/test_workspace/.gitignore
vendored
Normal file
|
|
@ -0,0 +1,2 @@
|
||||||
|
**
|
||||||
|
!.gitignore
|
||||||
Loading…
Reference in a new issue