OSDN Git Service

t/domtest: add finishTimeout parameter todomtest server and show error detail more...
authorhylom <hylom@users.sourceforge.jp>
Fri, 26 Jan 2018 12:32:54 +0000 (21:32 +0900)
committerhylom <hylom@users.sourceforge.jp>
Fri, 26 Jan 2018 12:32:54 +0000 (21:32 +0900)
src/newslash_web/t/dom_test/app.js
src/newslash_web/t/dom_test/domtest.js
src/newslash_web/t/dom_test/domtest_cli.js

index 085d8b6..767dca6 100644 (file)
@@ -83,6 +83,9 @@ function processRequest(req, resp) {
   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}`);
@@ -92,9 +95,25 @@ function processRequest(req, resp) {
       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;
+}
index 07ea5c4..4d53f70 100644 (file)
@@ -14,8 +14,8 @@ class DomTest {
     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"],
@@ -50,7 +50,7 @@ class DomTest {
     this.errorCounter++;
   }
 
-  _onTestDone(error, window) {
+  _onDone(error, window) {
     if (!this.doneTestCallback) {
       return;
     }
@@ -60,14 +60,16 @@ class DomTest {
       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;
index 54c38be..a633f86 100644 (file)
@@ -1,6 +1,7 @@
 #!/usr/bin/nodejs
 
 const http = require('http');
+const util = require('util');
 
 const DomTest = require('./domtest');
 const url = require('url');
@@ -32,6 +33,9 @@ domtest.run(targetUrl, options, (error) => {
     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);
+  });
 });