[Pkg-javascript-commits] [node-jsonstream] 197/214: add test for when body does not contain any matches, but the header should still be emitted
Bastien Roucariès
rouca at moszumanska.debian.org
Fri Dec 1 12:58:59 UTC 2017
This is an automated email from the git hooks/post-receive script.
rouca pushed a commit to branch master
in repository node-jsonstream.
commit 9de5fa596e5ba8d211021904fe2a355ac4fae046
Author: doowb <brian.woodward at gmail.com>
Date: Wed Sep 21 15:37:40 2016 -0400
add test for when body does not contain any matches, but the header should still be emitted
---
test/error_contents.js | 45 +++++++++++++++++++++++++++++++++++++++++++++
test/fixtures/error.json | 1 +
2 files changed, 46 insertions(+)
diff --git a/test/error_contents.js b/test/error_contents.js
new file mode 100644
index 0000000..13c27ae
--- /dev/null
+++ b/test/error_contents.js
@@ -0,0 +1,45 @@
+
+
+var fs = require ('fs')
+ , join = require('path').join
+ , file = join(__dirname, 'fixtures','error.json')
+ , JSONStream = require('../')
+ , it = require('it-is')
+
+var expected = JSON.parse(fs.readFileSync(file))
+ , parser = JSONStream.parse(['rows'])
+ , called = 0
+ , headerCalled = 0
+ , footerCalled = 0
+ , ended = false
+ , parsed = []
+
+fs.createReadStream(file).pipe(parser)
+
+parser.on('header', function (data) {
+ headerCalled ++
+ it(data).deepEqual({
+ error: 'error_code',
+ message: 'this is an error message'
+ })
+})
+
+parser.on('footer', function (data) {
+ footerCalled ++
+})
+
+parser.on('data', function (data) {
+ called ++
+ parsed.push(data)
+})
+
+parser.on('end', function () {
+ ended = true
+})
+
+process.on('exit', function () {
+ it(called).equal(0)
+ it(headerCalled).equal(1)
+ it(footerCalled).equal(0)
+ console.error('PASSED')
+})
diff --git a/test/fixtures/error.json b/test/fixtures/error.json
new file mode 100644
index 0000000..9736f3e
--- /dev/null
+++ b/test/fixtures/error.json
@@ -0,0 +1 @@
+{"error": "error_code", "message": "this is an error message"}
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-jsonstream.git
More information about the Pkg-javascript-commits
mailing list