From 5bceebf56cc70e82a3746dc75027d79f81849112 Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Tue, 29 Nov 2016 03:27:44 -0500 Subject: [PATCH] Reset Zotero prefs after each suite and when resetting DB But keep prefs set in runtests.sh --- test/content/runtests.js | 32 ++++++++++++++++++++++++++++++++ test/content/support.js | 2 +- 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/test/content/runtests.js b/test/content/runtests.js index 7057c1df45..e45f042e9f 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 2bb825aecb..0093a3d634 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);