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:
Dan Stillman 2021-06-24 06:07:33 -04:00
parent 88280641ac
commit f80ba89971
4 changed files with 20 additions and 15 deletions

View file

@ -331,7 +331,7 @@ Zotero.Schema = new function(){
}, 250);
}
}
}.bind(this), 1000);
}.bind(this), Zotero.isStandalone ? 1000 : 0);
});
return updated;

View file

@ -276,13 +276,15 @@ if (run && ZoteroUnit.tests) {
}
if(run) {
window.onload = function() {
Zotero.spawn(function* () {
yield Zotero.Schema.schemaUpdatePromise;
initPDFToolsPath();
return mocha.run();
})
window.onload = async function () {
await Zotero.Schema.schemaUpdatePromise;
// Make a copy of the database that can be used in resetDB()
var dbFile = Zotero.DataDirectory.getDatabase();
await OS.File.copy(dbFile, dbFile + '-test-template');
initPDFToolsPath();
return mocha.run();
};
}

View file

@ -623,10 +623,11 @@ async function resetDB(options = {}) {
}
var db = Zotero.DataDirectory.getDatabase();
await Zotero.reinit(
Zotero.Promise.coroutine(function* () {
yield OS.File.remove(db);
async function () {
// Swap in the initial copy we made of the DB
await OS.File.copy(db + '-test-template', db);
_defaultGroup = null;
}),
},
false,
options
);

View file

@ -1,10 +1,12 @@
describe("Support Functions for Unit Testing", function() {
describe("resetDB", function() {
it("should restore the DB to factory settings", function* () {
yield resetDB({
it("should restore the DB to factory settings", async function () {
await Zotero.DB.queryAsync("CREATE TABLE testTable (foo INTEGER PRIMARY KEY)");
assert.isTrue(await Zotero.DB.tableExists('testTable'));
await resetDB({
thisArg: this
});
assert.equal((yield Zotero.DB.valueQueryAsync("SELECT COUNT(*) FROM items")), 0);
assert.isFalse(await Zotero.DB.tableExists('testTable'));
});
});
describe("loadSampleData", function() {