From e31d8bca440afe7e4bcf92f3adad6ff8f3faba0a Mon Sep 17 00:00:00 2001 From: Abe Jellinek Date: Fri, 11 Jul 2025 10:25:06 -0400 Subject: [PATCH] Asyncify/ESMify tests They seem to be succeeding when run individually, but failing when run as a whole. Not sure why yet. --- test/components/zotero-unit.js | 3 +- test/content/runtests.js | 15 +- test/content/support.js | 78 +-- test/tests/advancedSearchTest.js | 52 +- test/tests/attachmentsTest.js | 150 +++--- test/tests/citationDialogTest.js | 18 +- test/tests/citeprocRsBridgeTest.js | 2 +- test/tests/collectionTest.js | 204 ++++---- test/tests/collectionTreeTest.js | 312 ++++++------ test/tests/collectionsTest.js | 54 +- test/tests/concurrentCallerTest.js | 70 +-- test/tests/creatorsTest.js | 8 +- test/tests/dataDirectoryTest.js | 106 ++-- test/tests/dataObjectTest.js | 256 +++++----- test/tests/dataObjectUtilitiesTest.js | 14 +- test/tests/dataObjectsTest.js | 30 +- test/tests/dateTest.js | 22 +- test/tests/dbTest.js | 110 ++--- test/tests/duplicatesTest.js | 20 +- test/tests/feedItemTest.js | 152 +++--- test/tests/feedItemsTest.js | 64 +-- test/tests/feedReaderTest.js | 82 ++-- test/tests/feedTest.js | 224 ++++----- test/tests/feedsTest.js | 84 ++-- test/tests/fileInterfaceTest.js | 34 +- test/tests/fileTest.js | 104 ++-- test/tests/folderImportTest.js | 4 +- test/tests/fulltextTest.js | 102 ++-- test/tests/groupTest.js | 36 +- test/tests/groupsTest.js | 14 +- test/tests/httpTest.js | 10 +- test/tests/integrationTest.js | 196 ++++---- test/tests/intlTest.js | 4 +- test/tests/itemFieldsTest.js | 6 +- test/tests/itemPaneTest.js | 66 +-- test/tests/itemTest.js | 650 ++++++++++++------------- test/tests/itemTreeTest.js | 244 +++++----- test/tests/itemsTest.js | 224 ++++----- test/tests/librariesTest.js | 120 ++--- test/tests/libraryTest.js | 250 +++++----- test/tests/lookupTest.js | 36 +- test/tests/mendeleyImportTest.js | 10 +- test/tests/noteeditorTest.js | 6 +- test/tests/notifierTest.js | 25 +- test/tests/openurlTest.js | 4 +- test/tests/preferences_advancedTest.js | 56 +-- test/tests/preferences_syncTest.js | 40 +- test/tests/profileTest.js | 39 +- test/tests/quickCopyTest.js | 10 +- test/tests/recognizeDocumentTest.js | 8 +- test/tests/relatedboxTest.js | 32 +- test/tests/relationsTest.js | 18 +- test/tests/schemaTest.js | 38 +- test/tests/searchTest.js | 170 +++---- test/tests/serverTest.js | 28 +- test/tests/server_connectorTest.js | 90 ++-- test/tests/storageLocalTest.js | 302 ++++++------ test/tests/storageRequestTest.js | 12 +- test/tests/styleTest.js | 24 +- test/tests/supportTest.js | 54 +- test/tests/syncAPIClientTest.js | 6 +- test/tests/syncEngineTest.js | 591 +++++++++++----------- test/tests/syncEventListenersTest.js | 16 +- test/tests/syncFullTextEngineTest.js | 108 ++-- test/tests/syncLocalTest.js | 320 ++++++------ test/tests/syncRunnerTest.js | 190 ++++---- test/tests/syncedSettingsTest.js | 6 +- test/tests/tagSelectorTest.js | 176 +++---- test/tests/tagsTest.js | 38 +- test/tests/tagsboxTest.js | 24 +- test/tests/translateTest.js | 290 +++++------ test/tests/translatorsTest.js | 28 +- test/tests/uriTest.js | 20 +- test/tests/utilities_internalTest.js | 30 +- test/tests/webdavTest.js | 232 ++++----- test/tests/zfsTest.js | 209 ++++---- test/tests/zoteroPaneTest.js | 184 +++---- 77 files changed, 3824 insertions(+), 3840 deletions(-) diff --git a/test/components/zotero-unit.js b/test/components/zotero-unit.js index 75236410ef..bd973e2dc9 100644 --- a/test/components/zotero-unit.js +++ b/test/components/zotero-unit.js @@ -23,7 +23,8 @@ ***** END LICENSE BLOCK ***** */ -Components.utils.import("resource://gre/modules/ComponentUtils.jsm"); + +const { ComponentUtils } = ChromeUtils.importESModule("resource://gre/modules/ComponentUtils.sys.mjs"); function ZoteroUnit() { this.wrappedJSObject = this; diff --git a/test/content/runtests.js b/test/content/runtests.js index 06d61646d8..fb0b7d7921 100644 --- a/test/content/runtests.js +++ b/test/content/runtests.js @@ -1,5 +1,6 @@ var { FileUtils } = ChromeUtils.importESModule("resource://gre/modules/FileUtils.sys.mjs"); +var { ZOTERO_CONFIG } = ChromeUtils.importESModule('resource://zotero/config.mjs'); var { Zotero } = ChromeUtils.importESModule("chrome://zotero/content/zotero.mjs"); var { TestOptions } = ChromeUtils.importESModule("chrome://zotero/content/modules/commandLineOptions.mjs"); var { OS } = ChromeUtils.importESModule("chrome://zotero/content/osfile.mjs"); @@ -51,8 +52,8 @@ if (TestOptions.makeTestData) { args: [false] } ]; - Zotero.Promise.coroutine(function* () { - yield Zotero.initializationPromise; + (async function () { + await Zotero.initializationPromise; for (let i=0; i { var origVal = TestOptions.customPrefs[key]; diff --git a/test/content/support.js b/test/content/support.js index 8b629e2751..745d86d7ae 100644 --- a/test/content/support.js +++ b/test/content/support.js @@ -192,7 +192,7 @@ function waitForWindow(uri, callback) { * @return {Promise} */ function waitForDialog(onOpen, button='accept', url) { - return waitForWindow(url || "chrome://global/content/commonDialog.xhtml", Zotero.Promise.method(function (win) { + return waitForWindow(url || "chrome://global/content/commonDialog.xhtml", function (win) { var dialog = win.document.querySelector('dialog'); var failure = false; if (onOpen) { @@ -236,7 +236,7 @@ function waitForDialog(onOpen, button='accept', url) { throw failure; } } - })) + }); } async function select(win, object) { @@ -278,16 +278,16 @@ async function selectTrash(win, libraryID = Zotero.Libraries.userLibraryID) { await waitForItemsLoad(win); } -var waitForItemsLoad = Zotero.Promise.coroutine(function* (win, collectionRowToSelect) { +var waitForItemsLoad = async function (win, collectionRowToSelect) { var zp = win.ZoteroPane; var cv = zp.collectionsView; - yield cv.waitForLoad(); + await cv.waitForLoad(); if (collectionRowToSelect !== undefined) { - yield cv.selectWait(collectionRowToSelect); + await cv.selectWait(collectionRowToSelect); } - yield zp.itemsView.waitForLoad(); -}); + await zp.itemsView.waitForLoad(); +}; /** * Return a promise that resolves once the tag selector has updated @@ -303,7 +303,7 @@ var waitForTagSelector = function (win, numUpdates = 1) { if (zp.tagSelectorShown()) { let tagSelector = zp.tagSelector; let componentDidUpdate = tagSelector.componentDidUpdate; - tagSelector.componentDidUpdate = function() { + tagSelector.componentDidUpdate = function () { updates++; if (updates == numUpdates) { deferred.resolve(); @@ -341,7 +341,7 @@ function waitForNotifierEvent(event, type) { if (!event) throw new Error("event not provided"); var deferred = Zotero.Promise.defer(); - var notifierID = Zotero.Notifier.registerObserver({notify:function(ev, type, ids, extraData) { + var notifierID = Zotero.Notifier.registerObserver({notify:function (ev, type, ids, extraData) { if(ev == event) { Zotero.Notifier.unregisterObserver(notifierID); deferred.resolve({ @@ -460,7 +460,7 @@ function gunzip(gzdata) { * Get a default group used by all tests that want one, creating one if necessary */ var _defaultGroup; -var getGroup = Zotero.Promise.method(function () { +var getGroup = function () { // Cleared in resetDB() if (_defaultGroup) { return _defaultGroup; @@ -468,14 +468,14 @@ var getGroup = Zotero.Promise.method(function () { return _defaultGroup = createGroup({ name: "My Group" }); -}); +}; -var createGroup = Zotero.Promise.coroutine(function* (props = {}) { +var createGroup = async function (props = {}) { // Create a group item requires the current user to be set if (!Zotero.Users.getCurrentUserID()) { - yield Zotero.Users.setCurrentUserID(1); - yield Zotero.Users.setName(1, 'Name'); + await Zotero.Users.setCurrentUserID(1); + await Zotero.Users.setName(1, 'Name'); } var group = new Zotero.Group; @@ -489,11 +489,11 @@ var createGroup = Zotero.Promise.coroutine(function* (props = {}) { group.libraryVersion = props.libraryVersion; } group.archived = props.archived === undefined ? false : props.archived; - yield group.saveTx(); + await group.saveTx(); return group; -}); +}; -var createFeed = Zotero.Promise.coroutine(function* (props = {}) { +var createFeed = async function (props = {}) { var feed = new Zotero.Feed; feed.name = props.name || "Test " + Zotero.Utilities.randomString(); feed.description = props.description || ""; @@ -501,16 +501,16 @@ var createFeed = Zotero.Promise.coroutine(function* (props = {}) { feed.refreshInterval = props.refreshInterval || 12; feed.cleanupReadAfter = props.cleanupReadAfter || 2; feed.cleanupUnreadAfter = props.cleanupUnreadAfter || 30; - yield feed.saveTx(props.saveOptions); + await feed.saveTx(props.saveOptions); return feed; -}); +}; -var clearFeeds = Zotero.Promise.coroutine(function* () { +var clearFeeds = async function () { let feeds = Zotero.Feeds.getAll(); for (let i=0; i