Add -g flag to runtests.sh to generate test data
Add functions to generate sample data for various formats * Zotero Web API JSON (Zotero.Item::toJSON) * CiteProc-JS JSON * Export translator JSON * Direct serialization of Zotero.Item fields Add a way to load sample data into DB from JSON Add tests for loading sample data into DB Add tests for automatically generated data This will help us make sure that field mappings and data formats don't change
This commit is contained in:
parent
9d5d8b525a
commit
2ebce91ecf
5 changed files with 593 additions and 24 deletions
|
@ -1,17 +1,17 @@
|
|||
Components.utils.import("resource://gre/modules/FileUtils.jsm");
|
||||
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"].
|
||||
getService(Components.interfaces.nsISupports).
|
||||
wrappedJSObject;
|
||||
getService(Components.interfaces.nsISupports).
|
||||
wrappedJSObject;
|
||||
|
||||
var dump = ZoteroUnit.dump;
|
||||
|
||||
function quit(failed) {
|
||||
// Quit with exit status
|
||||
if(!failed) {
|
||||
OS.File.writeAtomic(FileUtils.getFile("ProfD", ["success"]).path, Uint8Array(0));
|
||||
OS.File.writeAtomic(OS.Path.join(OS.Constants.Path.profileDir, "success"), new Uint8Array(0));
|
||||
}
|
||||
if(!ZoteroUnit.noquit) {
|
||||
Components.classes['@mozilla.org/toolkit/app-startup;1'].
|
||||
|
@ -20,6 +20,72 @@ function quit(failed) {
|
|||
}
|
||||
}
|
||||
|
||||
if (ZoteroUnit.makeTestData) {
|
||||
let dataPath = getTestDataDirectory().path;
|
||||
|
||||
Zotero.Prefs.set("export.citePaperJournalArticleURL", true);
|
||||
|
||||
let dataFiles = [
|
||||
{
|
||||
name: 'allTypesAndFields',
|
||||
func: generateAllTypesAndFieldsData
|
||||
},
|
||||
{
|
||||
name: 'itemJSON',
|
||||
func: generateItemJSONData,
|
||||
args: [null]
|
||||
},
|
||||
{
|
||||
name: 'citeProcJSExport',
|
||||
func: generateCiteProcJSExportData
|
||||
},
|
||||
{
|
||||
name: 'translatorExportLegacy',
|
||||
func: generateTranslatorExportData,
|
||||
args: [true]
|
||||
},
|
||||
{
|
||||
name: 'translatorExport',
|
||||
func: generateTranslatorExportData,
|
||||
args: [false]
|
||||
}
|
||||
];
|
||||
let p = Q.resolve();
|
||||
for (let i=0; i<dataFiles.length; i++) {
|
||||
let first = !i;
|
||||
let params = dataFiles[i];
|
||||
|
||||
p = p.then(function() {
|
||||
// Make sure to not run next loop if previous fails
|
||||
return Q.try(function() {
|
||||
if (!first) dump('\n');
|
||||
dump('Generating data for ' + params.name + '...');
|
||||
|
||||
let filePath = OS.Path.join(dataPath, params.name + '.js');
|
||||
|
||||
return Q.resolve(OS.File.exists(filePath))
|
||||
.then(function(exists) {
|
||||
let currentData;
|
||||
if (exists) {
|
||||
currentData = loadSampleData(params.name);
|
||||
}
|
||||
|
||||
let args = params.args || [];
|
||||
args.push(currentData);
|
||||
let str = stableStringify(params.func.apply(null, args));
|
||||
|
||||
return OS.File.writeAtomic(OS.Path.join(dataPath, params.name + '.js'), str);
|
||||
});
|
||||
})
|
||||
.then(function() { dump("done."); })
|
||||
.catch(function(e) { dump("failed!"); throw e })
|
||||
});
|
||||
}
|
||||
|
||||
p.catch(function(e) { dump('\n'); dump(Zotero.Utilities.varDump(e)) })
|
||||
.finally(function() { quit(false) });
|
||||
}
|
||||
|
||||
function Reporter(runner) {
|
||||
var indents = 0, passed = 0, failed = 0;
|
||||
|
||||
|
@ -71,8 +137,8 @@ var assert = chai.assert,
|
|||
expect = chai.expect;
|
||||
|
||||
// Set up tests to run
|
||||
var run = true;
|
||||
if(ZoteroUnit.tests) {
|
||||
var run = ZoteroUnit.runTests;
|
||||
if(run && ZoteroUnit.tests) {
|
||||
var testDirectory = getTestDataDirectory().parent,
|
||||
testFiles = [];
|
||||
if(ZoteroUnit.tests == "all") {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue