[Pkg-javascript-commits] [node-coveralls] 75/332: tests for fetchGitData

Bastien Roucariès rouca at moszumanska.debian.org
Thu Nov 9 13:53: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-coveralls.

commit 6e8f7eb88a365894df8352caa826f2c3d8ff700d
Author: Gabe Hayes <gabriel.hayes at gmail.com>
Date:   Sat Jul 27 11:17:58 2013 -0700

    tests for fetchGitData
---
 lib/fetchGitData.js  | 63 +++++++++++++++++++--------------
 test/fetchGitData.js | 99 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 136 insertions(+), 26 deletions(-)

diff --git a/lib/fetchGitData.js b/lib/fetchGitData.js
index 5f3e582..a5a8eb8 100644
--- a/lib/fetchGitData.js
+++ b/lib/fetchGitData.js
@@ -2,31 +2,42 @@ var exec = require("exec-sync");
 
 var fetchGitData = function(git) {
 
-  var i,
-      execGit = true,
-      head = {
-        "author_name": {
-          "format": "'%aN'",
-          "default": "Unknown Author"
-        },
-        "author_email": {
-          "format": "'%ae'",
-          "default": ""
-        },
-        "committer_name": {
-          "format": "'%cN'",
-          "default": "Unknown Committer"
-        },
-        "committer_email": {
-          "format": "'%ce'",
-          "default" :""
-        },
-        "message": {
-          "format": "'%s'",
-          "default": "Unknown Commit Message"
-        }
-      },
-      remotes = {};
+  var i;
+  var execGit = true;
+  var head = {
+    "author_name": {
+      "format": "'%aN'",
+      "default": "Unknown Author"
+    },
+    "author_email": {
+      "format": "'%ae'",
+      "default": ""
+    },
+    "committer_name": {
+      "format": "'%cN'",
+      "default": "Unknown Committer"
+    },
+    "committer_email": {
+      "format": "'%ce'",
+      "default" :""
+    },
+    "message": {
+      "format": "'%s'",
+      "default": "Unknown Commit Message"
+    }
+  };
+  var remotes = {};
+
+  //-- Throw an error if no data is passed
+  if ('undefined' === typeof git) {
+    throw new Error('No options passed');
+
+  //-- Throw an error if no head or head.id is provided
+  } else if (!git.hasOwnProperty('head')) {
+    throw new Error('You must provide the head');
+  } else if (!git.head.hasOwnProperty('id')) {
+    throw new Error('You must provide the head.id');
+  }
 
   function saveRemote(name, url, push) {
     var key = name + "-" + url;
@@ -87,7 +98,7 @@ var fetchGitData = function(git) {
   if (execGit) {
 
     //-- Branch
-    if ("" === git.branch.length) {
+    if ("" === git.branch) {
       git.branch = exec("git branch").split("\n")[0].replace(/^\*\ /, "").trim();
     }
 
diff --git a/test/fetchGitData.js b/test/fetchGitData.js
new file mode 100644
index 0000000..aa5e2b2
--- /dev/null
+++ b/test/fetchGitData.js
@@ -0,0 +1,99 @@
+var should = require('should');
+var git = require('../lib/fetchGitData');
+
+describe("fetchGitData", function(){
+  beforeEach(function(){
+    process.env = {};
+  });
+  it("should throw an error when no data is passed", function() {
+    git.should.throw(/No options passed/);
+  });
+  it("should throw an error if no head is provided", function() {
+    var fn = function() {
+      git({});
+    };
+    fn.should.throw(/You must provide the head/);
+  });
+  it("should throw an error if no head.id is provided", function() {
+    var fn = function() {
+      git({
+        head: {}
+      });
+    };
+    fn.should.throw(/You must provide the head.id/);
+  });
+  it("should return default values", function() {
+    var options = git({
+      head: {
+        id: "COMMIT_HASH"
+      }
+    });
+    options.should.eql({
+      "head": {
+        "id": "COMMIT_HASH",
+        "author_name": "Unknown Author",
+        "author_email": "",
+        "committer_name": "Unknown Committer",
+        "committer_email": "",
+        "message": "Unknown Commit Message"
+      },
+      "branch": "",
+      "remotes": []
+    });
+  });
+  it("should override default values", function() {
+    var options = git({
+      "head": {
+        "id": "COMMIT_HASH",
+        "author_name": "MY AUTHOR",
+        "author_email": "",
+        "committer_name": "MY COMMITTER",
+        "committer_email": "",
+        "message": "MY COMMIT MESSAGE"
+      },
+      "branch": "TEST",
+      "remotes": [
+        {
+          "name": "TEST",
+          "url": "test-url"
+        }
+      ]
+    });
+    options.should.eql({
+      "head": {
+        "id": "COMMIT_HASH",
+        "author_name": "MY AUTHOR",
+        "author_email": "",
+        "committer_name": "MY COMMITTER",
+        "committer_email": "",
+        "message": "MY COMMIT MESSAGE"
+      },
+      "branch": "TEST",
+      "remotes": [
+        {
+          "name": "TEST",
+          "url": "test-url"
+        }
+      ]
+    });
+  });
+  it("execute git commands when a valid commit hash is given", function() {
+    var options = git({
+      "head": {
+        "id": "5eaec7e76af0743f9764e617472ef434f283a195"
+      }
+    });
+    options.head.should.eql({
+      "id": "5eaec7e76af0743f9764e617472ef434f283a195",
+      "author_name": "cainus",
+      "author_email": "gregg at caines.ca",
+      "committer_name": "cainus",
+      "committer_email": "gregg at caines.ca",
+      "message": "first commit"
+    });
+    options.branch.should.equal("master");
+    options.should.have.property("remotes");
+    options.remotes.should.be.instanceof(Array);
+    options.remotes.length.should.be.above(0);
+  });
+});

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



More information about the Pkg-javascript-commits mailing list