Skip to content

Commit 779f479

Browse files
authored
test(editor): check if workspace configuration is updated (#7403)
setter methods can not return anything (void), so that why I needed to refactor them :)
1 parent 6c0d31b commit 779f479

5 files changed

Lines changed: 42 additions & 11 deletions

File tree

editors/vscode/.vscode-test.mjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@ import { defineConfig } from '@vscode/test-cli';
22

33
export default defineConfig({
44
files: 'out/**/*.spec.js',
5+
workspaceFolder: './test_workspace',
56
});

editors/vscode/client/Config.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ export class Config implements ConfigInterface {
2727
return this._runTrigger;
2828
}
2929

30-
set runTrigger(value: Trigger) {
30+
updateRunTrigger(value: Trigger): PromiseLike<void> {
3131
this._runTrigger = value;
32-
workspace
32+
return workspace
3333
.getConfiguration(Config._namespace)
3434
.update('lint.run', value);
3535
}
@@ -38,9 +38,9 @@ export class Config implements ConfigInterface {
3838
return this._enable;
3939
}
4040

41-
set enable(value: boolean) {
41+
updateEnable(value: boolean): PromiseLike<void> {
4242
this._enable = value;
43-
workspace
43+
return workspace
4444
.getConfiguration(Config._namespace)
4545
.update('enable', value);
4646
}
@@ -49,9 +49,9 @@ export class Config implements ConfigInterface {
4949
return this._trace;
5050
}
5151

52-
set trace(value: TraceLevel) {
52+
updateTrace(value: TraceLevel): PromiseLike<void> {
5353
this._trace = value;
54-
workspace
54+
return workspace
5555
.getConfiguration(Config._namespace)
5656
.update('trace.server', value);
5757
}
@@ -60,9 +60,9 @@ export class Config implements ConfigInterface {
6060
return this._configPath;
6161
}
6262

63-
set configPath(value: string) {
63+
updateConfigPath(value: string): PromiseLike<void> {
6464
this._configPath = value;
65-
workspace
65+
return workspace
6666
.getConfiguration(Config._namespace)
6767
.update('configPath', value);
6868
}
@@ -71,9 +71,9 @@ export class Config implements ConfigInterface {
7171
return this._binPath;
7272
}
7373

74-
set binPath(value: string | undefined) {
74+
updateBinPath(value: string | undefined): PromiseLike<void> {
7575
this._binPath = value;
76-
workspace
76+
return workspace
7777
.getConfiguration(Config._namespace)
7878
.update('path.server', value);
7979
}

editors/vscode/client/config.spec.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,15 @@
11
import { strictEqual } from 'assert';
2+
import { workspace } from 'vscode';
23
import { Config } from './Config.js';
34

45
suite('Config', () => {
6+
setup(async () => {
7+
const wsConfig = workspace.getConfiguration('oxc');
8+
const keys = ['lint.run', 'enable', 'trace.server', 'configPath', 'path.server'];
9+
10+
await Promise.all(keys.map(key => wsConfig.update(key, undefined)));
11+
});
12+
513
test('default values on initialization', () => {
614
const config = new Config();
715

@@ -11,4 +19,24 @@ suite('Config', () => {
1119
strictEqual(config.configPath, '.eslintrc');
1220
strictEqual(config.binPath, '');
1321
});
22+
23+
test('updating values updates the workspace configuration', async () => {
24+
const config = new Config();
25+
26+
await Promise.all([
27+
config.updateRunTrigger('onSave'),
28+
config.updateEnable(false),
29+
config.updateTrace('messages'),
30+
config.updateConfigPath('./somewhere'),
31+
config.updateBinPath('./binary'),
32+
]);
33+
34+
const wsConfig = workspace.getConfiguration('oxc');
35+
36+
strictEqual(wsConfig.get('lint.run'), 'onSave');
37+
strictEqual(wsConfig.get('enable'), false);
38+
strictEqual(wsConfig.get('trace.server'), 'messages');
39+
strictEqual(wsConfig.get('configPath'), './somewhere');
40+
strictEqual(wsConfig.get('path.server'), './binary');
41+
});
1442
});

editors/vscode/client/extension.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ export async function activate(context: ExtensionContext) {
5858
const toggleEnable = commands.registerCommand(
5959
OxcCommands.ToggleEnable,
6060
() => {
61-
configService.config.enable = !configService.config.enable;
61+
configService.config.updateEnable(!configService.config.enable);
6262
},
6363
);
6464

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
**
2+
!.gitignore

0 commit comments

Comments
 (0)