Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce code coverage reporting & remove dead code #49

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ cover_html
.c9revisions
test/tmp
build
coverage/
10 changes: 10 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@

BIN := ./node_modules/.bin
SRC = $(wildcard index.js lib/*.js)
TESTS = $(wildcard test/*.js)

test: node_modules
@$(BIN)/gnode $(BIN)/_mocha

node_modules: package.json
@npm install
@touch node_modules

coverage: $(SRC) $(TESTS)
@$(BIN)/gnode $(BIN)/istanbul cover $(BIN)/_mocha

clean:
@rm -rf coverage

.PHONY: test
29 changes: 1 addition & 28 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ function Package(repo, ref) {
this.tok = auth.password || null;
this.setMaxListeners(Infinity);
this.dir = process.cwd();
this.ua = 'duo-package';
this.useragent('duo-package');
this.resolved = false;
this.ref = ref || '*';
this._cache = true;
Expand Down Expand Up @@ -323,33 +323,6 @@ Package.prototype.slug = function() {
return repo + '@' + ref;
};

/**
* Return request options for `url`.
*
* @param {String} url
* @param {Object} [opts]
* @return {Object}
* @api private
*/

Package.prototype.options = function(url, other){
var token = this.token();
var user = this.user;

var opts = {
url: url,
headers: { 'User-Agent': this.ua }
};

if (other) {
for (var k in other) opts[k] = other[k];
}

if (token) opts.headers.Authorization = 'Bearer ' + token;

return opts;
};

/**
* Reliably download the package.
* Returns a store to be piped around.
Expand Down
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,11 @@
},
"devDependencies": {
"co": "^3.0.5",
"co-mocha": "0.0.4",
"co-mocha": "^1.0.3",
"istanbul": "git://github.com/gotwarlost/istanbul#c6f8fc8b102cfa4e4455d6a165485b38cb58160c",
"mkdirp": "^0.5.0",
"mocha": "*",
"mocha": "^2.0.1",
"rimraf": "^2.2.8"
},
"main": "index.js"
}
}
17 changes: 12 additions & 5 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,12 +108,19 @@ describe('duo-package', function(){
// TODO: figure out a way to test private modules
})

describe('Package#options()', function() {
it('should properly add a bearer token', function(){
describe('Package#useragent()', function() {
it('should get/set the useragent', function(){
var pkg = new Package('segmentio/marked', '*');
pkg.token('some token');
var opts = pkg.options();
assert('Bearer some token' == opts.headers.Authorization);
pkg.useragent('foo');
assert('foo' == pkg.useragent());
})
})

describe('Package#directory()', function() {
it('should get/set the directory', function(){
var pkg = new Package('segmentio/marked', '*');
pkg.directory(__dirname);
assert(__dirname == pkg.directory());
})
})
})