From 639b4b56239f37578746afdc84699854ce1a7347 Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Sat, 15 Jun 2024 00:39:27 -0400 Subject: [PATCH] Use local HTTP server for Zotero.BrowserDownload test --- test/tests/browserDownloadTest.js | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/test/tests/browserDownloadTest.js b/test/tests/browserDownloadTest.js index 5641b6380f..1ef733b644 100644 --- a/test/tests/browserDownloadTest.js +++ b/test/tests/browserDownloadTest.js @@ -25,13 +25,31 @@ describe("Zotero.BrowserDownload", function () { describe("#downloadPDF()", function () { + var http, port, baseURL; var tmpFile = Zotero.getTempDirectory(); tmpFile.append('browserDownloadTest.pdf'); + before(async function () { + ({ httpd, port } = await startHTTPServer()); + baseURL = `http://localhost:${port}/`; + }); + + after(async function () { + await new Promise(resolve => httpd.stop(resolve)); + }); + it("#downloadPDF() should download a PDF from a JS redirect page", async function () { - this.timeout(65e3); + var dir = getTestDataDirectory().path; + httpd.registerFile( + '/test-pdf-redirect.html', + Zotero.File.pathToFile(PathUtils.join(dir, 'test-pdf-redirect.html')) + ); + httpd.registerFile( + '/test.pdf', + Zotero.File.pathToFile(PathUtils.join(dir, 'test.pdf')) + ); - await Zotero.BrowserDownload.downloadPDF('https://zotero-static.s3.amazonaws.com/test-pdf-redirect.html', tmpFile.path); + await Zotero.BrowserDownload.downloadPDF(`${baseURL}test-pdf-redirect.html`, tmpFile.path); var sample = await Zotero.File.getContentsAsync(tmpFile, null, 1000); assert.equal(Zotero.MIME.sniffForMIMEType(sample), 'application/pdf');