[Pkg-javascript-commits] [node-lcov-parse] 08/45: Fixes #2 - Support parsing from string

Bastien Roucariès rouca at moszumanska.debian.org
Wed Sep 6 09:46:15 UTC 2017


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

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

commit 6e0d49e938bda599c5d389402a4964cf54f8cd67
Author: Dav Glass <davglass at gmail.com>
Date:   Thu Mar 28 10:16:27 2013 -0400

    Fixes #2 - Support parsing from string
---
 lib/index.js   | 10 ++++++----
 tests/parse.js | 10 ++++++++++
 2 files changed, 16 insertions(+), 4 deletions(-)

diff --git a/lib/index.js b/lib/index.js
index 66a4bbc..9934c3b 100644
--- a/lib/index.js
+++ b/lib/index.js
@@ -96,15 +96,17 @@ var walkFile = function(str, cb) {
             item = {};
         }
     });
-    cb(null, data);
+    if (data.length) {
+        cb(null, data);
+    } else {
+        cb('Failed to parse string');
+    }
 };
 
 var parse = function(file, cb) {
-    
     exists(file, function(x) {
         if (!x) {
-            cb("Failed to find file: " + file);
-            return;
+            return walkFile(file, cb);
         }
         fs.readFile(file, 'utf8', function(err, str) {
             walkFile(str, cb);
diff --git a/tests/parse.js b/tests/parse.js
index 6f6176b..2a27bb8 100644
--- a/tests/parse.js
+++ b/tests/parse.js
@@ -22,6 +22,16 @@ var tests = {
             assert.isString(err);
         }
     },
+    'Parse as a string': {
+        topic: function() {
+            parse('TN:TestName\nSF:foobar.js\nend_of_record\n', this.callback);
+        },
+        'should parse': function(err, data) {
+            assert.isArray(data);
+            assert.equal('TestName', data[0].title);
+            assert.equal('foobar.js', data[0].file);
+        }
+    },
     'parse the file': {
         topic: function() {
             parse(yuiFile, this.callback);

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



More information about the Pkg-javascript-commits mailing list