Skip to content

Commit fecefe4

Browse files
authored
Add unit tests to check codeQLDatabasesExperimental.configError value (#1876)
1 parent 727da3d commit fecefe4

3 files changed

Lines changed: 46 additions & 10 deletions

File tree

extensions/ql-vscode/src/databases/config/db-config-store.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -151,11 +151,6 @@ export class DbConfigStore extends DisposableObject {
151151
message: `Failed to read config file: ${this.configPath}`,
152152
},
153153
];
154-
await this.app.executeCommand(
155-
"setContext",
156-
"codeQLDatabasesExperimental.configError",
157-
true,
158-
);
159154
}
160155

161156
if (newConfig) {
@@ -171,6 +166,11 @@ export class DbConfigStore extends DisposableObject {
171166
);
172167
} else {
173168
this.config = undefined;
169+
await this.app.executeCommand(
170+
"setContext",
171+
"codeQLDatabasesExperimental.configError",
172+
true,
173+
);
174174
}
175175
}
176176

@@ -185,11 +185,6 @@ export class DbConfigStore extends DisposableObject {
185185
message: `Failed to read config file: ${this.configPath}`,
186186
},
187187
];
188-
void this.app.executeCommand(
189-
"setContext",
190-
"codeQLDatabasesExperimental.configError",
191-
true,
192-
);
193188
}
194189

195190
if (newConfig) {
@@ -205,6 +200,11 @@ export class DbConfigStore extends DisposableObject {
205200
);
206201
} else {
207202
this.config = undefined;
203+
void this.app.executeCommand(
204+
"setContext",
205+
"codeQLDatabasesExperimental.configError",
206+
true,
207+
);
208208
}
209209
this.onDidChangeConfigEventEmitter.fire();
210210
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{}

extensions/ql-vscode/test/pure-tests/databases/config/db-config-store.test.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,4 +128,39 @@ describe("db config store", () => {
128128

129129
configStore.dispose();
130130
});
131+
132+
it("should set codeQLDatabasesExperimental.configError to true when config has error", async () => {
133+
const testDataStoragePathInvalid = join(__dirname, "data", "invalid");
134+
135+
const app = createMockApp({
136+
extensionPath,
137+
workspaceStoragePath: testDataStoragePathInvalid,
138+
});
139+
const configStore = new DbConfigStore(app);
140+
await configStore.initialize();
141+
142+
expect(app.executeCommand).toBeCalledWith(
143+
"setContext",
144+
"codeQLDatabasesExperimental.configError",
145+
true,
146+
);
147+
configStore.dispose();
148+
});
149+
150+
it("should set codeQLDatabasesExperimental.configError to false when config is valid", async () => {
151+
const app = createMockApp({
152+
extensionPath,
153+
workspaceStoragePath: testDataStoragePath,
154+
});
155+
const configStore = new DbConfigStore(app);
156+
await configStore.initialize();
157+
158+
expect(app.executeCommand).toBeCalledWith(
159+
"setContext",
160+
"codeQLDatabasesExperimental.configError",
161+
false,
162+
);
163+
164+
configStore.dispose();
165+
});
131166
});

0 commit comments

Comments
 (0)