Skip to content

Commit 2eec6af

Browse files
author
Ændrew Rininsland
committed
Adds Karma.
1 parent 4b120b6 commit 2eec6af

8 files changed

Lines changed: 194 additions & 95 deletions

File tree

gulpfile.js

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ var jshint = require('gulp-jshint');
55
var jscs = require('gulp-jscs');
66
var rename = require('gulp-rename');
77
var uglify = require('gulp-uglify');
8+
var path = require('path');
9+
var karma = require('karma');
810

911
gulp.task('lint', function() {
1012
return gulp.src('github.js')
@@ -17,7 +19,12 @@ gulp.task('lint', function() {
1719
.pipe(gulp.dest('.'));
1820
});
1921

20-
gulp.task('test', function() {
22+
gulp.task('test', function(done) {
23+
runTests(true, done);
24+
});
25+
26+
gulp.task('test:auto', function(done) {
27+
runTests(false, done);
2128
});
2229

2330
gulp.task('build', function() {
@@ -29,4 +36,35 @@ gulp.task('build', function() {
2936

3037
gulp.task('default', function() {
3138
gulp.start('lint', 'test', 'build');
32-
});
39+
});
40+
41+
function runTests (singleRun, done) {
42+
var reporters = ['mocha'];
43+
var preprocessors = {};
44+
45+
var pathSrcJs = [
46+
path.join(__dirname, 'github.js')
47+
];
48+
49+
if (singleRun) {
50+
pathSrcJs.forEach(function(path) {
51+
preprocessors[path] = ['coverage'];
52+
});
53+
reporters.push('coverage');
54+
55+
preprocessors['test/user.json'] = ['json_fixtures'];
56+
}
57+
58+
var localConfig = {
59+
configFile: path.join(__dirname, './karma.conf.js'),
60+
singleRun: singleRun,
61+
autoWatch: !singleRun,
62+
reporters: reporters,
63+
preprocessors: preprocessors
64+
};
65+
66+
var server = new karma.Server(localConfig, function(failCount) {
67+
done(failCount ? new Error('Failed ' + failCount + ' tests.') : null);
68+
});
69+
server.start();
70+
}

package.json

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
{
22
"name": "github-api",
3-
"version": "0.10.6",
3+
"version": "0.10.7",
44
"description": "A higher-level wrapper around the Github API.",
55
"main": "github.js",
66
"dependencies": {
77
"js-base64": "^2.1.8",
8+
"karma-json-fixtures-preprocessor": "0.0.5",
89
"xmlhttprequest": "~1.7.0"
910
},
1011
"devDependencies": {
@@ -18,11 +19,16 @@
1819
"istanbul": "^0.3.13",
1920
"jshint": "^2.5.8",
2021
"jshint-stylish": "^2.0.1",
21-
"plato": "^1.4.0",
2222
"karma": "^0.13.14",
23+
"karma-chai": "^0.1.0",
2324
"karma-coverage": "^0.5.3",
2425
"karma-mocha": "^0.2.0",
26+
"karma-mocha-reporter": "^1.1.1",
27+
"karma-phantomjs-launcher": "^0.2.1",
28+
"karma-sinon": "^1.0.4",
2529
"mocha": "^2.3.3",
30+
"phantomjs": "^1.9.18",
31+
"plato": "^1.4.0",
2632
"sinon": "^1.17.2",
2733
"sinon-chai": "^2.8.0"
2834
},

test/test.auth.js

Lines changed: 31 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,32 @@
11
'use strict';
22

3-
// module dependencies
4-
var chai = require('chai'),
5-
sinonChai = require('sinon-chai');
3+
var test_user, github, user;
64

7-
var Github = require('../');
8-
var test_user = require('./user.json');
5+
if (typeof window === 'undefined') {
6+
// module dependencies
7+
var chai = require('chai'),
8+
sinonChai = require('sinon-chai');
99

10-
// Use should flavour for Mocha
11-
var should = chai.should();
12-
chai.use(sinonChai);
10+
var Github = require('../');
11+
test_user = require('./user.json');
12+
13+
// Use should flavour for Mocha
14+
var should = chai.should();
15+
chai.use(sinonChai);
16+
}
1317

1418
describe('Github constructor', function() {
15-
var github = new Github({
16-
username: test_user.USERNAME,
17-
password: test_user.PASSWORD,
18-
auth: 'basic'
19+
before(function(){
20+
if (typeof window !== 'undefined') test_user = window.__fixtures__['test/user'];
21+
22+
github = new Github({
23+
username: test_user.USERNAME,
24+
password: test_user.PASSWORD,
25+
auth: 'basic'
26+
});
27+
28+
user = github.getUser();
1929
});
20-
var user = github.getUser();
2130

2231
it('should authenticate and return no errors', function(done){
2332
user.notifications(function(err){
@@ -28,12 +37,16 @@ describe('Github constructor', function() {
2837
});
2938

3039
describe('Github constructor (failing case)', function() {
31-
var github = new Github({
32-
username: test_user.USERNAME,
33-
password: 'fake124',
34-
auth: 'basic'
40+
before(function(){
41+
if (typeof window !== 'undefined') test_user = window.__fixtures__['test/user'];
42+
43+
github = new Github({
44+
username: test_user.USERNAME,
45+
password: 'fake124',
46+
auth: 'basic'
47+
});
48+
user = github.getUser();
3549
});
36-
var user = github.getUser();
3750

3851
it('should fail authentication and return err', function(done){
3952
user.notifications(function(err){

test/test.issue.js

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,32 @@
11
'use strict';
22

3-
// module dependencies
4-
var chai = require('chai'), sinonChai = require('sinon-chai');
3+
var test_user, github, issues;
54

6-
// GitHub data
7-
var Github = require('../');
8-
var test_user = require('./user.json');
5+
if (typeof window === 'undefined') {
6+
// module dependencies
7+
var chai = require('chai'),
8+
sinonChai = require('sinon-chai');
99

10-
// Use should flavour for Mocha
11-
var should = chai.should();
12-
chai.use(sinonChai);
10+
var Github = require('../');
11+
test_user = require('./user.json');
12+
13+
// Use should flavour for Mocha
14+
var should = chai.should();
15+
chai.use(sinonChai);
16+
}
1317

1418
describe('Github.Issue', function() {
15-
var github = new Github({
16-
username : test_user.USERNAME,
17-
password : test_user.PASSWORD,
18-
auth : 'basic'
19-
});
19+
before(function(){
20+
if (typeof window !== 'undefined') test_user = window.__fixtures__['test/user'];
2021

21-
var issues = github.getIssues('mikedeboertest', 'TestRepo');
22+
github = new Github({
23+
username : test_user.USERNAME,
24+
password : test_user.PASSWORD,
25+
auth : 'basic'
26+
});
27+
28+
issues = github.getIssues('mikedeboertest', 'TestRepo');
29+
});
2230

2331
it('should list issues', function(done) {
2432
issues.list({}, function(err, issues) {

test/test.repo.js

Lines changed: 50 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,32 @@
11
'use strict';
22

3-
// module dependencies
4-
var chai = require('chai'), sinonChai = require('sinon-chai');
3+
var github, repo, user, test_user;
54

6-
var Github = require('../');
7-
var test_user = require('./user.json');
5+
if (typeof window === 'undefined') {
6+
// module dependencies
7+
var chai = require('chai'),
8+
sinonChai = require('sinon-chai');
89

9-
// Use should flavour for Mocha
10-
var should = chai.should();
11-
chai.use(sinonChai);
10+
var Github = require('../');
11+
test_user = require('./user.json');
12+
13+
// Use should flavour for Mocha
14+
var should = chai.should();
15+
chai.use(sinonChai);
16+
}
1217

1318
describe('Github.Repository', function() {
14-
var github = new Github({
15-
username : test_user.USERNAME,
16-
password : test_user.PASSWORD,
17-
auth : 'basic'
19+
before(function(){
20+
if (typeof window !== 'undefined') test_user = window.__fixtures__['test/user'];
21+
22+
github = new Github({
23+
username : test_user.USERNAME,
24+
password : test_user.PASSWORD,
25+
auth : 'basic'
26+
});
27+
28+
repo = github.getRepo('michael', 'github');
1829
});
19-
var repo = github.getRepo('michael', 'github');
2030

2131
it('should show repo', function(done) {
2232
repo.show(function(err, res) {
@@ -82,7 +92,7 @@ describe('Github.Repository', function() {
8292
it('should get a SHA from a repo', function(done) {
8393
repo.getSha('master', '.gitignore', function(err, sha) {
8494
should.not.exist(err);
85-
sha.should.equal('8293a5658aed839ed52fb0e5bd9e6c467c992d3d');
95+
sha.should.equal('743f72052be92b3e7f42b8318f2663a9011ef5be');
8696
done();
8797
});
8898
});
@@ -100,12 +110,18 @@ describe('Github.Repository', function() {
100110
var repoTest = Math.floor(Math.random() * (100000 - 0)) + 0;
101111

102112
describe('Creating new Github.Repository', function() {
103-
var github = new Github({
104-
username : test_user.USERNAME,
105-
password : test_user.PASSWORD,
106-
auth : 'basic'
113+
before(function(){
114+
if (typeof window !== 'undefined') test_user = window.__fixtures__['test/user'];
115+
116+
github = new Github({
117+
username : test_user.USERNAME,
118+
password : test_user.PASSWORD,
119+
auth : 'basic'
120+
});
121+
122+
user = github.getUser();
123+
repo = github.getRepo(test_user.USERNAME, repoTest);
107124
});
108-
var user = github.getUser();
109125

110126
it('should create repo', function(done) {
111127
user.createRepo({'name' : repoTest}, function(err, res) {
@@ -115,8 +131,6 @@ describe('Creating new Github.Repository', function() {
115131
});
116132
});
117133

118-
var repo = github.getRepo(test_user.USERNAME, repoTest);
119-
120134
it('should write to repo', function(done) {
121135
repo.write('master', 'TEST.md', 'THIS IS A TEST', 'Creating test', function(err) {
122136
should.not.exist(err);
@@ -267,12 +281,15 @@ describe('Creating new Github.Repository', function() {
267281
});
268282

269283
describe('deleting a Github.Repository', function() {
270-
var github = new Github({
271-
username : test_user.USERNAME,
272-
password : test_user.PASSWORD,
273-
auth : 'basic'
284+
before(function(){
285+
if (typeof window !== 'undefined') test_user = window.__fixtures__['test/user'];
286+
github = new Github({
287+
username : test_user.USERNAME,
288+
password : test_user.PASSWORD,
289+
auth : 'basic'
290+
});
291+
repo = github.getRepo(test_user.USERNAME, repoTest);
274292
});
275-
var repo = github.getRepo(test_user.USERNAME, repoTest);
276293

277294
it('should delete the repo', function(done){
278295
repo.deleteRepo(function(err, res) {
@@ -284,12 +301,15 @@ describe('deleting a Github.Repository', function() {
284301
});
285302

286303
describe('Repo returns commit errors correctly', function() {
287-
var github = new Github({
288-
username : test_user.USERNAME,
289-
password : test_user.PASSWORD,
290-
auth : 'basic'
304+
before(function(){
305+
if (typeof window !== 'undefined') test_user = window.__fixtures__['test/user'];
306+
github = new Github({
307+
username : test_user.USERNAME,
308+
password : test_user.PASSWORD,
309+
auth : 'basic'
310+
});
311+
repo = github.getRepo(test_user.USERNAME, test_user.REPO);
291312
});
292-
var repo = github.getRepo(test_user.USERNAME, test_user.REPO);
293313

294314
it('should fail on broken commit', function(done){
295315
repo.commit('broken-parent-hash', 'broken-tree-hash', 'commit message', function(err) {

test/test.search.js

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,28 @@
11
'use strict';
22

3-
// module dependencies
4-
var chai = require('chai'), sinonChai = require('sinon-chai');
3+
var github;
54

6-
var Github = require('../');
7-
var test_user = require('./user.json');
5+
if (typeof window === 'undefined') {
6+
// module dependencies
7+
var chai = require('chai'),
8+
sinonChai = require('sinon-chai');
89

9-
// Use should flavour for Mocha
10-
var should = chai.should();
11-
chai.use(sinonChai);
10+
var Github = require('../');
11+
var test_user = require('./user.json');
12+
13+
// Use should flavour for Mocha
14+
var should = chai.should();
15+
chai.use(sinonChai);
16+
}
1217

1318
describe('Github.Search', function() {
14-
var github = new Github({
15-
username: test_user.USERNAME,
16-
password: test_user.PASSWORD,
17-
auth: "basic"
19+
before(function(){
20+
if (typeof window !== 'undefined') test_user = window.__fixtures__['test/user'];
21+
github = new Github({
22+
username: test_user.USERNAME,
23+
password: test_user.PASSWORD,
24+
auth: "basic"
25+
});
1826
});
1927

2028
it('should search.repositories', function(done) {

0 commit comments

Comments
 (0)