commit 409553da2e10b40a1bab5702b377152e83a487f4
parent 2ebce91ecf96486859d389e343c9e7d2e3aa66d4
Author: Aurimas Vinckevicius <aurimas.dev@gmail.com>
Date: Sun, 26 Apr 2015 01:31:03 -0500
Add getTempDirectory (async) method to support.js
Returns a promise for a path to a new temporary directory
Diffstat:
2 files changed, 24 insertions(+), 1 deletion(-)
diff --git a/test/content/runtests.js b/test/content/runtests.js
@@ -1,5 +1,4 @@
Components.utils.import("resource://gre/modules/osfile.jsm");
-Components.utils.import("resource://zotero/q.js");
var EventUtils = Components.utils.import("resource://zotero-unit/EventUtils.jsm");
var ZoteroUnit = Components.classes["@mozilla.org/commandlinehandler/general-startup;1?type=zotero-unit"].
diff --git a/test/content/support.js b/test/content/support.js
@@ -1,3 +1,5 @@
+Components.utils.import("resource://zotero/q.js");
+
// Useful "constants"
var sqlDateTimeRe = /^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/;
var isoDateTimeRe = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z$/;
@@ -162,6 +164,28 @@ function getTestDataDirectory() {
}
/**
+ * Returns an absolute path to an empty temporary directory
+ * (i.e., test/tests/data)
+ */
+var getTempDirectory = Q.async(function getTempDirectory() {
+ Components.utils.import("resource://gre/modules/osfile.jsm");
+ let path,
+ attempts = 3,
+ zoteroTmpDirPath = Zotero.getTempDirectory().path;
+ while (attempts--) {
+ path = OS.Path.join(zoteroTmpDirPath, Zotero.Utilities.randomString());
+ try {
+ yield OS.File.makeDir(path, { ignoreExisting: false });
+ break;
+ } catch (e) {
+ if (!attempts) throw e; // Throw on last attempt
+ }
+ }
+
+ Q.return(path);
+});
+
+/**
* Resets the Zotero DB and restarts Zotero. Returns a promise resolved
* when this finishes.
*/