[Pkg-javascript-commits] [node-tap] 22/186: Slight tweaks to lib/base to make it more coverageable

Bastien Roucariès rouca at moszumanska.debian.org
Fri Dec 1 16:40:39 UTC 2017


This is an automated email from the git hooks/post-receive script.

rouca pushed a commit to branch master
in repository node-tap.

commit e8e02134eaeca98564377b89e906ef5972c07dc5
Author: isaacs <i at izs.me>
Date:   Tue Sep 5 21:13:50 2017 -0700

    Slight tweaks to lib/base to make it more coverageable
---
 lib/base.js             | 20 ++++++++++++++------
 lib/extra-from-error.js |  6 ++++--
 2 files changed, 18 insertions(+), 8 deletions(-)

diff --git a/lib/base.js b/lib/base.js
index c818291..9d700ee 100644
--- a/lib/base.js
+++ b/lib/base.js
@@ -21,6 +21,7 @@ class Base extends MiniPass {
     this.start = 0
     this.hrtime = null
     this.time = null
+    this.timer = null
     this.readyToProcess = false
     this.options = options
     this.grep = ownOr(options, 'grep', [])
@@ -66,15 +67,21 @@ class Base extends MiniPass {
   }
 
   setTimeout (n) {
-    if (!this.hrtime)
-      this.hrtime = process.hrtime()
-
     if (!n) {
       clearTimeout(this.timer)
       this.timer = null
     } else {
-      this.start = Date.now()
+      if (!this.hrtime)
+        this.hrtime = process.hrtime()
+
+      if (!this.start)
+        this.start = Date.now()
+
+      if (this.timer)
+        clearTimeout(this.timer)
+
       this.timer = setTimeout(this.timeout.bind(this), n)
+      /* istanbul ignore else */
       if (this.timer.unref)
         this.timer.unref()
     }
@@ -96,7 +103,8 @@ class Base extends MiniPass {
       else if (!er.stack)
         console.error(er)
       else {
-        er.message = message
+        if (message)
+          er.message = message
         delete extra.stack
         delete extra.at
         console.error('%s: %s', er.name || 'Error', message)
@@ -114,7 +122,7 @@ class Base extends MiniPass {
     const er = new Error('timeout!')
     options = options || {}
     options.expired = options.expired || this.name
-    this.threw(new Error('timeout!'), options)
+    this.emit('timeout', this.threw(new Error('timeout!'), options))
   }
 
   main (cb) {
diff --git a/lib/extra-from-error.js b/lib/extra-from-error.js
index 849fd22..673129f 100644
--- a/lib/extra-from-error.js
+++ b/lib/extra-from-error.js
@@ -18,7 +18,8 @@ module.exports = function (er, extra, options) {
     : ''
   const addName = er.message || !er.stack
 
-  er.message = ''
+  if (er.message)
+    er.message = ''
   const st = er.stack
   if (st) {
     const splitst = st.split('\n')
@@ -26,7 +27,8 @@ module.exports = function (er, extra, options) {
     extra.at = stack.parseLine(splitst[1])
     extra.stack = stack.clean(splitst)
   }
-  er.message = message
+  if (message)
+    er.message = message
 
   if (er.name && er.name !== 'Error')
     extra.type = er.name

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-tap.git



More information about the Pkg-javascript-commits mailing list