Skip to content

Commit 5e6572b

Browse files
Added Sauce Labs tests
1 parent 26ea5e4 commit 5e6572b

File tree

3 files changed

+151
-47
lines changed

3 files changed

+151
-47
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ ono (Oh No!)
1313
[![Bower](http://img.shields.io/bower/v/ono.svg)](#bower)
1414
[![License](https://img.shields.io/npm/l/ono.svg)](LICENSE)
1515

16+
[![Sauce Test Status](https://saucelabs.com/browser-matrix/bigstickcarpet-ono.svg)](https://saucelabs.com/u/bigstickcarpet-ono)
1617

1718
Features
1819
--------------------------

karma.conf.js

Lines changed: 147 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,9 @@
33
// Karma config
44
// https://karma-runner.github.io/0.12/config/configuration-file.html
55
module.exports = function(config) {
6-
var isMac = /^darwin/.test(process.platform),
7-
isWindows = /^win/.test(process.platform),
8-
isLinux = !(isMac || isWindows);
9-
10-
config.set({
6+
var baseConfig = {
117
frameworks: ['mocha', 'chai', 'sinon'],
12-
reporters: ['mocha', 'coverage'],
8+
reporters: ['mocha'],
139

1410
files: [
1511
// ono
@@ -18,31 +14,151 @@ module.exports = function(config) {
1814
// Unit tests
1915
'tests/helper.js',
2016
'tests/**/*.spec.js'
21-
],
17+
]
18+
};
2219

23-
browsers: (function() {
24-
// Test on all browsers that are available for the environment
25-
if (isMac) {
26-
return ['PhantomJS', 'Firefox', 'Chrome', 'Safari'];
27-
}
28-
else if (isWindows) {
29-
return ['PhantomJS', 'Firefox', 'Chrome', 'Safari', 'IE'];
20+
configureBrowsers(baseConfig);
21+
configureSauceLabs(baseConfig);
22+
config.set(baseConfig);
23+
};
24+
25+
/**
26+
* Configures the browsers for the current platform
27+
*/
28+
function configureBrowsers(config) {
29+
var isMac = /^darwin/.test(process.platform),
30+
isWindows = /^win/.test(process.platform),
31+
isLinux = !(isMac || isWindows);
32+
33+
if (isMac) {
34+
config.browsers = ['PhantomJS', 'Firefox', 'Chrome', 'Safari'];
35+
}
36+
else if (isLinux) {
37+
config.browsers = ['PhantomJS', 'Firefox'];
38+
}
39+
else if (isWindows) {
40+
config.browsers = ['PhantomJS', 'Firefox', 'Chrome', 'Safari', 'IE9', 'IE10', 'IE'];
41+
42+
// NOTE: IE 6, 7, 8 are not supported by Chai
43+
config.customLaunchers = {
44+
IE9: {
45+
base: 'IE',
46+
'x-ua-compatible': 'IE=EmulateIE9'
47+
},
48+
IE10: {
49+
base: 'IE',
50+
'x-ua-compatible': 'IE=EmulateIE10'
3051
}
31-
else if (isLinux) {
32-
return ['PhantomJS', 'Firefox'];
52+
};
53+
}
54+
}
55+
56+
/**
57+
* Configures Sauce Labs emulated browsers/devices.
58+
* https://github.com/karma-runner/karma-sauce-launcher
59+
*/
60+
function configureSauceLabs(config) {
61+
var username = process.env.SAUCE_USERNAME;
62+
var accessKey = process.env.SAUCE_ACCESS_KEY;
63+
var jobNumber = getJobNumber(process.env.TRAVIS_JOB_NUMBER);
64+
65+
// Only run Sauce Labs if we have the username & access key.
66+
// And only run it for the first job in a build. No need to run it for every job.
67+
if (username && accessKey && jobNumber <= 1) {
68+
var project = require('./package.json');
69+
var testName = project.name + ' v' + project.version;
70+
var build = testName + ' @ ' + new Date();
71+
72+
config.sauceLabs = {
73+
build: build,
74+
testName: testName,
75+
tags: [project.name],
76+
recordVideo: true,
77+
recordScreenshots: true
78+
};
79+
80+
config.customLaunchers = {
81+
'IE-9': {
82+
base: 'SauceLabs',
83+
platform: 'Windows 7',
84+
browserName: 'internet explorer',
85+
version: '9'
86+
},
87+
'IE-10': {
88+
base: 'SauceLabs',
89+
platform: 'Windows 7',
90+
browserName: 'internet explorer',
91+
version: '10'
92+
},
93+
'IE-11': {
94+
base: 'SauceLabs',
95+
platform: 'Windows 7',
96+
browserName: 'internet explorer',
97+
version: '11'
98+
},
99+
'Chrome-Latest': {
100+
base: 'SauceLabs',
101+
platform: 'Windows 7',
102+
browserName: 'chrome'
103+
},
104+
'Firefox-Latest': {
105+
base: 'SauceLabs',
106+
platform: 'Windows 7',
107+
browserName: 'firefox'
108+
},
109+
'Opera-Latest': {
110+
base: 'SauceLabs',
111+
platform: 'Windows 7',
112+
browserName: 'opera'
113+
},
114+
'Safari-Latest': {
115+
base: 'SauceLabs',
116+
platform: 'OS X 10.10',
117+
browserName: 'safari'
118+
},
119+
'iOS-6': {
120+
base: 'SauceLabs',
121+
platform: 'OS X 10.10',
122+
browserName: 'iphone',
123+
version: '6'
124+
},
125+
'iOS-8': {
126+
base: 'SauceLabs',
127+
platform: 'OS X 10.10',
128+
browserName: 'iphone',
129+
version: '8'
130+
},
131+
'Android-4-4': {
132+
base: 'SauceLabs',
133+
platform: 'Linux',
134+
browserName: 'android',
135+
version: '4.4'
136+
},
137+
'Android-5': {
138+
base: 'SauceLabs',
139+
platform: 'Linux',
140+
browserName: 'android',
141+
version: '5'
33142
}
34-
})(),
35-
36-
coverageReporter: {
37-
reporters: [
38-
{type: 'text-summary'},
39-
{
40-
type: 'lcov',
41-
subdir: function(browser) {
42-
return browser.toLowerCase().split(/[ /-]/)[0];
43-
}
44-
},
45-
]
46-
}
47-
});
48-
};
143+
};
144+
145+
config.reporters.push('saucelabs');
146+
config.browsers = Object.keys(config.customLaunchers);
147+
}
148+
}
149+
150+
/**
151+
* Returns the Travis CI job number, or 1 if there is no job number.
152+
*
153+
* Examples:
154+
* - "4.1" -> 1
155+
* - "16.2" -> 2
156+
* - "16" -> 1
157+
* - "" -> 1
158+
* - null -> 1
159+
*/
160+
function getJobNumber(number) {
161+
var match = /\.(\d+)/.exec(number);
162+
var job = match ? match[1] || '1' : '1';
163+
return parseInt(job);
164+
}

package.json

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -31,20 +31,6 @@
3131
"bump": "bump --prompt --tag --push --all",
3232
"release": "npm run upgrade && npm run build && npm test && npm run bump && npm publish"
3333
},
34-
"testling": {
35-
"harness": "mocha",
36-
"files": "tests/**/*.js",
37-
"browsers": [
38-
"ie/6..latest",
39-
"chrome/22..latest",
40-
"firefox/16..latest",
41-
"safari/5.0..latest",
42-
"opera/11.0..latest",
43-
"iphone/6..latest",
44-
"ipad/6..latest",
45-
"android-browser/4.2..latest"
46-
]
47-
},
4834
"repository": {
4935
"type": "git",
5036
"url": "https://github.com/bigstickcarpet/ono.git"
@@ -53,7 +39,7 @@
5339
"chai": "^3.2.0",
5440
"coveralls": "^2.11.3",
5541
"istanbul": "^0.3.17",
56-
"jscs": "^1.13.1",
42+
"jscs": "^2.0.0",
5743
"jshint": "^2.8.0",
5844
"karma": "^0.13.3",
5945
"karma-chai": "^0.1.0",
@@ -66,6 +52,7 @@
6652
"karma-mocha-reporter": "^1.0.3",
6753
"karma-phantomjs-launcher": "^0.2.0",
6854
"karma-safari-launcher": "^0.1.1",
55+
"karma-sauce-launcher": "^0.2.14",
6956
"karma-sinon": "^1.0.4",
7057
"mocha": "^2.2.5",
7158
"npm-check-updates": "^1.5.1",
@@ -75,4 +62,4 @@
7562
"version-bump-prompt": "^1.4.2"
7663
},
7764
"dependencies": {}
78-
}
65+
}

0 commit comments

Comments
 (0)