From 35837935713c32ae3c36c80eb5e92160a3e392c1 Mon Sep 17 00:00:00 2001 From: Simon Kornblith Date: Wed, 11 Mar 2015 13:18:11 -0400 Subject: [PATCH] Wait for bundled file updates to complete before running tests --- chrome/content/zotero/xpcom/schema.js | 10 ++++++++-- test/content/runtests.js | 4 +++- test/content/support.js | 2 ++ test/tests/lookup.js | 1 - test/tests/recognizePDF.js | 1 - test/tests/support.js | 1 + 6 files changed, 14 insertions(+), 5 deletions(-) diff --git a/chrome/content/zotero/xpcom/schema.js b/chrome/content/zotero/xpcom/schema.js index 62d0b61536..b46a0bfc09 100644 --- a/chrome/content/zotero/xpcom/schema.js +++ b/chrome/content/zotero/xpcom/schema.js @@ -27,6 +27,9 @@ Zotero.Schema = new function(){ this.skipDefaultData = false; this.dbInitialized = false; this.goToChangeLog = false; + + var _schemaUpdateDeferred = Q.defer(); + this.schemaUpdatePromise = _schemaUpdateDeferred.promise; var _dbVersions = []; var _schemaVersions = []; @@ -121,7 +124,9 @@ Zotero.Schema = new function(){ // 'user' is for pre-1.0b2 'user' table if (!dbVersion && !this.getDBVersion('schema') && !this.getDBVersion('user')){ Zotero.debug('Database does not exist -- creating\n'); - _initializeSchema(); + _initializeSchema().then(function() { + _schemaUpdateDeferred.resolve(true); + }); return true; } @@ -219,6 +224,7 @@ Zotero.Schema = new function(){ Zotero.Schema.updateBundledFiles(null, false, true) .finally(function () { Zotero.UnresponsiveScriptIndicator.enable(); + _schemaUpdateDeferred.resolve(true); }) .done(); }, 5000); @@ -1507,7 +1513,7 @@ Zotero.Schema = new function(){ throw(e); } - Zotero.Schema.updateBundledFiles(null, null, true) + return Zotero.Schema.updateBundledFiles(null, null, true) .catch(function (e) { Zotero.debug(e); Zotero.logError(e); diff --git a/test/content/runtests.js b/test/content/runtests.js index ae4adbd622..1b3d8dc9b7 100644 --- a/test/content/runtests.js +++ b/test/content/runtests.js @@ -108,6 +108,8 @@ if(ZoteroUnit.tests) { if(run) { window.onload = function() { - mocha.run(); + Zotero.Schema.schemaUpdatePromise.then(function() { + mocha.run(); + }).done(); }; } \ No newline at end of file diff --git a/test/content/support.js b/test/content/support.js index 8ff21269c1..6830bcb79a 100644 --- a/test/content/support.js +++ b/test/content/support.js @@ -164,5 +164,7 @@ function resetDB() { var db = Zotero.getZoteroDatabase(); return Zotero.reinit(function() { db.remove(false); + }).then(function() { + return Zotero.Schema.schemaUpdatePromise; }); } \ No newline at end of file diff --git a/test/tests/lookup.js b/test/tests/lookup.js index f49bef5750..829b3260f8 100644 --- a/test/tests/lookup.js +++ b/test/tests/lookup.js @@ -13,7 +13,6 @@ describe("Add Item by Identifier", function() { // make sure they're available before we run the tests) return loadZoteroPane().then(function(w) { win = w; - return Zotero.Schema.updateBundledFiles('translators', null, false); }); }); after(function() { diff --git a/test/tests/recognizePDF.js b/test/tests/recognizePDF.js index efba88d3a5..6704227486 100644 --- a/test/tests/recognizePDF.js +++ b/test/tests/recognizePDF.js @@ -8,7 +8,6 @@ describe("PDF Recognition", function() { // translators return Q.all([loadZoteroPane().then(function(w) { win = w; - return Zotero.Schema.updateBundledFiles('translators', null, false); }), installPDFTools()]); }); afterEach(function() { diff --git a/test/tests/support.js b/test/tests/support.js index f8c91f6f3c..cdcd4e950f 100644 --- a/test/tests/support.js +++ b/test/tests/support.js @@ -1,6 +1,7 @@ describe("Support Functions for Unit Testing", function() { describe("resetDB", function() { it("should restore the DB to factory settings", function() { + this.timeout(10000); var quickstart = Zotero.Items.erase(1); assert.equal(Zotero.Items.get(1), false); return resetDB().then(function() {