zotero/test/tests/debugTest.js
Dan Stillman cfd0600b77 Add -debug-file flag to write debug output to a file
Terminal output is unreliable on Windows, and a redirect doesn't work
from the Run dialog.
2026-11-04 13:13:01 -05:00

60 lines
1.5 KiB
JavaScript

describe("Zotero.Debug", function () {
describe("#init()", function () {
after(function () {
Zotero.Debug.init();
});
it("should write output to a file", async function () {
let path = PathUtils.join(Zotero.getTempDirectory().path, 'debug.txt');
Zotero.Debug.init(0, path);
Zotero.debug("Debug file test");
assert.include(await Zotero.File.getContentsAsync(path), "Debug file test");
});
});
describe("Debug Output Logging", function () {
var server;
var win;
var doc;
before(async function () {
server = sinon.fakeServer.create();
server.autoRespond = true;
Zotero.HTTP.mock = sinon.FakeXMLHttpRequest;
win = await loadZoteroPane();
doc = win.document;
});
after(function () {
Zotero.HTTP.mock = null;
win.close();
});
it("should log output and submit to server", async function () {
doc.getElementById('debug-output-enable-disable').doCommand();
await createDataObject('item');
doc.getElementById('debug-output-submit').doCommand();
server.respond(function (req) {
if (req.method == "POST") {
req.respond(
200,
{},
'<?xml version="1.0" encoding="UTF-8"?>\n'
+ '<xml><reported reportID="1234567890"/></xml>'
);
}
});
// Make sure Debug ID is shown in dialog
var promise = waitForDialog(function (dialog) {
assert.match(dialog.document.documentElement.textContent, /D1234567890/);
});
doc.getElementById('debug-output-submit').click();
await promise;
win.close();
});
});
});