Massively speed up tests
- Make a copy of the database after first initialization that can be swapped in when reinitializing in resetDB() - Avoid unnecessary one-second delay on every reset Probably more that can be done, but this should take minutes off the test runs
This commit is contained in:
parent
88280641ac
commit
f80ba89971
4 changed files with 20 additions and 15 deletions
|
@ -331,7 +331,7 @@ Zotero.Schema = new function(){
|
||||||
}, 250);
|
}, 250);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}.bind(this), 1000);
|
}.bind(this), Zotero.isStandalone ? 1000 : 0);
|
||||||
});
|
});
|
||||||
|
|
||||||
return updated;
|
return updated;
|
||||||
|
|
|
@ -276,13 +276,15 @@ if (run && ZoteroUnit.tests) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if(run) {
|
if(run) {
|
||||||
window.onload = function() {
|
window.onload = async function () {
|
||||||
Zotero.spawn(function* () {
|
await Zotero.Schema.schemaUpdatePromise;
|
||||||
yield Zotero.Schema.schemaUpdatePromise;
|
|
||||||
|
// Make a copy of the database that can be used in resetDB()
|
||||||
initPDFToolsPath();
|
var dbFile = Zotero.DataDirectory.getDatabase();
|
||||||
|
await OS.File.copy(dbFile, dbFile + '-test-template');
|
||||||
return mocha.run();
|
|
||||||
})
|
initPDFToolsPath();
|
||||||
|
|
||||||
|
return mocha.run();
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -623,10 +623,11 @@ async function resetDB(options = {}) {
|
||||||
}
|
}
|
||||||
var db = Zotero.DataDirectory.getDatabase();
|
var db = Zotero.DataDirectory.getDatabase();
|
||||||
await Zotero.reinit(
|
await Zotero.reinit(
|
||||||
Zotero.Promise.coroutine(function* () {
|
async function () {
|
||||||
yield OS.File.remove(db);
|
// Swap in the initial copy we made of the DB
|
||||||
|
await OS.File.copy(db + '-test-template', db);
|
||||||
_defaultGroup = null;
|
_defaultGroup = null;
|
||||||
}),
|
},
|
||||||
false,
|
false,
|
||||||
options
|
options
|
||||||
);
|
);
|
||||||
|
|
|
@ -1,10 +1,12 @@
|
||||||
describe("Support Functions for Unit Testing", function() {
|
describe("Support Functions for Unit Testing", function() {
|
||||||
describe("resetDB", function() {
|
describe("resetDB", function() {
|
||||||
it("should restore the DB to factory settings", function* () {
|
it("should restore the DB to factory settings", async function () {
|
||||||
yield resetDB({
|
await Zotero.DB.queryAsync("CREATE TABLE testTable (foo INTEGER PRIMARY KEY)");
|
||||||
|
assert.isTrue(await Zotero.DB.tableExists('testTable'));
|
||||||
|
await resetDB({
|
||||||
thisArg: this
|
thisArg: this
|
||||||
});
|
});
|
||||||
assert.equal((yield Zotero.DB.valueQueryAsync("SELECT COUNT(*) FROM items")), 0);
|
assert.isFalse(await Zotero.DB.tableExists('testTable'));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
describe("loadSampleData", function() {
|
describe("loadSampleData", function() {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue