Skip to content

Commit 0efbbbf

Browse files
committed
Add test for download progress reporting
1 parent 610a623 commit 0efbbbf

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

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

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,47 @@ describe(VariantAnalysisResultsManager.name, () => {
154154
).toBe(true);
155155
});
156156

157+
it("should report download progress", async () => {
158+
// This generates a "fake" stream which "downloads" the file in 5 chunks,
159+
// rather than in 1 chunk. This is used for testing that we actually get
160+
// multiple progress reports.
161+
async function* generateInParts() {
162+
const partLength = fileContents.length / 5;
163+
for (let i = 0; i < 5; i++) {
164+
yield fileContents.slice(i * partLength, (i + 1) * partLength);
165+
}
166+
}
167+
168+
getVariantAnalysisRepoResultStub.mockImplementation(
169+
(url: RequestInfo, _init?: RequestInit) => {
170+
if (url === dummyRepoTask.artifactUrl) {
171+
const response = new Response(Readable.from(generateInParts()));
172+
response.size = fileContents.length;
173+
return Promise.resolve(response);
174+
}
175+
return Promise.reject(new Error("Unexpected artifact URL"));
176+
},
177+
);
178+
179+
const downloadPercentageChanged = jest
180+
.fn()
181+
.mockResolvedValue(undefined);
182+
183+
await variantAnalysisResultsManager.download(
184+
variantAnalysisId,
185+
dummyRepoTask,
186+
variantAnalysisStoragePath,
187+
downloadPercentageChanged,
188+
);
189+
190+
expect(downloadPercentageChanged).toHaveBeenCalledTimes(5);
191+
expect(downloadPercentageChanged).toHaveBeenCalledWith(20);
192+
expect(downloadPercentageChanged).toHaveBeenCalledWith(40);
193+
expect(downloadPercentageChanged).toHaveBeenCalledWith(60);
194+
expect(downloadPercentageChanged).toHaveBeenCalledWith(80);
195+
expect(downloadPercentageChanged).toHaveBeenCalledWith(100);
196+
});
197+
157198
describe("isVariantAnalysisRepoDownloaded", () => {
158199
it("should return true once results are downloaded", async () => {
159200
await variantAnalysisResultsManager.download(

0 commit comments

Comments
 (0)