-
-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathtest.js
78 lines (66 loc) · 2.38 KB
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
'use strict';
require('mocha');
var extend = require('extend-shallow');
var store = require('data-store')('github-base-tests');
var assert = require('assert');
var contributors = require('./');
// todo: wire up CLI to set auth
var auth = store.get('auth') || {};
describe('contributors', function() {
it('should return an empty array when the URL is not found', function(cb) {
contributors('flkjsalkfjas;lj', auth, function(err, res) {
if (err) return cb(err);
assert(Array.isArray(res));
assert.equal(res.length, 0);
cb();
});
});
it('should get a valid response (json) from the github api:', function(cb) {
contributors('assemble/assemble', auth, function(err, res) {
if (err) return cb(err);
assert(Array.isArray(res));
assert(res[0].hasOwnProperty('login'));
assert(res[0].hasOwnProperty('id'));
assert(res[0].hasOwnProperty('avatar_url'));
assert(res[0].hasOwnProperty('gravatar_id'));
cb();
});
});
it('should generate a formatted list of contributors:', function(cb) {
var opts = extend({}, auth, {format: 'list'});
contributors('jonschlinkert/micromatch', opts, function(err, res) {
if (err) return cb(err);
assert(res.indexOf('**Commits** / **Contributor**') !== -1);
cb();
});
});
it('should generate a formatted, aligned list of contributors:', function(cb) {
var opts = extend({}, auth, {format: 'aligned'});
contributors('jonschlinkert/gray-matter', opts, function(err, res) {
if (err) return cb(err);
assert(res.indexOf('COMMITS') !== -1);
cb();
});
});
it('should generate a formatted table of contributors:', function(cb) {
var opts = extend({}, auth, {format: 'table'});
contributors('assemble/assemble', opts, function(err, res) {
if (err) return cb(err);
assert(res.indexOf('| **Commits** | **Contributor**<br/> |') !== -1);
cb();
});
});
it('should throw an error when repo is not a string:', function() {
assert.throws(function() {
contributors('foo');
}, /expected callback to be a function/);
});
it('should throw an error when no callback is given.', function() {
assert.throws(function() {
contributors('foo');
}, /expected callback to be a function/);
assert.throws(function() {
contributors('foo', {});
}, /expected callback to be a function/);
});
});