Skip to content

Commit 610a623

Browse files
committed
Fix download tests
1 parent 37c9414 commit 610a623

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

extensions/ql-vscode/test/vscode-tests/cli-integration/remote-queries/variant-analysis-manager.test.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import * as ghApiClient from "../../../../src/remote-queries/gh-api/gh-api-clien
2121
import * as ghActionsApiClient from "../../../../src/remote-queries/gh-api/gh-actions-api-client";
2222
import * as fs from "fs-extra";
2323
import { join } from "path";
24+
import { Readable } from "stream";
2425
import { Response } from "node-fetch";
2526
import * as fetchModule from "node-fetch";
2627

@@ -389,10 +390,10 @@ describe("Variant Analysis Manager", () => {
389390
__dirname,
390391
"../data/variant-analysis-results.zip",
391392
);
392-
const arrayBuffer = fs.readFileSync(sourceFilePath).buffer;
393-
getVariantAnalysisRepoResultStub.mockResolvedValue(
394-
new Response(arrayBuffer),
395-
);
393+
const fileContents = fs.readFileSync(sourceFilePath);
394+
const response = new Response(Readable.from(fileContents));
395+
response.size = fileContents.length;
396+
getVariantAnalysisRepoResultStub.mockResolvedValue(response);
396397
});
397398

398399
it("should return early if variant analysis is cancelled", async () => {

extensions/ql-vscode/test/vscode-tests/cli-integration/remote-queries/variant-analysis-results-manager.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { CodeQLExtensionInterface } from "../../../../src/extension";
33
import { extLogger } from "../../../../src/common";
44
import * as fs from "fs-extra";
55
import { join, resolve } from "path";
6+
import { Readable } from "stream";
67
import { Response, RequestInfo, RequestInit } from "node-fetch";
78
import * as fetchModule from "node-fetch";
89

@@ -94,24 +95,23 @@ describe(VariantAnalysisResultsManager.name, () => {
9495
});
9596

9697
describe("when the artifact_url is present", () => {
97-
let arrayBuffer: ArrayBuffer;
98-
9998
let getVariantAnalysisRepoResultStub: jest.SpiedFunction<
10099
typeof fetchModule.default
101100
>;
101+
let fileContents: Buffer;
102102

103103
beforeEach(async () => {
104104
const sourceFilePath = join(
105105
__dirname,
106106
"../data/variant-analysis-results.zip",
107107
);
108-
arrayBuffer = fs.readFileSync(sourceFilePath).buffer;
108+
fileContents = fs.readFileSync(sourceFilePath);
109109

110110
getVariantAnalysisRepoResultStub = jest
111111
.spyOn(fetchModule, "default")
112112
.mockImplementation((url: RequestInfo, _init?: RequestInit) => {
113113
if (url === dummyRepoTask.artifactUrl) {
114-
return Promise.resolve(new Response(arrayBuffer));
114+
return Promise.resolve(new Response(Readable.from(fileContents)));
115115
}
116116
return Promise.reject(new Error("Unexpected artifact URL"));
117117
});

0 commit comments

Comments
 (0)