Skip to content

Commit c895f35

Browse files
author
Ændrew Rininsland
committed
Fixed linting issue after last merge, made repo.delete an alias for repo.remove, fixed repo.remove, fixed window undefined issue in Node, added Mocha tests to Travis.
1 parent 15893aa commit c895f35

File tree

4 files changed

+69
-52
lines changed

4 files changed

+69
-52
lines changed

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@ node_js:
88
- "0.10"
99
script:
1010
- npm test
11+
- mocha test/ --timeout=60000
1112
- npm run-script codecov

github.js

Lines changed: 28 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -11,30 +11,31 @@
1111
*/
1212

1313
(function (root, factory) {
14-
// UMD boilerplate from https://github.com/umdjs/umd/blob/master/returnExportsGlobal.js
15-
'use strict';
16-
17-
/* istanbul ignore next */
18-
if (typeof define === 'function' && define.amd) {
19-
// AMD. Register as an anonymous module.
20-
define(['xmlhttprequest', 'js-base64'], function (XMLHttpRequest, b64encode) {
21-
return (root.Github = factory(XMLHttpRequest.XMLHttpRequest, b64encode.Base64.encode));
22-
});
23-
} else if (typeof module === 'object' && module.exports) {
24-
if (window) {
25-
module.exports = factory(window.XMLHttpRequest, window.btoa);
26-
} else {
27-
module.exports = factory(require('xmlhttprequest').XMLHttpRequest, require('js-base64').Base64.encode);
28-
}
29-
} else {
30-
// Browser globals
31-
var b64encode = function(str) {
32-
return root.btoa(encodeURIComponent(str).replace(/%([0-9A-F]{2})/g, function(match, p1) {
33-
return String.fromCharCode('0x' + p1);
34-
}));
35-
};
36-
root.Github = factory(root.XMLHttpRequest, b64encode);
37-
}
14+
// UMD boilerplate from https://github.com/umdjs/umd/blob/master/returnExportsGlobal.js
15+
'use strict';
16+
17+
/* istanbul ignore next */
18+
if (typeof define === 'function' && define.amd) {
19+
// AMD. Register as an anonymous module.
20+
define(['xmlhttprequest', 'js-base64'], function (XMLHttpRequest, b64encode) {
21+
return (root.Github = factory(XMLHttpRequest.XMLHttpRequest, b64encode.Base64.encode));
22+
});
23+
} else if (typeof module === 'object' && module.exports) {
24+
if (typeof window !== 'undefined') { // jscs:ignore
25+
module.exports = factory(window.XMLHttpRequest, window.btoa);
26+
} else { // jscs:ignore
27+
module.exports = factory(require('xmlhttprequest').XMLHttpRequest, require('js-base64').Base64.encode);
28+
}
29+
} else {
30+
// Browser globals
31+
var b64encode = function(str) {
32+
return root.btoa(encodeURIComponent(str).replace(/%([0-9A-F]{2})/g, function(match, p1) {
33+
return String.fromCharCode('0x' + p1);
34+
}));
35+
};
36+
37+
root.Github = factory(root.XMLHttpRequest, b64encode);
38+
}
3839
}(this, function (XMLHttpRequest, b64encode) {
3940
'use strict';
4041

@@ -55,7 +56,7 @@
5556

5657
url += ((/\?/).test(url) ? '&' : '?');
5758

58-
if (data && typeof data === 'object' && ['GET', 'HEAD'].indexOf(method) > -1) {
59+
if (data && typeof data === 'object' && ['GET', 'HEAD', 'DELETE'].indexOf(method) > -1) {
5960
for(var param in data) {
6061
if (data.hasOwnProperty(param))
6162
url += '&' + encodeURIComponent(param) + '=' + encodeURIComponent(data[param]);
@@ -720,24 +721,9 @@
720721
});
721722
};
722723

723-
// Delete a file from the tree
724+
// Alias for repo.remove for backwards comapt.
724725
// -------
725-
726-
this.delete = function(branch, path, cb) {
727-
that.getSha(branch, path, function(err, sha) {
728-
if (!sha) return cb('not found', null);
729-
var delPath = repoPath + '/contents/' + path;
730-
var params = {
731-
message: 'Deleted ' + path,
732-
sha: sha
733-
};
734-
735-
delPath += '?message=' + encodeURIComponent(params.message);
736-
delPath += '&sha=' + encodeURIComponent(params.sha);
737-
delPath += '&branch=' + encodeURIComponent(branch);
738-
_request('DELETE', delPath, null, cb);
739-
});
740-
};
726+
this.delete = this.remove;
741727

742728
// Move a file to a new location
743729
// -------

test/test.repo.js

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict';
22

3-
var github, repo, user, testUser;
3+
var github, repo, user, testUser, timeout;
44

55
if (typeof window === 'undefined') {
66
// Module dependencies
@@ -11,9 +11,17 @@ if (typeof window === 'undefined') {
1111

1212
// Use should flavour for Mocha
1313
var should = chai.should();
14+
15+
// Long timeouts for Mocha.
16+
timeout = 60000;
17+
} else {
18+
// Short timeouts for Karma!
19+
timeout = 12000;
1420
}
1521

1622
describe('Github.Repository', function() {
23+
this.timeout(timeout); // Bit of a longer timeout
24+
1725
before(function() {
1826
if (typeof window !== 'undefined') testUser = window.__fixtures__['test/user'];
1927

@@ -122,6 +130,8 @@ describe('Creating new Github.Repository', function() {
122130

123131
user = github.getUser();
124132
repo = github.getRepo(testUser.USERNAME, repoTest);
133+
134+
this.timeout(timeout);
125135
});
126136

127137
it('should create repo', function(done) {
@@ -144,8 +154,6 @@ describe('Creating new Github.Repository', function() {
144154
});
145155

146156
it('should write to repo branch', function(done) {
147-
this.timeout(8000); // Bit of a longer timeout
148-
149157
repo.branch('master', 'dev', function(err) {
150158
should.not.exist(err);
151159
repo.write('dev', 'TEST.md', 'THIS IS AN UPDATED TEST', 'Updating test', function(err) {
@@ -221,6 +229,28 @@ describe('Creating new Github.Repository', function() {
221229
});
222230
});
223231

232+
it('should delete a file on the repo', function(done) {
233+
repo.write('master', 'REMOVE-TEST.md', 'THIS IS A TEST', 'Remove test', function(err) {
234+
should.not.exist(err);
235+
236+
repo.remove('master', 'REMOVE-TEST.md', function(err) {
237+
should.not.exist(err);
238+
done();
239+
});
240+
});
241+
});
242+
243+
it('should use repo.delete as an alias for repo.remove', function(done) {
244+
repo.write('master', 'REMOVE-TEST.md', 'THIS IS A TEST', 'Remove test', function(err) {
245+
should.not.exist(err);
246+
247+
repo.delete('master', 'REMOVE-TEST.md', function(err) {
248+
should.not.exist(err);
249+
done();
250+
});
251+
});
252+
});
253+
224254
it('should list pull requests on repo', function(done) {
225255
repo.listPulls('open', function(err) {
226256
should.not.exist(err);
@@ -275,8 +305,6 @@ describe('Creating new Github.Repository', function() {
275305
});
276306

277307
it('should pass a regression test for _request (#14)', function(done) {
278-
this.timeout(8000); // Bit of a longer timeout
279-
280308
repo.getRef('heads/master', function(err, sha) {
281309
var refSpec = {
282310
ref: 'refs/heads/testing-14', sha: sha

test/test.user.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict';
22

3-
var testUser, user, github;
3+
var testUser, user, github, timeout;
44

55
if (typeof window === 'undefined') {
66
// Module dependencies
@@ -11,9 +11,15 @@ if (typeof window === 'undefined') {
1111

1212
// Use should flavour for Mocha
1313
var should = chai.should();
14+
15+
timeout = 60000;
16+
} else {
17+
timeout = 12000;
1418
}
1519

1620
describe('Github.User', function() {
21+
this.timeout(timeout);
22+
1723
before(function() {
1824
if (typeof window !== 'undefined') testUser = window.__fixtures__['test/user'];
1925
github = new Github({
@@ -22,13 +28,9 @@ describe('Github.User', function() {
2228
auth: 'basic'
2329
});
2430
user = github.getUser();
25-
26-
this.timeout(8000); // Bit of a longer timeout
2731
});
2832

2933
it('should get user.repos', function(done) {
30-
this.timeout(8000); // Bit of a longer timeout
31-
3234
user.repos(function(err) {
3335
should.not.exist(err);
3436
done();

0 commit comments

Comments
 (0)