if (req.parsedBody.ignoreMessages) {
options.ignoreMessages = req.parsedBody.ignoreMessages;
}
+ if (req.parsedBody.finishTimeout) {
+ options.finishTimeout = req.parsedBody.finishTimeout;
+ }
// start test
console.log(`run test for ${targetUrl}`);
sendJSON(resp, 500, {error: error, message: "domtest running error" });
return;
}
+
+ const errors = stringifyErrors(domtest.runtimeErrors);
sendJSON(resp, 200, {error: 0,
runtimeErrorCount: domtest.errorCounter,
- runtimeErrors: domtest.runtimeErrors});
- });
+ runtimeErrors: errors, });
+ });
}
+function stringifyErrors(errors) {
+ const result = [];
+ errors.forEach((val) => {
+ const rs = {};
+ if (val.type) {
+ rs.type = val.type;
+ }
+ if (val.detail) {
+ rs.detail = val.detail.toString();
+ }
+ result.push(rs);
+ });
+ return result;
+}
this.jsdomConfig = {
url: "",
virtualConsole: this.virtualConsole,
- created: (error, window) => {this._onTestCreated(error, window);},
- done: (error, window) => {this._onTestDone(error, window);},
+ created: (error, window) => {this._onCreated(error, window);},
+ done: (error, window) => {this._onDone(error, window);},
strictSSL: false,
features: {
FetchExternalResources: ["script", "link"],
this.errorCounter++;
}
- _onTestDone(error, window) {
+ _onDone(error, window) {
if (!this.doneTestCallback) {
return;
}
return;
}
- window.close();
- if (this.errorCounter) {
- this.resultCode = 1;
- }
- this.doneTestCallback(error, this);
+ window.setTimeout(() => {
+ if (this.errorCounter) {
+ this.resultCode = 1;
+ }
+ this.doneTestCallback(error, this);
+ window.close();
+ }, this.options.finishTimeout || 5000);
}
- _onTestCreated(error, window) {
+ _onCreated(error, window) {
if (error) {
this.doneTestCallback(error, this);
return;
#!/usr/bin/nodejs
const http = require('http');
+const util = require('util');
const DomTest = require('./domtest');
const url = require('url');
console.log("domtest running error");
return;
}
- console.log(domtest.runtimeErrors);
+ domtest.runtimeErrors.forEach((val) => {
+ console.log(util.inspect(val, {showHidden:false, depth:null}));
+ //console.log(val.stack);
+ });
});