11'use strict' ;
22
3- var github , repo , user , testUser , timeout ;
3+ var github , repo , user , testUser , timeout , imageB64 , imageBlob ;
44
5- if ( typeof window === 'undefined' ) {
5+ if ( typeof window === 'undefined' ) { // We're in NodeJS
66 // Module dependencies
77 var chai = require ( 'chai' ) ;
88 var Github = require ( '../' ) ;
@@ -14,9 +14,32 @@ if (typeof window === 'undefined') {
1414
1515 // Long timeouts for Mocha.
1616 timeout = 60000 ;
17- } else {
18- // Short timeouts for Karma!
17+
18+ var fs = require ( 'fs' ) ;
19+ var path = require ( 'path' ) ;
20+
21+ imageBlob = fs . readFileSync ( path . join ( __dirname , 'gh.png' ) ) ; // This is a Buffer().
22+ imageB64 = imageBlob . toString ( 'base64' ) ;
23+ } else { // We're in the browser
24+ // Shorter timeouts for Karma!
1925 timeout = 12000 ;
26+
27+ var xhr = new XMLHttpRequest ( ) ;
28+
29+ xhr . responseType = 'blob' ;
30+ xhr . open ( 'GET' , 'base/test/gh.png' ) ;
31+ xhr . onload = function ( ) {
32+ var reader = new FileReader ( ) ;
33+
34+ reader . onloadend = function ( ) {
35+ imageB64 = btoa ( reader . result ) ;
36+ imageBlob = reader . result ;
37+ } ;
38+
39+ reader . readAsBinaryString ( xhr . response ) ;
40+ } ;
41+
42+ xhr . send ( ) ;
2043}
2144
2245describe ( 'Github.Repository' , function ( ) {
@@ -216,13 +239,13 @@ describe('Creating new Github.Repository', function() {
216239 sort : 'updated' ,
217240 direction : 'desc' ,
218241 page : 1 ,
219- per_page : 100
242+ per_page : 10
220243 } ;
221244
222245 repo . listPulls ( options , function ( err , pull_list ) {
223246 should . not . exist ( err ) ;
224247 pull_list . should . be . instanceof ( Array ) ;
225- pull_list . should . have . length ( 100 ) ;
248+ pull_list . should . have . length ( 10 ) ;
226249 should . exist ( pull_list [ 0 ] . title ) ;
227250 should . exist ( pull_list [ 0 ] . body ) ;
228251 should . exist ( pull_list [ 0 ] . url ) ;
@@ -300,6 +323,7 @@ describe('Creating new Github.Repository', function() {
300323 repo . write ( 'master' , 'TEST_unicode.md' , '\u2014' , 'Long dash unicode' , function ( err ) {
301324 should . not . exist ( err ) ;
302325
326+ if ( err ) console . log ( err ) ;
303327 repo . read ( 'master' , 'TEST_unicode.md' , function ( err , obj ) {
304328 should . not . exist ( err ) ;
305329 obj . should . equal ( '\u2014' ) ;
@@ -334,6 +358,27 @@ describe('Creating new Github.Repository', function() {
334358 } ) ;
335359 } ) ;
336360 } ) ;
361+
362+ it ( 'should be able to write an image to the repo' , function ( done ) {
363+ repo . write ( 'master' , 'TEST_image.png' , imageB64 , 'Image test' , {
364+ encode : false
365+ } , function ( err ) {
366+ if ( err ) console . log ( err ) ;
367+ should . not . exist ( err ) ;
368+ done ( ) ;
369+ } ) ;
370+ } ) ;
371+
372+ it ( 'should be able to write a blob to the repo' , function ( done ) {
373+ repo . postBlob ( 'String test' , function ( err ) { // Test strings
374+ should . not . exist ( err ) ;
375+
376+ repo . postBlob ( imageBlob , function ( err ) { // Test non-strings
377+ should . not . exist ( err ) ;
378+ done ( ) ;
379+ } ) ;
380+ } ) ;
381+ } ) ;
337382} ) ;
338383
339384describe ( 'deleting a Github.Repository' , function ( ) {
0 commit comments