[Pkg-javascript-commits] [node-tap] 48/186: add stdin unit test

Bastien Roucariès rouca at moszumanska.debian.org
Fri Dec 1 16:40:42 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 e6ee1f8bf47ed8e3caa1da8d41abccb6ac5be0be
Author: isaacs <i at izs.me>
Date:   Mon Oct 30 13:50:28 2017 -0700

    add stdin unit test
---
 lib/stdin.js  |  2 +-
 unit/stdin.js | 79 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 80 insertions(+), 1 deletion(-)

diff --git a/lib/stdin.js b/lib/stdin.js
index 79af532..1bc47b4 100644
--- a/lib/stdin.js
+++ b/lib/stdin.js
@@ -6,8 +6,8 @@ const domain = require('domain')
 class Stdin extends Base {
   constructor (options) {
     options = options || {}
-    super(options)
     options.name = ownOr(options, 'name', '/dev/stdin')
+    super(options)
 
     // This has to be here for node 0.10's wonky streams
     this.stream = ownOr(options, 'tapStream', process.stdin)
diff --git a/unit/stdin.js b/unit/stdin.js
new file mode 100644
index 0000000..6ae9168
--- /dev/null
+++ b/unit/stdin.js
@@ -0,0 +1,79 @@
+const t = require('../')
+const Stdin = require('../lib/stdin.js')
+const MP = require('minipass')
+
+t.test('uses stdin if no stream provided', t => {
+  const s = new Stdin()
+  t.equal(s.stream, process.stdin)
+  t.equal(s.name, '/dev/stdin')
+  t.end()
+})
+
+t.test('basic test', t => {
+  const stream = new MP()
+  const s = new Stdin({
+    tapStream: stream,
+    name: 'foo',
+    buffered: true
+  })
+  t.equal(s.stream, stream)
+  t.equal(s.name, 'foo')
+
+  s.main(_ => {
+    t.match(s.results, {
+      ok: true,
+      count: 1,
+      pass: 1,
+      fail: 0,
+      bailout: false,
+      plan: {
+        start: 1,
+        end: 1,
+        skipAll: false
+      },
+      failures: []
+    })
+    t.end()
+  })
+
+  s.stream.end(`TAP version 13
+1..1
+ok 1 - this is fine
+`)
+})
+
+t.test('failure test', t => {
+  const stream = new MP()
+  const s = new Stdin({
+    tapStream: stream
+  })
+
+  s.main(_ => {
+    t.match(s.results, {
+      ok: false,
+      count: 2,
+      pass: 1,
+      fail: 1,
+      bailout: false,
+      todo: 0,
+      skip: 0,
+      plan: {
+        start: 1,
+        end: 2,
+        skipAll: false
+      },
+      failures: [{
+        ok: false,
+        id: 2,
+        name: 'oops'
+      }]
+    })
+    t.end()
+  })
+
+  s.stream.write(`TAP version 13
+ok 1 - this is fine
+`)
+
+  s.threw(new Error('oops'))
+})

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