Fix download tests
This commit is contained in:
Родитель
37c9414dad
Коммит
610a623bc5
|
@ -21,6 +21,7 @@ import * as ghApiClient from "../../../../src/remote-queries/gh-api/gh-api-clien
|
|||
import * as ghActionsApiClient from "../../../../src/remote-queries/gh-api/gh-actions-api-client";
|
||||
import * as fs from "fs-extra";
|
||||
import { join } from "path";
|
||||
import { Readable } from "stream";
|
||||
import { Response } from "node-fetch";
|
||||
import * as fetchModule from "node-fetch";
|
||||
|
||||
|
@ -389,10 +390,10 @@ describe("Variant Analysis Manager", () => {
|
|||
__dirname,
|
||||
"../data/variant-analysis-results.zip",
|
||||
);
|
||||
const arrayBuffer = fs.readFileSync(sourceFilePath).buffer;
|
||||
getVariantAnalysisRepoResultStub.mockResolvedValue(
|
||||
new Response(arrayBuffer),
|
||||
);
|
||||
const fileContents = fs.readFileSync(sourceFilePath);
|
||||
const response = new Response(Readable.from(fileContents));
|
||||
response.size = fileContents.length;
|
||||
getVariantAnalysisRepoResultStub.mockResolvedValue(response);
|
||||
});
|
||||
|
||||
it("should return early if variant analysis is cancelled", async () => {
|
||||
|
|
|
@ -3,6 +3,7 @@ import { CodeQLExtensionInterface } from "../../../../src/extension";
|
|||
import { extLogger } from "../../../../src/common";
|
||||
import * as fs from "fs-extra";
|
||||
import { join, resolve } from "path";
|
||||
import { Readable } from "stream";
|
||||
import { Response, RequestInfo, RequestInit } from "node-fetch";
|
||||
import * as fetchModule from "node-fetch";
|
||||
|
||||
|
@ -94,24 +95,23 @@ describe(VariantAnalysisResultsManager.name, () => {
|
|||
});
|
||||
|
||||
describe("when the artifact_url is present", () => {
|
||||
let arrayBuffer: ArrayBuffer;
|
||||
|
||||
let getVariantAnalysisRepoResultStub: jest.SpiedFunction<
|
||||
typeof fetchModule.default
|
||||
>;
|
||||
let fileContents: Buffer;
|
||||
|
||||
beforeEach(async () => {
|
||||
const sourceFilePath = join(
|
||||
__dirname,
|
||||
"../data/variant-analysis-results.zip",
|
||||
);
|
||||
arrayBuffer = fs.readFileSync(sourceFilePath).buffer;
|
||||
fileContents = fs.readFileSync(sourceFilePath);
|
||||
|
||||
getVariantAnalysisRepoResultStub = jest
|
||||
.spyOn(fetchModule, "default")
|
||||
.mockImplementation((url: RequestInfo, _init?: RequestInit) => {
|
||||
if (url === dummyRepoTask.artifactUrl) {
|
||||
return Promise.resolve(new Response(arrayBuffer));
|
||||
return Promise.resolve(new Response(Readable.from(fileContents)));
|
||||
}
|
||||
return Promise.reject(new Error("Unexpected artifact URL"));
|
||||
});
|
||||
|
|
Загрузка…
Ссылка в новой задаче