[Pkg-javascript-commits] [node-tap] 32/186: unit test for test point class

Bastien Roucariès rouca at moszumanska.debian.org
Fri Dec 1 16:40:41 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 f785142a27d60ca00aad362be1bb07723e2fbfe0
Author: isaacs <i at izs.me>
Date:   Wed Sep 6 17:32:17 2017 -0700

    unit test for test point class
    
    Also make a few little tweaks in the TestPoint class that showed up
    during testing.
---
 lib/point.js  | 15 +++++++-----
 unit/point.js | 77 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 86 insertions(+), 6 deletions(-)

diff --git a/lib/point.js b/lib/point.js
index 4c35247..e59a115 100644
--- a/lib/point.js
+++ b/lib/point.js
@@ -10,20 +10,21 @@ class TestPoint {
     if (typeof ok !== 'boolean')
       throw new TypeError('ok must be boolean')
 
-    if (!(this instanceof TestPoint))
-      return new TestPoint(ok, message, extra)
+    if (typeof message !== 'string')
+      throw new TypeError('message must be a string')
+
+    extra = extra || {}
 
     this.ok = ok ? 'ok ' : 'not ok '
-    this.message = tpMessage(message, extra)
+    this.message = tpMessage(message.trim(), extra)
   }
 }
 
 const tpMessage = (message, extra) => {
-  message = message + ''
   if (message)
     message = ' - ' + message
+
   message = message.replace(/[\n\r]/g, ' ').replace(/\t/g, '  ')
-  extra = extra || {}
 
   if (extra.skip) {
     message += ' # SKIP'
@@ -45,7 +46,9 @@ const tpMessage = (message, extra) => {
     message += '{\n' + extra.tapChildBuffer.trimRight() + '\n}\n'
   }
 
-  message += '\n'
+  if (message)
+    message += '\n'
+
   return message
 }
 
diff --git a/unit/point.js b/unit/point.js
new file mode 100644
index 0000000..6ec6906
--- /dev/null
+++ b/unit/point.js
@@ -0,0 +1,77 @@
+'use strict'
+const t = require('../')
+const TestPoint = require('../lib/point.js')
+
+t.throws(_ => new TestPoint(99),
+  new TypeError('ok must be boolean'))
+
+t.throws(_ => new TestPoint(true, Math),
+  new TypeError('message must be a string'))
+
+const cases = [
+  [true, 'this is fine', null, {
+    ok: 'ok ',
+    message: ' - this is fine'
+  }],
+  [false, 'this is fine', null, {
+    ok: 'not ok ',
+    message: ' - this is fine'
+  }],
+  [true, '     ', null, {
+    ok: 'ok ',
+    message: ''
+  }],
+  [false, '\n\r\t\n', null, {
+    ok: 'not ok ',
+    message: ''
+  }],
+  [true, 'this is fine        ', { skip: true }, {
+    ok: 'ok ',
+    message: ' - this is fine # SKIP'
+  }],
+  [true, 'this is fine', { skip: 'nope' }, {
+    ok: 'ok ',
+    message: ' - this is fine # SKIP nope'
+  }],
+  [true, 'this is fine', { todo: true }, {
+    ok: 'ok ',
+    message: ' - this is fine # TODO'
+  }],
+  [true, 'this is fine', { todo: 'later' }, {
+    ok: 'ok ',
+    message: ' - this is fine # TODO later'
+  }],
+  [true, 'time waits for no one', { time: '12345ms' }, {
+    ok: 'ok ',
+    message: 'time waits for no one # time=12345ms'
+  }],
+  [true, 'fine', { foo: 'bar', diagnostic: true }, {
+    ok: 'ok ',
+    message: ' - fine\n  ---\n  foo: bar\n  ...\n\n'
+  }],
+  [true, '', { foo: 'bar', diagnostic: true }, {
+    ok: 'ok ',
+    message: '\n  ---\n  foo: bar\n  ...\n\n'
+  }],
+  [false, 'x\ny\r\nz', {}, {
+    ok: 'not ok ',
+    message: 'x y  z'
+  }],
+  [true, '', {
+    tapChildBuffer: 'child output',
+    diagnostic: true,
+    fluffer: 'nutter'
+  }, {
+    ok: 'ok ',
+    message: '\n  ---\n  fluffer: nutter\n  ...\n{\nchild output\n}\n'
+  }],
+  [true, '', {
+    tapChildBuffer: 'child output',
+    fluffer: 'nutter'
+  }, {
+    ok: 'ok ',
+    message: ' {\nchild output\n}\n'
+  }],
+]
+
+cases.forEach(c => t.match(new TestPoint(c[0], c[1], c[2]), c[3]))

-- 
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