diff --git a/test/chrome.manifest b/test/chrome.manifest index 411d7b98ba..22d60d9591 100644 --- a/test/chrome.manifest +++ b/test/chrome.manifest @@ -1,7 +1,3 @@ content zotero-unit test/content/ resource zotero-unit test/resource/ resource zotero-unit-tests test/tests/ - -component {b8570031-be5e-46e8-9785-38cd50a5d911} test/components/zotero-unit.js -contract @zotero.org/zotero/tests-clh;1 {b8570031-be5e-46e8-9785-38cd50a5d911} -category command-line-handler m-zotero-unit @zotero.org/zotero/tests-clh;1 diff --git a/test/content/runtests.html b/test/content/runtests.html index bde7bd68ff..44dbdfcdd0 100644 --- a/test/content/runtests.html +++ b/test/content/runtests.html @@ -5,14 +5,13 @@ Zotero Unit Tests - - - + + \ No newline at end of file diff --git a/test/content/runtests.js b/test/content/runtests.js index bf711ac499..39ea0b5840 100644 --- a/test/content/runtests.js +++ b/test/content/runtests.js @@ -1,13 +1,11 @@ Components.utils.import("resource://gre/modules/Services.jsm"); Services.scriptloader.loadSubScript("resource://zotero/polyfill.js"); -Components.utils.import("resource://gre/modules/osfile.jsm"); var EventUtils = Components.utils.import("resource://zotero-unit/EventUtils.jsm"); +var { FileUtils } = ChromeUtils.importESModule("resource://gre/modules/FileUtils.sys.mjs"); -var ZoteroUnit = Components.classes["@zotero.org/zotero/tests-clh;1"]. - getService(Components.interfaces.nsISupports). - wrappedJSObject; - -var dump = ZoteroUnit.dump; +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"); // Mocha HTML reporter doesn't show deepEqual diffs, so we change this. chai.config.truncateThreshold = 0 @@ -17,7 +15,7 @@ function quit(failed) { if(!failed) { OS.File.writeAtomic(OS.Path.join(OS.Constants.Path.profileDir, "success"), new Uint8Array(0)); } - if(!ZoteroUnit.noquit) { + if(!TestOptions.noquit) { setTimeout(function () { Components.classes['@mozilla.org/toolkit/app-startup;1'] .getService(Components.interfaces.nsIAppStartup) @@ -26,7 +24,7 @@ function quit(failed) { } } -if (ZoteroUnit.makeTestData) { +if (TestOptions.makeTestData) { let dataPath = getTestDataDirectory().path; Zotero.Prefs.set("export.citePaperJournalArticleURL", true); @@ -149,7 +147,7 @@ function Reporter(runner) { + indentStr + " " + err.message + " at\n" + err.stack.replace(/^/gm, indentStr + " ").trim() + "\n\n"); - if (ZoteroUnit.bail) { + if (TestOptions.bail) { aborted = true; runner.abort(); } @@ -166,8 +164,8 @@ function Reporter(runner) { mocha.setup({ ui: "bdd", reporter: Reporter, - timeout: ZoteroUnit.timeout || 10000, - grep: ZoteroUnit.grep + timeout: TestOptions.timeout || 10000, + grep: TestOptions.grep }); coMocha(Mocha); @@ -176,10 +174,10 @@ before(function () { // Store all prefs set in runtests.sh Components.utils.import("resource://zotero/config.js"); var prefBranch = Services.prefs.getBranch(ZOTERO_CONFIG.PREF_BRANCH); - ZoteroUnit.customPrefs = {}; + TestOptions.customPrefs = {}; prefBranch.getChildList("", {}) .filter(key => prefBranch.prefHasUserValue(key)) - .forEach(key => ZoteroUnit.customPrefs[key] = Zotero.Prefs.get(key)); + .forEach(key => TestOptions.customPrefs[key] = Zotero.Prefs.get(key)); }); /** @@ -189,10 +187,10 @@ function resetPrefs() { Components.utils.import("resource://zotero/config.js"); var prefBranch = Services.prefs.getBranch(ZOTERO_CONFIG.PREF_BRANCH); prefBranch.getChildList("", {}).forEach(key => { - var origVal = ZoteroUnit.customPrefs[key]; + var origVal = TestOptions.customPrefs[key]; if (origVal !== undefined) { if (origVal != Zotero.Prefs.get(key)) { - Zotero.Prefs.set(key, ZoteroUnit.customPrefs[key]); + Zotero.Prefs.set(key, TestOptions.customPrefs[key]); } } else if (prefBranch.prefHasUserValue(key)) { @@ -210,8 +208,8 @@ var assert = chai.assert, expect = chai.expect; // Set up tests to run -var run = ZoteroUnit.runTests; -if (run && ZoteroUnit.tests) { +var run = TestOptions.runTests; +if (run && TestOptions.tests) { function getTestFilename(test) { // Remove any directory prefixes e.g. tests/fooTest.js, test/tests/fooTest.js test = test.split(/[/\\]/).pop(); @@ -223,11 +221,11 @@ if (run && ZoteroUnit.tests) { var testDirectory = getTestDataDirectory().parent, testFiles = []; - if(ZoteroUnit.tests == "all") { + if(TestOptions.tests == "all") { var enumerator = testDirectory.directoryEntries; - let startFile = ZoteroUnit.startAt ? getTestFilename(ZoteroUnit.startAt) : false; + let startFile = TestOptions.startAt ? getTestFilename(TestOptions.startAt) : false; let started = !startFile; - let stopFile = ZoteroUnit.stopAt ? getTestFilename(ZoteroUnit.stopAt) : false; + let stopFile = TestOptions.stopAt ? getTestFilename(TestOptions.stopAt) : false; while(enumerator.hasMoreElements()) { var file = enumerator.getNext().QueryInterface(Components.interfaces.nsIFile); if (file.leafName.endsWith(".js")) { @@ -259,7 +257,7 @@ if (run && ZoteroUnit.tests) { } testFiles = testFiles.slice(startPos, stopPos + 1); } else { - var specifiedTests = ZoteroUnit.tests.split(","); + var specifiedTests = TestOptions.tests.split(","); for (let test of specifiedTests) { let fname = getTestFilename(test); let file = testDirectory.clone(); diff --git a/test/content/support.js b/test/content/support.js index 728cbf1e9b..23bb2afc77 100644 --- a/test/content/support.js +++ b/test/content/support.js @@ -1,3 +1,5 @@ +var { Zotero } = ChromeUtils.importESModule("chrome://zotero/content/zotero.mjs"); + chai.use(chaiAsPromised); // Useful "constants" @@ -630,7 +632,6 @@ function getTestDataUrl(path) { * Returns an absolute path to an empty temporary directory */ var getTempDirectory = Zotero.Promise.coroutine(function* getTempDirectory() { - Components.utils.import("resource://gre/modules/osfile.jsm"); let path, attempts = 3, zoteroTmpDirPath = Zotero.getTempDirectory().path;