From 2796e6c80a65d169e4f67fdcc83408796946598f Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Sat, 15 Apr 2023 00:19:27 -0400 Subject: [PATCH] Fix attachment tests that depend on HTML indexing HTML files are now indexed instead of read directly, and indexing was previous skipped in tests and otherwise performed on a delay, so set a flag in the affected tests that triggers inline indexing. --- chrome/content/zotero/xpcom/attachments.js | 10 +++++----- chrome/content/zotero/xpcom/fulltext.js | 18 +++++++++++++++--- test/tests/attachmentsTest.js | 2 ++ 3 files changed, 22 insertions(+), 8 deletions(-) diff --git a/chrome/content/zotero/xpcom/attachments.js b/chrome/content/zotero/xpcom/attachments.js index 1f51fc6cbd..260b33741a 100644 --- a/chrome/content/zotero/xpcom/attachments.js +++ b/chrome/content/zotero/xpcom/attachments.js @@ -719,7 +719,7 @@ Zotero.Attachments = new function(){ await Zotero.Notifier.commit(notifierQueue); } - Zotero.Fulltext.queueItem(attachmentItem); + await Zotero.FullText.queueItem(attachmentItem); return attachmentItem; }; @@ -952,11 +952,11 @@ Zotero.Attachments = new function(){ attachmentItem.attachmentPath = 'storage:' + fileName; var itemID = await attachmentItem.save(saveOptions); - Zotero.Fulltext.queueItem(attachmentItem); - destDir = this.getStorageDirectory(attachmentItem).path; await OS.File.move(tmpDir, destDir); }.bind(this)); + + yield Zotero.FullText.queueItem(attachmentItem); } catch (e) { Zotero.debug(e, 1); @@ -1047,10 +1047,10 @@ Zotero.Attachments = new function(){ saveOptions }); - Zotero.Fulltext.queueItem(attachmentItem); - destDirectory = this.getStorageDirectory(attachmentItem).path; await OS.File.move(tmpDirectory, destDirectory); + + await Zotero.FullText.queueItem(attachmentItem); } catch (e) { Zotero.debug(e, 1); diff --git a/chrome/content/zotero/xpcom/fulltext.js b/chrome/content/zotero/xpcom/fulltext.js index 1be619968d..2550105b24 100644 --- a/chrome/content/zotero/xpcom/fulltext.js +++ b/chrome/content/zotero/xpcom/fulltext.js @@ -549,9 +549,17 @@ Zotero.Fulltext = Zotero.FullText = new function(){ var _nextIndexTime; var _indexDelay = 5000; var _indexInterval = 500; - this.queueItem = function (item) { - // Don't index files in the background during tests - if (Zotero.test) return; + var _indexNextInTest = false; + + this.queueItem = async function (item) { + // Index files immediately during tests that enable it + if (Zotero.test) { + if (_indexNextInTest) { + _indexNextInTest = false; + await this.indexItems([item.id]); + } + return; + } _queue.push(item.id); _nextIndexTime = Date.now() + _indexDelay; @@ -560,6 +568,10 @@ Zotero.Fulltext = Zotero.FullText = new function(){ }, _indexDelay); }; + this.indexNextInTest = function () { + _indexNextInTest = true; + }; + async function _processNextItem() { if (!_queue.length) return; // Another _processNextItem() was scheduled diff --git a/test/tests/attachmentsTest.js b/test/tests/attachmentsTest.js index 8341bee3e9..b291fe2329 100644 --- a/test/tests/attachmentsTest.js +++ b/test/tests/attachmentsTest.js @@ -357,6 +357,7 @@ describe("Zotero.Attachments", function() { httpd.registerDirectory("/" + prefix + "/", new FileUtils.File(uri)); browser = await HiddenBrowser.create(testServerPath + "/index.html"); + Zotero.FullText.indexNextInTest(); var attachment = await Zotero.Attachments.importFromDocument({ browser, parentItemID: item.id @@ -528,6 +529,7 @@ describe("Zotero.Attachments", function() { let snapshotContent = await Zotero.File.getContentsAsync(content); + Zotero.FullText.indexNextInTest(); let attachment = await Zotero.Attachments.importFromSnapshotContent({ parentItemID: item.id, url: "https://example.com/test.html",