Fix download tests

This commit is contained in:
Koen Vlaswinkel
2023-01-26 12:24:47 +01:00
parent 37c9414dad
commit 610a623bc5
2 changed files with 9 additions and 8 deletions

View File

@@ -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 () => {

View File

@@ -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"));
});