Skip to content

Commit d2fc035

Browse files
author
Ændrew Rininsland
committed
Fixing tests, reverting PhantomJS, adding Sauce Labs support.
1 parent ee3206b commit d2fc035

File tree

6 files changed

+337
-60
lines changed

6 files changed

+337
-60
lines changed

.travis.yml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
language: node_js
2+
23
sudo: false
4+
35
node_js:
46
- "4.1"
57
- "4.0"
68
- "0.12"
79
- "0.11"
810
- "0.10"
11+
912
script:
10-
- npm test
13+
- gulp lint
14+
- gulp test:ci
1115
- mocha test/ --timeout=60000
1216
- npm run-script codecov
13-
14-
before_script:
15-
- npm install -g phantomjs2

gulpfile.js

Lines changed: 97 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,56 @@ var stylish = require('gulp-jscs-stylish');
99
var path = require('path');
1010
var karma = require('karma');
1111

12+
function runTests(singleRun, isCI, done) {
13+
var reporters = ['mocha'];
14+
var preprocessors = {};
15+
16+
var files = [
17+
path.join(__dirname, 'test/vendor/*.js'), // PhantomJS 1.x polyfills
18+
path.join(__dirname, 'github.js'),
19+
path.join(__dirname, 'test/*.js')
20+
];
21+
22+
if (singleRun) {
23+
files.forEach(function(path) {
24+
preprocessors[path] = ['coverage'];
25+
});
26+
reporters.push('coverage');
27+
}
28+
29+
files.push(path.join(__dirname, 'test/user.json'));
30+
files.push({
31+
pattern: path.join(__dirname, 'test/gh.png'),
32+
watched: false,
33+
included: false
34+
});
35+
preprocessors['test/user.json'] = ['json_fixtures'];
36+
37+
var localConfig = {
38+
files: files,
39+
configFile: path.join(__dirname, './karma.conf.js'),
40+
singleRun: singleRun,
41+
autoWatch: !singleRun,
42+
reporters: reporters,
43+
preprocessors: preprocessors
44+
};
45+
46+
if (isCI) {
47+
localConfig.sauceLabs = {
48+
testName: 'GitHub.js UAT tests'
49+
};
50+
localConfig.customLaunchers = sauceLaunchers;
51+
localConfig.browsers = Object.keys(sauceLaunchers);
52+
reporters.push('saucelabs');
53+
}
54+
55+
var server = new karma.Server(localConfig, function(failCount) {
56+
done(failCount ? new Error('Failed ' + failCount + ' tests.') : null);
57+
});
58+
59+
server.start();
60+
} // End runTests()
61+
1262
gulp.task('lint', function() {
1363
return gulp.src([
1464
path.join(__dirname, '/*.js'),
@@ -28,11 +78,15 @@ gulp.task('lint', function() {
2878
});
2979

3080
gulp.task('test', function(done) {
31-
runTests(true, done);
81+
runTests(true, false, done);
82+
});
83+
84+
gulp.task('test:ci', function(done) {
85+
runTests(true, true, done);
3286
});
3387

3488
gulp.task('test:auto', function(done) {
35-
runTests(false, done);
89+
runTests(false, false, done);
3690
});
3791

3892
gulp.task('build', function() {
@@ -46,42 +100,45 @@ gulp.task('default', function() {
46100
gulp.start('lint', 'test', 'build');
47101
});
48102

49-
function runTests (singleRun, done) {
50-
var reporters = ['mocha'];
51-
var preprocessors = {};
52-
53-
var files = [
54-
path.join(__dirname, 'github.js'),
55-
path.join(__dirname, 'test/*.js')
56-
];
57-
58-
if (singleRun) {
59-
files.forEach(function(path) {
60-
preprocessors[path] = ['coverage'];
61-
});
62-
reporters.push('coverage');
103+
var sauceLaunchers = {
104+
SL_Chrome: {
105+
base: 'SauceLabs',
106+
browserName: 'chrome',
107+
version: '45'
108+
},
109+
SL_Firefox: {
110+
base: 'SauceLabs',
111+
browserName: 'firefox',
112+
version: '39'
113+
},
114+
SL_Safari: {
115+
base: 'SauceLabs',
116+
browserName: 'safari',
117+
platform: 'OS X 10.10',
118+
version: '8'
119+
},
120+
SL_IE_9: {
121+
base: 'SauceLabs',
122+
browserName: 'internet explorer',
123+
platform: 'Windows 2008',
124+
version: '9'
125+
},
126+
SL_IE_10: {
127+
base: 'SauceLabs',
128+
browserName: 'internet explorer',
129+
platform: 'Windows 2012',
130+
version: '10'
131+
},
132+
SL_IE_11: {
133+
base: 'SauceLabs',
134+
browserName: 'internet explorer',
135+
platform: 'Windows 8.1',
136+
version: '11'
137+
},
138+
SL_iOS: {
139+
base: 'SauceLabs',
140+
browserName: 'iphone',
141+
platform: 'OS X 10.10',
142+
version: '8.1'
63143
}
64-
65-
files.push(path.join(__dirname, 'test/user.json'));
66-
files.push({
67-
pattern: path.join(__dirname, 'test/gh.png'),
68-
watched: false,
69-
included: false
70-
});
71-
preprocessors['test/user.json'] = ['json_fixtures'];
72-
73-
var localConfig = {
74-
files: files,
75-
configFile: path.join(__dirname, './karma.conf.js'),
76-
singleRun: singleRun,
77-
autoWatch: !singleRun,
78-
reporters: reporters,
79-
preprocessors: preprocessors
80-
};
81-
82-
var server = new karma.Server(localConfig, function(failCount) {
83-
done(failCount ? new Error('Failed ' + failCount + ' tests.') : null);
84-
});
85-
86-
server.start();
87-
}
144+
};

karma.conf.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ module.exports = function(config) {
1212

1313
frameworks: ['mocha', 'chai'],
1414

15-
browsers: ['PhantomJS2'],
15+
browsers: ['PhantomJS'],
1616

1717
coverageReporter: {
1818
reporters: [

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"main": "github.js",
66
"dependencies": {
77
"js-base64": "^2.1.8",
8+
"karma-phantomjs-launcher": "^0.2.1",
89
"xmlhttprequest": "~1.7.0"
910
},
1011
"devDependencies": {
@@ -25,7 +26,7 @@
2526
"karma-json-fixtures-preprocessor": "0.0.5",
2627
"karma-mocha": "^0.2.0",
2728
"karma-mocha-reporter": "^1.1.1",
28-
"karma-phantomjs2-launcher": "^0.3.2",
29+
"karma-sauce-launcher": "^0.3.0",
2930
"mocha": "^2.3.3"
3031
},
3132
"scripts": {

test/test.repo.js

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,25 +21,32 @@ if (typeof window === 'undefined') { // We're in NodeJS
2121
imageBlob = fs.readFileSync(path.join(__dirname, 'gh.png')); // This is a Buffer().
2222
imageB64 = imageBlob.toString('base64');
2323
} else { // We're in the browser
24-
// Shorter timeouts for Karma!
25-
timeout = 12000;
24+
timeout = 12000; // Shorter timeouts for Karma!
2625

27-
var xhr = new XMLHttpRequest();
26+
if (typeof window._phantom !== 'undefined') {
27+
var xhr = new XMLHttpRequest();
2828

29-
xhr.responseType = 'blob';
30-
xhr.open('GET', 'base/test/gh.png');
31-
xhr.onload = function() {
32-
var reader = new FileReader();
29+
xhr.responseType = 'blob';
30+
xhr.open('GET', 'base/test/gh.png');
31+
xhr.onload = function() {
32+
var reader = new FileReader();
3333

34-
reader.onloadend = function() {
35-
imageB64 = btoa(reader.result);
36-
imageBlob = reader.result;
37-
};
34+
reader.onloadend = function() {
35+
imageB64 = btoa(reader.result);
36+
imageBlob = reader.result;
37+
console.log(imageBlob);
38+
};
3839

39-
reader.readAsBinaryString(xhr.response);
40-
};
40+
reader.readAsBinaryString(xhr.response);
41+
};
4142

42-
xhr.send();
43+
xhr.send();
44+
} else {
45+
// jscs:disable
46+
imageB64 = 'iVBORw0KGgoAAAANSUhEUgAAACsAAAAmCAAAAAB4qD3CAAABgElEQVQ4y9XUsUocURQGYN/pAyMWBhGtrEIMiFiooGuVIoYsSBAsRSQvYGFWC4uFhUBYsilXLERQsDA20YAguIbo5PQp3F3inVFTheSvZoavGO79z+mJP0/Pv2nPtlfLpfLq9tljNquO62S8mj1kmy/8nrHm/Xaz1930bt5n1+SzVmyrilItsod9ON0td1V59xR9hwV2HsMRsbfROLo4amzsRcQw5vO2CZPJEU5CM2cXYTCxg7CY2mwIVhK7AkNZYg9g4CqxVwNwkNg6zOTKMQP1xFZgKWeXoJLYdSjl7BysJ7YBIzk7Ap8TewLOE3oOTtIz6y/64bfQn55ZTIAPd2gNTOTurcbzp7z50v1y/Pq2Q7Wczca8vFjG6LvbMo92hiPL96xO+eYVPkVExMdONetFXZ+l+eP9cuV7RER8a9PZwrloTXv2tfv285ZOt4rnrTXlydxCu9sZmGrdN8eXC3ATERHXsHD5wC7ZL3HdsaX9R3bUzlb7YWvn/9ipf93+An8cHsx3W3WHAAAAAElFTkSuQmCC';
47+
imageBlob = new Blob();
48+
// jscs:enable
49+
}
4350
}
4451

4552
describe('Github.Repository', function() {

0 commit comments

Comments
 (0)