Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 26 additions & 1 deletion extensions/ql-vscode/src/mocks/mock-gh-api-server.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,28 @@
import { MockGitHubApiConfigListener } from '../config';

/**
* Enables mocking of the GitHub API server via HTTP interception, using msw.
*/
export class MockGitHubApiServer {
private isListening: boolean;
private config: MockGitHubApiConfigListener;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this be readonly and instantiated inline?

Suggested change
private config: MockGitHubApiConfigListener;
private readonly config = new MockGitHubApiConfigListener();

I'm also happy to leave it like this.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not a huge fan of adding logic outside of the constructor (but that runs as part of the constructor).


constructor() {
this.isListening = false;
this.config = new MockGitHubApiConfigListener();
this.setupConfigListener();
}

public startServer(): void {
this.isListening = true;

// TODO: Enable HTTP interception.
}

public stopServer(): void {
// Disable HTTP interception.
this.isListening = false;

// TODO: Disable HTTP interception.
}

public loadScenario(): void {
Expand All @@ -21,4 +36,14 @@ export class MockGitHubApiServer {
public recordScenario(): void {
// TODO: Implement logic to record a new scenario to a directory.
}

private setupConfigListener(): void {
this.config.onDidChangeConfiguration(() => {
if (this.config.mockServerEnabled && !this.isListening) {
this.startServer();
} else if (!this.config.mockServerEnabled && this.isListening) {
this.stopServer();
}
});
}
}