Skip to content

Commit 1813b0d

Browse files
author
Ændrew Rininsland
committed
Rewrote all unit tests to use Mocha Chai instead of Tape.
1 parent 05ca726 commit 1813b0d

File tree

7 files changed

+306
-276
lines changed

7 files changed

+306
-276
lines changed

package.json

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"xmlhttprequest": "~1.7.0"
99
},
1010
"devDependencies": {
11+
"chai": "^3.4.0",
1112
"codecov": "^1.0.1",
1213
"gulp": "^3.9.0",
1314
"gulp-jscs": "^3.0.1",
@@ -18,12 +19,17 @@
1819
"jshint": "^2.5.8",
1920
"jshint-stylish": "^2.0.1",
2021
"plato": "^1.4.0",
21-
"tape": "^3.0.3"
22+
"karma": "^0.13.14",
23+
"karma-coverage": "^0.5.3",
24+
"karma-mocha": "^0.2.0",
25+
"mocha": "^2.3.3",
26+
"sinon": "^1.17.2",
27+
"sinon-chai": "^2.8.0"
2228
},
2329
"scripts": {
24-
"test": "tape test/*.js && npm run-script jshint",
30+
"test": "mocha test/*.js && npm run-script jshint",
2531
"jshint": "jshint github.js test/",
26-
"codecov": "istanbul cover tape test/*.js && cat ./coverage/coverage.json | ./node_modules/.bin/codecov"
32+
"codecov": "istanbul cover ./node_modules/mocha/bin/_mocha -- -R spec && cat ./coverage/lcov.info | ./node_modules/.bin/codecov"
2733
},
2834
"repository": {
2935
"type": "git",

test/test.auth.js

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,45 @@
11
'use strict';
22

3-
var test = require('tape'); //jshint ignore:line
4-
var Github = require("../");
3+
// module dependencies
4+
var chai = require('chai'),
5+
sinonChai = require('sinon-chai');
6+
7+
var Github = require('../');
58
var test_user = require('./user.json');
69

7-
test("Basic Auth - Pass", function(t) {
8-
var timeout = setTimeout(function () { t.fail(); }, 10000);
10+
// Use should flavour for Mocha
11+
var should = chai.should();
12+
chai.use(sinonChai);
13+
14+
describe('Github constructor', function() {
915
var github = new Github({
1016
username: test_user.USERNAME,
1117
password: test_user.PASSWORD,
12-
auth: "basic"
18+
auth: 'basic'
1319
});
1420
var user = github.getUser();
15-
16-
user.notifications(function(err) {
17-
t.error(err, 'user is authd');
21+
22+
it('should authenticate and return no errors', function(done){
23+
user.notifications(function(err){
24+
should.not.exist(err);
25+
done();
26+
});
1827
});
19-
20-
clearTimeout(timeout);
21-
t.end();
2228
});
2329

24-
test("Basic Auth - Fail", function(t) {
25-
var timeout = setTimeout(function () { t.fail(); }, 10000);
30+
describe('Github constructor (failing case)', function() {
2631
var github = new Github({
2732
username: test_user.USERNAME,
2833
password: 'fake124',
29-
auth: "basic"
34+
auth: 'basic'
3035
});
3136
var user = github.getUser();
3237

33-
user.notifications(function(err) {
34-
t.ok(err, 'user is not authd');
35-
t.equals(JSON.parse(err.request.responseText).message, 'Bad credentials', 'confirm error');
38+
it('should fail authentication and return err', function(done){
39+
user.notifications(function(err){
40+
err.request.status.should.equal(401, 'Return 401 status for bad auth');
41+
JSON.parse(err.request.responseText).message.should.equal('Bad credentials');
42+
done();
43+
});
3644
});
37-
38-
clearTimeout(timeout);
39-
t.end();
40-
4145
});

test/test.gist.js

Whitespace-only changes.

test/test.issue.js

Lines changed: 31 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,40 @@
11
'use strict';
22

3-
var test = require('tape'); //jshint ignore:line
4-
var Github = require("../");
3+
// module dependencies
4+
var chai = require('chai'), sinonChai = require('sinon-chai');
5+
6+
// GitHub data
7+
var Github = require('../');
58
var test_user = require('./user.json');
69

7-
test("Issues API", function(t) {
8-
var github = new Github({
9-
username: test_user.USERNAME,
10-
password: test_user.PASSWORD,
11-
auth: "basic"
12-
});
10+
// Use should flavour for Mocha
11+
var should = chai.should();
12+
chai.use(sinonChai);
1313

14-
var issues = github.getIssues('mikedeboertest', 'TestRepo');
14+
describe('Github.Issue', function() {
15+
var github = new Github({
16+
username : test_user.USERNAME,
17+
password : test_user.PASSWORD,
18+
auth : 'basic'
19+
});
1520

16-
t.test('issues.list', function(q) {
17-
issues.list({},function(err, issues) {
18-
q.error(err);
19-
t.equals(issues.length > 0, true, 'Issues!');
20-
q.end();
21-
});
22-
t.end();
23-
});
21+
var issues = github.getIssues('mikedeboertest', 'TestRepo');
2422

25-
t.test('issues.comment', function(q) {
26-
issues.list({},function(err, issuesList) {
27-
issues.comment(issuesList[0], 'Comment test', function(err, res){
28-
q.error(err);
29-
t.equals(res.body, 'Comment test', 'Comments!');
30-
q.end();
31-
});
32-
});
23+
it('should list issues', function(done) {
24+
issues.list({}, function(err, issues) {
25+
should.not.exist(err);
26+
issues.should.have.length.above(0);
27+
done();
3328
});
29+
});
3430

35-
36-
});
31+
it('should post issue comment', function(done) {
32+
issues.list({}, function(err, issuesList) {
33+
issues.comment(issuesList[0], 'Comment test', function(err, res) {
34+
should.not.exist(err);
35+
res.body.should.equal('Comment test');
36+
done();
37+
});
38+
});
39+
});
40+
});

0 commit comments

Comments
 (0)