diff --git a/test/content/runtests.js b/test/content/runtests.js index 7057c1df4..e45f042e9 100644 --- a/test/content/runtests.js +++ b/test/content/runtests.js @@ -196,6 +196,38 @@ mocha.setup({ }; })(); +before(function () { + // Store all prefs set in runtests.sh + var prefBranch = Services.prefs.getBranch(ZOTERO_CONFIG.PREF_BRANCH); + ZoteroUnit.customPrefs = {}; + prefBranch.getChildList("", {}) + .filter(key => prefBranch.prefHasUserValue(key)) + .forEach(key => ZoteroUnit.customPrefs[key] = Zotero.Prefs.get(key)); +}); + +/** + * Clear all prefs, and reset those set in runtests.sh to original values + */ +function resetPrefs() { + var prefBranch = Services.prefs.getBranch(ZOTERO_CONFIG.PREF_BRANCH); + prefBranch.getChildList("", {}).forEach(key => { + var origVal = ZoteroUnit.customPrefs[key]; + if (origVal !== undefined) { + if (origVal != Zotero.Prefs.get(key)) { + Zotero.Prefs.set(key, ZoteroUnit.customPrefs[key]); + } + } + else if (prefBranch.prefHasUserValue(key)) { + Zotero.Prefs.clear(key) + } + }); +} + +afterEach(function () { + resetPrefs(); +}); + + var assert = chai.assert, expect = chai.expect; diff --git a/test/content/support.js b/test/content/support.js index 2bb825aec..0093a3d63 100644 --- a/test/content/support.js +++ b/test/content/support.js @@ -511,7 +511,7 @@ var removeDir = Zotero.Promise.coroutine(function* (dir) { * any that were set at startup */ function resetDB(options = {}) { - Zotero.Prefs.clear('lastViewedFolder') + resetPrefs(); if (options.thisArg) { options.thisArg.timeout(60000);