Merge pull request #2382 from github/charisk/move-mocks
Move mock GitHub API server files
This commit is contained in:
@@ -133,4 +133,4 @@ Once the scenario has been recorded, it's often useful to remove some of the req
|
||||
|
||||
### Scenario data location
|
||||
|
||||
Pre-recorded scenarios are stored in `./src/mocks/scenarios`. However, it's possible to configure the location, by setting the `codeQL.mockGitHubApiServer.scenariosPath` configuration property in the VS Code user settings.
|
||||
Pre-recorded scenarios are stored in `./src/variant-analysis/github-api/mocks/scenarios`. However, it's possible to configure the location, by setting the `codeQL.mockGitHubApiServer.scenariosPath` configuration property in the VS Code user settings.
|
||||
|
||||
@@ -18,13 +18,16 @@ import { Octokit, type RestEndpointMethodTypes } from "@octokit/rest";
|
||||
import { throttling } from "@octokit/plugin-throttling";
|
||||
|
||||
import { getFiles } from "./util/files";
|
||||
import type { GitHubApiRequest } from "../src/mocks/gh-api-request";
|
||||
import { isGetVariantAnalysisRequest } from "../src/mocks/gh-api-request";
|
||||
import type { GitHubApiRequest } from "../src/variant-analysis/gh-api/mocks/gh-api-request";
|
||||
import { isGetVariantAnalysisRequest } from "../src/variant-analysis/gh-api/mocks/gh-api-request";
|
||||
import { VariantAnalysis } from "../src/variant-analysis/gh-api/variant-analysis";
|
||||
import { RepositoryWithMetadata } from "../src/variant-analysis/gh-api/repository";
|
||||
|
||||
const extensionDirectory = resolve(__dirname, "..");
|
||||
const scenariosDirectory = resolve(extensionDirectory, "src/mocks/scenarios");
|
||||
const scenariosDirectory = resolve(
|
||||
extensionDirectory,
|
||||
"src/variant-analysis/gh-api/mocks/scenarios",
|
||||
);
|
||||
|
||||
// Make sure we don't run into rate limits by automatically waiting until we can
|
||||
// make another request.
|
||||
|
||||
@@ -20,7 +20,10 @@ if (process.argv.length !== 3) {
|
||||
const scenarioName = process.argv[2];
|
||||
|
||||
const extensionDirectory = resolve(__dirname, "..");
|
||||
const scenariosDirectory = resolve(extensionDirectory, "src/mocks/scenarios");
|
||||
const scenariosDirectory = resolve(
|
||||
extensionDirectory,
|
||||
"src/variant-analysis/gh-api/mocks/scenarios",
|
||||
);
|
||||
const scenarioDirectory = resolve(scenariosDirectory, scenarioName);
|
||||
|
||||
async function fixScenarioFiles() {
|
||||
|
||||
@@ -8,13 +8,19 @@ import { getFiles } from "./util/files";
|
||||
|
||||
const extensionDirectory = resolve(__dirname, "..");
|
||||
const rootDirectory = resolve(extensionDirectory, "../..");
|
||||
const scenariosDirectory = resolve(extensionDirectory, "src/mocks/scenarios");
|
||||
const scenariosDirectory = resolve(
|
||||
extensionDirectory,
|
||||
"src/variant-analysis/gh-api/mocks/scenarios",
|
||||
);
|
||||
|
||||
const debug = process.env.RUNNER_DEBUG || process.argv.includes("--debug");
|
||||
|
||||
async function lintScenarios() {
|
||||
const schema = createGenerator({
|
||||
path: resolve(extensionDirectory, "src/mocks/gh-api-request.ts"),
|
||||
path: resolve(
|
||||
extensionDirectory,
|
||||
"src/variant-analysis/gh-api/mocks/gh-api-request.ts",
|
||||
),
|
||||
tsconfig: resolve(extensionDirectory, "tsconfig.json"),
|
||||
type: "GitHubApiRequest",
|
||||
skipTypeCheck: true,
|
||||
|
||||
@@ -102,7 +102,7 @@ import { VariantAnalysisView } from "./variant-analysis/variant-analysis-view";
|
||||
import { VariantAnalysisViewSerializer } from "./variant-analysis/variant-analysis-view-serializer";
|
||||
import { VariantAnalysisManager } from "./variant-analysis/variant-analysis-manager";
|
||||
import { createVariantAnalysisContentProvider } from "./variant-analysis/variant-analysis-content-provider";
|
||||
import { VSCodeMockGitHubApiServer } from "./mocks/vscode-mock-gh-api-server";
|
||||
import { VSCodeMockGitHubApiServer } from "./variant-analysis/gh-api/mocks/vscode-mock-gh-api-server";
|
||||
import { VariantAnalysisResultsManager } from "./variant-analysis/variant-analysis-results-manager";
|
||||
import { ExtensionApp } from "./common/vscode/vscode-app";
|
||||
import { DbModule } from "./databases/db-module";
|
||||
|
||||
@@ -1,8 +1,5 @@
|
||||
import { Repository } from "../variant-analysis/gh-api/repository";
|
||||
import {
|
||||
VariantAnalysis,
|
||||
VariantAnalysisRepoTask,
|
||||
} from "../variant-analysis/gh-api/variant-analysis";
|
||||
import { Repository } from "../repository";
|
||||
import { VariantAnalysis, VariantAnalysisRepoTask } from "../variant-analysis";
|
||||
|
||||
// Types that represent requests/responses from the GitHub API
|
||||
// that we need to mock.
|
||||
@@ -2,11 +2,11 @@ import { join, resolve } from "path";
|
||||
import { pathExists } from "fs-extra";
|
||||
import { setupServer, SetupServer } from "msw/node";
|
||||
|
||||
import { DisposableObject } from "../pure/disposable-object";
|
||||
import { DisposableObject } from "../../../pure/disposable-object";
|
||||
|
||||
import { Recorder } from "./recorder";
|
||||
import { createRequestHandlers } from "./request-handlers";
|
||||
import { getDirectoryNamesInsidePath } from "../pure/files";
|
||||
import { getDirectoryNamesInsidePath } from "../../../pure/files";
|
||||
|
||||
/**
|
||||
* Enables mocking of the GitHub API server via HTTP interception, using msw.
|
||||
@@ -129,9 +129,12 @@ export class MockGitHubApiServer extends DisposableObject {
|
||||
|
||||
public async getDefaultScenariosPath(): Promise<string | undefined> {
|
||||
// This should be the directory where package.json is located
|
||||
const rootDirectory = resolve(__dirname, "../..");
|
||||
const rootDirectory = resolve(__dirname, "../../../..");
|
||||
|
||||
const scenariosPath = resolve(rootDirectory, "src/mocks/scenarios");
|
||||
const scenariosPath = resolve(
|
||||
rootDirectory,
|
||||
"src/variant-analysis/gh-api/mocks/scenarios",
|
||||
);
|
||||
if (await pathExists(scenariosPath)) {
|
||||
return scenariosPath;
|
||||
}
|
||||
@@ -8,7 +8,7 @@ import { IsomorphicResponse } from "@mswjs/interceptors";
|
||||
import { Headers } from "headers-polyfill";
|
||||
import fetch from "node-fetch";
|
||||
|
||||
import { DisposableObject } from "../pure/disposable-object";
|
||||
import { DisposableObject } from "../../../pure/disposable-object";
|
||||
|
||||
import {
|
||||
GetVariantAnalysisRepoResultRequest,
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user