www

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | Submodules | README | LICENSE

commit 5bceebf56cc70e82a3746dc75027d79f81849112
parent 30d0858ebfd2b5d315cd091f553db15841e737fe
Author: Dan Stillman <dstillman@zotero.org>
Date:   Tue, 29 Nov 2016 03:27:44 -0500

Reset Zotero prefs after each suite and when resetting DB

But keep prefs set in runtests.sh

Diffstat:
Mtest/content/runtests.js | 32++++++++++++++++++++++++++++++++
Mtest/content/support.js | 2+-
2 files changed, 33 insertions(+), 1 deletion(-)

diff --git 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 @@ -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);