Add tests for parsing git url

This commit is contained in:
Samy Pessé
2015-01-26 08:05:07 +01:00
parent 0f0ec4cf3d
commit d6b44cc149
3 changed files with 38 additions and 2 deletions
+4 -1
View File
@@ -4,6 +4,7 @@ var url = require("url");
var tmp = require("tmp");
var path = require("path");
var crc = require("crc");
var ngu = require('normalize-git-url');
var exec = Q.denodeify(require("child_process").exec);
var fs = require("./fs");
@@ -28,6 +29,8 @@ function parseGitUrl(giturl) {
giturl = giturl.slice(GIT_PREFIX.length);
var parts = url.parse(giturl);
var normalized = ngu(giturl);
console.log(normalized);
var ref = parts.hash;
@@ -42,7 +45,7 @@ function parseGitUrl(giturl) {
return {
host: githost,
ref: ref,
ref: ref || "master",
filepath: filepath
};
}
+2 -1
View File
@@ -27,7 +27,8 @@
"tiny-lr-fork": "0.0.5",
"tmp": "0.0.24",
"crc": "3.2.1",
"bash-color": "0.0.3"
"bash-color": "0.0.3",
"normalize-git-url": "1.0.0"
},
"devDependencies": {
"mocha": "1.18.2",
+32
View File
@@ -0,0 +1,32 @@
var path = require('path');
var _ = require('lodash');
var assert = require('assert');
var fs = require("fs");
var git = require("../lib/utils/git");
describe('GIT parser and getter', function () {
it('should correctly parse an https url', function() {
var parts = git.parseUrl("git+https://gist.github.com/69ea4542e4c8967d2fa7.git/test.md");
assert(parts);
assert.equal(parts.host, "https://gist.github.com/69ea4542e4c8967d2fa7.git");
assert.equal(parts.ref, "master");
assert.equal(parts.filepath, "test.md");
});
it('should correctly parse an https url with a reference', function() {
var parts = git.parseUrl("git+https://gist.github.com/69ea4542e4c8967d2fa7.git/test.md#0.1.2");
assert(parts);
assert.equal(parts.host, "https://gist.github.com/69ea4542e4c8967d2fa7.git");
assert.equal(parts.ref, "0.1.2");
assert.equal(parts.filepath, "test.md");
});
it('should correctly parse an ssh url', function() {
var parts = git.parseUrl("git+git@github.com:GitbookIO/gitbook.git/directory/README.md#e1594cde2c32e4ff48f6c4eff3d3d461743d74e1");
assert(parts);
assert.equal(parts.host, "git@github.com");
assert.equal(parts.ref, "e1594cde2c32e4ff48f6c4eff3d3d461743d74e1");
assert.equal(parts.filepath, "directory/README.md");
});
});