Skip to content

Commit 6a78560

Browse files
authored
Add mock GitHub API config listener (#1632)
1 parent fe31730 commit 6a78560

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed

extensions/ql-vscode/src/mocks/mock-gh-api-server.ts

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,28 @@
1+
import { MockGitHubApiConfigListener } from '../config';
2+
13
/**
24
* Enables mocking of the GitHub API server via HTTP interception, using msw.
35
*/
46
export class MockGitHubApiServer {
7+
private isListening: boolean;
8+
private config: MockGitHubApiConfigListener;
9+
10+
constructor() {
11+
this.isListening = false;
12+
this.config = new MockGitHubApiConfigListener();
13+
this.setupConfigListener();
14+
}
15+
516
public startServer(): void {
17+
this.isListening = true;
18+
619
// TODO: Enable HTTP interception.
720
}
821

922
public stopServer(): void {
10-
// Disable HTTP interception.
23+
this.isListening = false;
24+
25+
// TODO: Disable HTTP interception.
1126
}
1227

1328
public loadScenario(): void {
@@ -21,4 +36,14 @@ export class MockGitHubApiServer {
2136
public recordScenario(): void {
2237
// TODO: Implement logic to record a new scenario to a directory.
2338
}
39+
40+
private setupConfigListener(): void {
41+
this.config.onDidChangeConfiguration(() => {
42+
if (this.config.mockServerEnabled && !this.isListening) {
43+
this.startServer();
44+
} else if (!this.config.mockServerEnabled && this.isListening) {
45+
this.stopServer();
46+
}
47+
});
48+
}
2449
}

0 commit comments

Comments
 (0)