fx115: Restore test runner
This commit is contained in:
parent
d026d9684f
commit
33db3c28fc
4 changed files with 23 additions and 29 deletions
|
@ -1,7 +1,3 @@
|
||||||
content zotero-unit test/content/
|
content zotero-unit test/content/
|
||||||
resource zotero-unit test/resource/
|
resource zotero-unit test/resource/
|
||||||
resource zotero-unit-tests test/tests/
|
resource zotero-unit-tests test/tests/
|
||||||
|
|
||||||
component {b8570031-be5e-46e8-9785-38cd50a5d911} test/components/zotero-unit.js
|
|
||||||
contract @zotero.org/zotero/tests-clh;1 {b8570031-be5e-46e8-9785-38cd50a5d911}
|
|
||||||
category command-line-handler m-zotero-unit @zotero.org/zotero/tests-clh;1
|
|
||||||
|
|
|
@ -5,14 +5,13 @@
|
||||||
<title>Zotero Unit Tests</title>
|
<title>Zotero Unit Tests</title>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<script src="chrome://zotero/content/include.js"></script>
|
|
||||||
<script src="resource://zotero-unit/chai.js"></script>
|
<script src="resource://zotero-unit/chai.js"></script>
|
||||||
<script src="resource://zotero-unit/chai-as-promised.js"></script>
|
<script src="resource://zotero-unit/chai-as-promised.js"></script>
|
||||||
<script src="resource://zotero-unit/mocha.js"></script>
|
<script src="resource://zotero-unit/mocha.js"></script>
|
||||||
<script src="resource://zotero-unit/co-mocha.js"></script>
|
<script src="resource://zotero-unit/co-mocha.js"></script>
|
||||||
<script src="resource://zotero-unit/sinon.js"></script>
|
<script src="resource://zotero-unit/sinon.js"></script>
|
||||||
<script src="resource://zotero-unit/pako_inflate.js"></script>
|
<script src="resource://zotero-unit/pako_inflate.js"></script>
|
||||||
<script src="support.js" type="application/javascript"></script>
|
<script src="support.js"></script>
|
||||||
<script src="runtests.js" type="application/javascript"></script>
|
<script src="runtests.js"></script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
|
@ -1,13 +1,11 @@
|
||||||
Components.utils.import("resource://gre/modules/Services.jsm");
|
Components.utils.import("resource://gre/modules/Services.jsm");
|
||||||
Services.scriptloader.loadSubScript("resource://zotero/polyfill.js");
|
Services.scriptloader.loadSubScript("resource://zotero/polyfill.js");
|
||||||
Components.utils.import("resource://gre/modules/osfile.jsm");
|
|
||||||
var EventUtils = Components.utils.import("resource://zotero-unit/EventUtils.jsm");
|
var EventUtils = Components.utils.import("resource://zotero-unit/EventUtils.jsm");
|
||||||
|
var { FileUtils } = ChromeUtils.importESModule("resource://gre/modules/FileUtils.sys.mjs");
|
||||||
|
|
||||||
var ZoteroUnit = Components.classes["@zotero.org/zotero/tests-clh;1"].
|
var { Zotero } = ChromeUtils.importESModule("chrome://zotero/content/zotero.mjs");
|
||||||
getService(Components.interfaces.nsISupports).
|
var { TestOptions } = ChromeUtils.importESModule("chrome://zotero/content/modules/commandLineOptions.mjs");
|
||||||
wrappedJSObject;
|
var { OS } = ChromeUtils.importESModule("chrome://zotero/content/osfile.mjs");
|
||||||
|
|
||||||
var dump = ZoteroUnit.dump;
|
|
||||||
|
|
||||||
// Mocha HTML reporter doesn't show deepEqual diffs, so we change this.
|
// Mocha HTML reporter doesn't show deepEqual diffs, so we change this.
|
||||||
chai.config.truncateThreshold = 0
|
chai.config.truncateThreshold = 0
|
||||||
|
@ -17,7 +15,7 @@ function quit(failed) {
|
||||||
if(!failed) {
|
if(!failed) {
|
||||||
OS.File.writeAtomic(OS.Path.join(OS.Constants.Path.profileDir, "success"), new Uint8Array(0));
|
OS.File.writeAtomic(OS.Path.join(OS.Constants.Path.profileDir, "success"), new Uint8Array(0));
|
||||||
}
|
}
|
||||||
if(!ZoteroUnit.noquit) {
|
if(!TestOptions.noquit) {
|
||||||
setTimeout(function () {
|
setTimeout(function () {
|
||||||
Components.classes['@mozilla.org/toolkit/app-startup;1']
|
Components.classes['@mozilla.org/toolkit/app-startup;1']
|
||||||
.getService(Components.interfaces.nsIAppStartup)
|
.getService(Components.interfaces.nsIAppStartup)
|
||||||
|
@ -26,7 +24,7 @@ function quit(failed) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ZoteroUnit.makeTestData) {
|
if (TestOptions.makeTestData) {
|
||||||
let dataPath = getTestDataDirectory().path;
|
let dataPath = getTestDataDirectory().path;
|
||||||
|
|
||||||
Zotero.Prefs.set("export.citePaperJournalArticleURL", true);
|
Zotero.Prefs.set("export.citePaperJournalArticleURL", true);
|
||||||
|
@ -149,7 +147,7 @@ function Reporter(runner) {
|
||||||
+ indentStr + " " + err.message + " at\n"
|
+ indentStr + " " + err.message + " at\n"
|
||||||
+ err.stack.replace(/^/gm, indentStr + " ").trim() + "\n\n");
|
+ err.stack.replace(/^/gm, indentStr + " ").trim() + "\n\n");
|
||||||
|
|
||||||
if (ZoteroUnit.bail) {
|
if (TestOptions.bail) {
|
||||||
aborted = true;
|
aborted = true;
|
||||||
runner.abort();
|
runner.abort();
|
||||||
}
|
}
|
||||||
|
@ -166,8 +164,8 @@ function Reporter(runner) {
|
||||||
mocha.setup({
|
mocha.setup({
|
||||||
ui: "bdd",
|
ui: "bdd",
|
||||||
reporter: Reporter,
|
reporter: Reporter,
|
||||||
timeout: ZoteroUnit.timeout || 10000,
|
timeout: TestOptions.timeout || 10000,
|
||||||
grep: ZoteroUnit.grep
|
grep: TestOptions.grep
|
||||||
});
|
});
|
||||||
|
|
||||||
coMocha(Mocha);
|
coMocha(Mocha);
|
||||||
|
@ -176,10 +174,10 @@ before(function () {
|
||||||
// Store all prefs set in runtests.sh
|
// Store all prefs set in runtests.sh
|
||||||
Components.utils.import("resource://zotero/config.js");
|
Components.utils.import("resource://zotero/config.js");
|
||||||
var prefBranch = Services.prefs.getBranch(ZOTERO_CONFIG.PREF_BRANCH);
|
var prefBranch = Services.prefs.getBranch(ZOTERO_CONFIG.PREF_BRANCH);
|
||||||
ZoteroUnit.customPrefs = {};
|
TestOptions.customPrefs = {};
|
||||||
prefBranch.getChildList("", {})
|
prefBranch.getChildList("", {})
|
||||||
.filter(key => prefBranch.prefHasUserValue(key))
|
.filter(key => prefBranch.prefHasUserValue(key))
|
||||||
.forEach(key => ZoteroUnit.customPrefs[key] = Zotero.Prefs.get(key));
|
.forEach(key => TestOptions.customPrefs[key] = Zotero.Prefs.get(key));
|
||||||
});
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -189,10 +187,10 @@ function resetPrefs() {
|
||||||
Components.utils.import("resource://zotero/config.js");
|
Components.utils.import("resource://zotero/config.js");
|
||||||
var prefBranch = Services.prefs.getBranch(ZOTERO_CONFIG.PREF_BRANCH);
|
var prefBranch = Services.prefs.getBranch(ZOTERO_CONFIG.PREF_BRANCH);
|
||||||
prefBranch.getChildList("", {}).forEach(key => {
|
prefBranch.getChildList("", {}).forEach(key => {
|
||||||
var origVal = ZoteroUnit.customPrefs[key];
|
var origVal = TestOptions.customPrefs[key];
|
||||||
if (origVal !== undefined) {
|
if (origVal !== undefined) {
|
||||||
if (origVal != Zotero.Prefs.get(key)) {
|
if (origVal != Zotero.Prefs.get(key)) {
|
||||||
Zotero.Prefs.set(key, ZoteroUnit.customPrefs[key]);
|
Zotero.Prefs.set(key, TestOptions.customPrefs[key]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (prefBranch.prefHasUserValue(key)) {
|
else if (prefBranch.prefHasUserValue(key)) {
|
||||||
|
@ -210,8 +208,8 @@ var assert = chai.assert,
|
||||||
expect = chai.expect;
|
expect = chai.expect;
|
||||||
|
|
||||||
// Set up tests to run
|
// Set up tests to run
|
||||||
var run = ZoteroUnit.runTests;
|
var run = TestOptions.runTests;
|
||||||
if (run && ZoteroUnit.tests) {
|
if (run && TestOptions.tests) {
|
||||||
function getTestFilename(test) {
|
function getTestFilename(test) {
|
||||||
// Remove any directory prefixes e.g. tests/fooTest.js, test/tests/fooTest.js
|
// Remove any directory prefixes e.g. tests/fooTest.js, test/tests/fooTest.js
|
||||||
test = test.split(/[/\\]/).pop();
|
test = test.split(/[/\\]/).pop();
|
||||||
|
@ -223,11 +221,11 @@ if (run && ZoteroUnit.tests) {
|
||||||
|
|
||||||
var testDirectory = getTestDataDirectory().parent,
|
var testDirectory = getTestDataDirectory().parent,
|
||||||
testFiles = [];
|
testFiles = [];
|
||||||
if(ZoteroUnit.tests == "all") {
|
if(TestOptions.tests == "all") {
|
||||||
var enumerator = testDirectory.directoryEntries;
|
var enumerator = testDirectory.directoryEntries;
|
||||||
let startFile = ZoteroUnit.startAt ? getTestFilename(ZoteroUnit.startAt) : false;
|
let startFile = TestOptions.startAt ? getTestFilename(TestOptions.startAt) : false;
|
||||||
let started = !startFile;
|
let started = !startFile;
|
||||||
let stopFile = ZoteroUnit.stopAt ? getTestFilename(ZoteroUnit.stopAt) : false;
|
let stopFile = TestOptions.stopAt ? getTestFilename(TestOptions.stopAt) : false;
|
||||||
while(enumerator.hasMoreElements()) {
|
while(enumerator.hasMoreElements()) {
|
||||||
var file = enumerator.getNext().QueryInterface(Components.interfaces.nsIFile);
|
var file = enumerator.getNext().QueryInterface(Components.interfaces.nsIFile);
|
||||||
if (file.leafName.endsWith(".js")) {
|
if (file.leafName.endsWith(".js")) {
|
||||||
|
@ -259,7 +257,7 @@ if (run && ZoteroUnit.tests) {
|
||||||
}
|
}
|
||||||
testFiles = testFiles.slice(startPos, stopPos + 1);
|
testFiles = testFiles.slice(startPos, stopPos + 1);
|
||||||
} else {
|
} else {
|
||||||
var specifiedTests = ZoteroUnit.tests.split(",");
|
var specifiedTests = TestOptions.tests.split(",");
|
||||||
for (let test of specifiedTests) {
|
for (let test of specifiedTests) {
|
||||||
let fname = getTestFilename(test);
|
let fname = getTestFilename(test);
|
||||||
let file = testDirectory.clone();
|
let file = testDirectory.clone();
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
var { Zotero } = ChromeUtils.importESModule("chrome://zotero/content/zotero.mjs");
|
||||||
|
|
||||||
chai.use(chaiAsPromised);
|
chai.use(chaiAsPromised);
|
||||||
|
|
||||||
// Useful "constants"
|
// Useful "constants"
|
||||||
|
@ -630,7 +632,6 @@ function getTestDataUrl(path) {
|
||||||
* Returns an absolute path to an empty temporary directory
|
* Returns an absolute path to an empty temporary directory
|
||||||
*/
|
*/
|
||||||
var getTempDirectory = Zotero.Promise.coroutine(function* getTempDirectory() {
|
var getTempDirectory = Zotero.Promise.coroutine(function* getTempDirectory() {
|
||||||
Components.utils.import("resource://gre/modules/osfile.jsm");
|
|
||||||
let path,
|
let path,
|
||||||
attempts = 3,
|
attempts = 3,
|
||||||
zoteroTmpDirPath = Zotero.getTempDirectory().path;
|
zoteroTmpDirPath = Zotero.getTempDirectory().path;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue