diff --git a/test/tests/attachmentsTest.js b/test/tests/attachmentsTest.js index 77d7a9fcab..5e297ec353 100644 --- a/test/tests/attachmentsTest.js +++ b/test/tests/attachmentsTest.js @@ -308,7 +308,7 @@ describe("Zotero.Attachments", function() { describe("#importFromDocument()", function () { Components.utils.import("resource://gre/modules/FileUtils.jsm"); Components.utils.import("resource://zotero-unit/httpd.js"); - var testServerPath, httpd; + var testServerPath, httpd, prefix; var testServerPort = 16213; before(async function () { @@ -317,9 +317,10 @@ describe("Zotero.Attachments", function() { }); beforeEach(function () { + prefix = Zotero.Utilities.randomString(); // Alternate ports to prevent exceptions not catchable in JS - testServerPort += (testServerPort & 1) ? 1 : -1; - testServerPath = 'http://127.0.0.1:' + testServerPort; + // Use random prefix because httpd does not actually stop between tests + testServerPath = 'http://127.0.0.1:' + testServerPort + '/' + prefix; httpd = new HttpServer(); httpd.start(testServerPort); }); @@ -334,7 +335,7 @@ describe("Zotero.Attachments", function() { var item = yield createDataObject('item'); var uri = OS.Path.join(getTestDataDirectory().path, "snapshot"); - httpd.registerDirectory("/", new FileUtils.File(uri)); + httpd.registerDirectory("/" + prefix + "/", new FileUtils.File(uri)); var deferred = Zotero.Promise.defer(); win.addEventListener('pageshow', () => deferred.resolve()); @@ -357,7 +358,7 @@ describe("Zotero.Attachments", function() { var storageDir = Zotero.Attachments.getStorageDirectory(attachment).path; var file = yield attachment.getFilePathAsync(); assert.equal(OS.Path.basename(file), 'index.html'); - assert.isTrue(yield OS.File.exists(OS.Path.join(storageDir, 'images', '2.gif'))); + assert.isTrue(yield OS.File.exists(OS.Path.join(storageDir, 'images', '1.gif'))); // Check attachment html file contents let path = OS.Path.join(storageDir, 'index.html'); @@ -366,7 +367,7 @@ describe("Zotero.Attachments", function() { assert.isTrue(contents.startsWith("