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 ghActionsApiClient from "../../../../src/remote-queries/gh-api/gh-actions-api-client";
import * as fs from "fs-extra"; import * as fs from "fs-extra";
import { join } from "path"; import { join } from "path";
import { Readable } from "stream";
import { Response } from "node-fetch"; import { Response } from "node-fetch";
import * as fetchModule from "node-fetch"; import * as fetchModule from "node-fetch";
@@ -389,10 +390,10 @@ describe("Variant Analysis Manager", () => {
__dirname, __dirname,
"../data/variant-analysis-results.zip", "../data/variant-analysis-results.zip",
); );
const arrayBuffer = fs.readFileSync(sourceFilePath).buffer; const fileContents = fs.readFileSync(sourceFilePath);
getVariantAnalysisRepoResultStub.mockResolvedValue( const response = new Response(Readable.from(fileContents));
new Response(arrayBuffer), response.size = fileContents.length;
); getVariantAnalysisRepoResultStub.mockResolvedValue(response);
}); });
it("should return early if variant analysis is cancelled", async () => { 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 { extLogger } from "../../../../src/common";
import * as fs from "fs-extra"; import * as fs from "fs-extra";
import { join, resolve } from "path"; import { join, resolve } from "path";
import { Readable } from "stream";
import { Response, RequestInfo, RequestInit } from "node-fetch"; import { Response, RequestInfo, RequestInit } from "node-fetch";
import * as fetchModule from "node-fetch"; import * as fetchModule from "node-fetch";
@@ -94,24 +95,23 @@ describe(VariantAnalysisResultsManager.name, () => {
}); });
describe("when the artifact_url is present", () => { describe("when the artifact_url is present", () => {
let arrayBuffer: ArrayBuffer;
let getVariantAnalysisRepoResultStub: jest.SpiedFunction< let getVariantAnalysisRepoResultStub: jest.SpiedFunction<
typeof fetchModule.default typeof fetchModule.default
>; >;
let fileContents: Buffer;
beforeEach(async () => { beforeEach(async () => {
const sourceFilePath = join( const sourceFilePath = join(
__dirname, __dirname,
"../data/variant-analysis-results.zip", "../data/variant-analysis-results.zip",
); );
arrayBuffer = fs.readFileSync(sourceFilePath).buffer; fileContents = fs.readFileSync(sourceFilePath);
getVariantAnalysisRepoResultStub = jest getVariantAnalysisRepoResultStub = jest
.spyOn(fetchModule, "default") .spyOn(fetchModule, "default")
.mockImplementation((url: RequestInfo, _init?: RequestInit) => { .mockImplementation((url: RequestInfo, _init?: RequestInit) => {
if (url === dummyRepoTask.artifactUrl) { 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")); return Promise.reject(new Error("Unexpected artifact URL"));
}); });