Skip to content

Commit 4fb5836

Browse files
Refactored the build/test/CI scripts
1 parent 3e19a81 commit 4fb5836

File tree

19 files changed

+1081
-177
lines changed

19 files changed

+1081
-177
lines changed

.jshintrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,5 +80,6 @@
8080
// Custom Globals
8181
"globals": {
8282
}
83+
8384
}
8485

.npmignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ npm-debug.log
55
/.idea
66
/coverage
77
/dist/*.test.js
8+
karma.conf.js
89
/tests
910
/www
11+
bower.json
12+
index.html
1013
/.*

.travis.yml

Lines changed: 36 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,43 @@
33

44
sudo: false
55
language: node_js
6-
node_js:
7-
- 'iojs'
8-
- '0.10'
9-
- '0.11'
10-
- '0.12'
11-
branches:
12-
only:
13-
- /^v\d\.\d\.\d/ # only build tagged versions (rather than EVERY push)
14-
- /^PR / # also build pull requests
6+
matrix:
7+
include:
8+
# IO.js
9+
- node_js: iojs
10+
env: KARMA=false
11+
12+
# Node
13+
- node_js: 0.10
14+
env: KARMA=false
15+
- node_js: 0.11
16+
env: KARMA=false
17+
- node_js: 0.12
18+
env: KARMA=false
19+
20+
# Local Browsers
21+
- node_js: 0.12
22+
env: KARMA_COVERAGE=true KARMA_SAUCE=false
23+
24+
# Sauce Labs
25+
- node_js: 0.12
26+
env: KARMA_SAUCE=true KARMA_COVERAGE=false
27+
28+
fast_finish: true
29+
allow_failures:
30+
- node_js: 0.12
31+
env: KARMA_SAUCE=true KARMA_COVERAGE=false
32+
1533
before_script:
1634
- export DISPLAY=:99.0
1735
- sh -e /etc/init.d/xvfb start
18-
- npm run build
36+
- npm update -g npm
37+
branches:
38+
only:
39+
- master # only run CI on the master branch
40+
- /^PR / # also build pull requests
1941
after_success:
20-
- cat coverage/lcov.info | node_modules/coveralls/bin/coveralls.js
42+
- cat coverage/*/lcov.info > coveralls.txt # concatenate all code-coverage data into a single file
43+
- cat coveralls.txt # output the file contents (for debugging)
44+
- ls -R1 coverage/*/lcov.info # list the files (for debugging)
45+
- cat coveralls.txt | node_modules/coveralls/bin/coveralls.js # send code-coverage data to Coveralls

karma.conf.js

Lines changed: 138 additions & 131 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,74 @@
1-
'use strict';
2-
31
// Karma config
42
// https://karma-runner.github.io/0.12/config/configuration-file.html
3+
'use strict';
4+
5+
var baseConfig = {
6+
frameworks: ['mocha'],
7+
reporters: ['mocha'],
8+
files: [
9+
// Third-Party Libraries
10+
'tests/bower_components/chai/chai.js',
11+
'tests/bower_components/sinon-js/sinon.js',
12+
'tests/bower_components/useragent-parser/src/useragent-parser.js',
13+
14+
// Ono
15+
'dist/ono.min.js',
16+
{pattern: 'dist/*.map', included: false, served: true},
17+
18+
// Test Fixtures
19+
'tests/fixtures/**/*.js',
20+
21+
// Tests
22+
'tests/specs/**/*.spec.js'
23+
]
24+
};
25+
526
module.exports = function(config) {
6-
var baseConfig = {
7-
frameworks: ['mocha'],
8-
reporters: ['mocha'],
9-
files: [
10-
// Third-Party Libraries
11-
'www/bower_components/chai/chai.js',
12-
'www/bower_components/sinon-js/sinon.js',
13-
'www/bower_components/useragent-parser/src/useragent-parser.js',
14-
15-
// Ono
16-
'dist/ono.min.js',
17-
18-
// Unit Tests
19-
'tests/**/_*.js',
20-
'tests/**/*.spec.js'
21-
]
22-
};
27+
var karma = process.env.KARMA ? process.env.KARMA === 'true' : true;
28+
var coverage = process.env.KARMA_COVERAGE ? process.env.KARMA_COVERAGE === 'true' : true;
29+
var sauce = process.env.KARMA_SAUCE ? process.env.KARMA_SAUCE === 'true' : true;
30+
var sauceUsername = process.env.SAUCE_USERNAME;
31+
var sauceAccessKey = process.env.SAUCE_ACCESS_KEY;
2332

24-
configureBrowsers(baseConfig);
25-
configureSauceLabs(baseConfig);
33+
if (!karma) {
34+
// Karma is disabled, so abort immediately
35+
process.exit();
36+
return;
37+
}
38+
39+
if (coverage) {
40+
configureCodeCoverage(baseConfig);
41+
}
42+
43+
if (sauce && sauceUsername && sauceAccessKey) {
44+
configureSauceLabs(baseConfig);
45+
}
46+
else {
47+
configureLocalBrowsers(baseConfig);
48+
}
49+
50+
console.log('Karma Config:\n', JSON.stringify(baseConfig, null, 2));
2651
config.set(baseConfig);
2752
};
2853

54+
/**
55+
* Configures the code-coverage reporter
56+
*/
57+
function configureCodeCoverage(config) {
58+
config.reporters.push('coverage');
59+
config.files.splice(config.files.indexOf('dist/ono.min.js'), 1, 'dist/ono.test.js');
60+
config.coverageReporter = {
61+
reporters: [
62+
{type: 'text-summary'},
63+
{type: 'lcov'}
64+
]
65+
};
66+
}
67+
2968
/**
3069
* Configures the browsers for the current platform
3170
*/
32-
function configureBrowsers(config) {
71+
function configureLocalBrowsers(config) {
3372
var isMac = /^darwin/.test(process.platform),
3473
isWindows = /^win/.test(process.platform),
3574
isLinux = !(isMac || isWindows);
@@ -42,9 +81,8 @@ function configureBrowsers(config) {
4281
}
4382
else if (isWindows) {
4483
config.browsers = ['PhantomJS', 'Firefox', 'Chrome', 'Safari', 'IE9', 'IE10', 'IE'];
45-
46-
// NOTE: IE 6, 7, 8 are not supported by Chai
4784
config.customLaunchers = {
85+
// NOTE: IE 6, 7, 8 are not supported by Chai
4886
IE9: {
4987
base: 'IE',
5088
'x-ua-compatible': 'IE=EmulateIE9'
@@ -62,114 +100,83 @@ function configureBrowsers(config) {
62100
* https://github.com/karma-runner/karma-sauce-launcher
63101
*/
64102
function configureSauceLabs(config) {
65-
var username = process.env.SAUCE_USERNAME;
66-
var accessKey = process.env.SAUCE_ACCESS_KEY;
67-
var jobNumber = getJobNumber(process.env.TRAVIS_JOB_NUMBER);
68-
69-
// Only run Sauce Labs if we have the username & access key.
70-
// And only run it for the first job in a build. No need to run it for every job.
71-
if (username && accessKey && jobNumber <= 1) {
72-
var project = require('./package.json');
73-
var testName = project.name + ' v' + project.version;
74-
var build = testName + ' Build #' + process.env.TRAVIS_JOB_NUMBER + ' @ ' + new Date();
75-
76-
config.sauceLabs = {
77-
build: build,
78-
testName: testName,
79-
tags: [project.name],
80-
recordVideo: true,
81-
recordScreenshots: true
82-
};
103+
var project = require('./package.json');
104+
var testName = project.name + ' v' + project.version;
105+
var build = testName + ' Build #' + process.env.TRAVIS_JOB_NUMBER + ' @ ' + new Date();
83106

84-
config.customLaunchers = {
85-
'IE-9': {
86-
base: 'SauceLabs',
87-
platform: 'Windows 7',
88-
browserName: 'internet explorer',
89-
version: '9'
90-
},
91-
'IE-10': {
92-
base: 'SauceLabs',
93-
platform: 'Windows 7',
94-
browserName: 'internet explorer',
95-
version: '10'
96-
},
97-
'IE-11': {
98-
base: 'SauceLabs',
99-
platform: 'Windows 7',
100-
browserName: 'internet explorer',
101-
version: '11'
102-
},
103-
'Chrome-Latest': {
104-
base: 'SauceLabs',
105-
platform: 'Windows 7',
106-
browserName: 'chrome'
107-
},
108-
'Firefox-Latest': {
109-
base: 'SauceLabs',
110-
platform: 'Windows 7',
111-
browserName: 'firefox'
112-
},
113-
'Opera-Latest': {
114-
base: 'SauceLabs',
115-
platform: 'Windows 7',
116-
browserName: 'opera'
117-
},
118-
'Safari-Latest': {
119-
base: 'SauceLabs',
120-
platform: 'OS X 10.10',
121-
browserName: 'safari'
122-
},
123-
'iOS-6': {
124-
base: 'SauceLabs',
125-
platform: 'OS X 10.10',
126-
browserName: 'iphone',
127-
version: '6'
128-
},
129-
'iOS-8': {
130-
base: 'SauceLabs',
131-
platform: 'OS X 10.10',
132-
browserName: 'iphone',
133-
version: '8'
134-
},
135-
'Android-4-4': {
136-
base: 'SauceLabs',
137-
platform: 'Linux',
138-
browserName: 'android',
139-
version: '4.4'
140-
},
141-
'Android-5': {
142-
base: 'SauceLabs',
143-
platform: 'Linux',
144-
browserName: 'android',
145-
version: '5'
146-
}
147-
};
148-
149-
config.reporters.push('saucelabs');
150-
config.browsers = Object.keys(config.customLaunchers);
107+
config.sauceLabs = {
108+
build: build,
109+
testName: testName,
110+
tags: [project.name],
111+
recordVideo: true,
112+
recordScreenshots: true
113+
};
151114

152-
// Sauce Connect sometimes hangs (https://github.com/karma-runner/karma-sauce-launcher/issues/14)
153-
// So terminate the process after a few minutes
154-
setTimeout(function() {
155-
console.warn('\nWARNING: Sauce Connect appears to have hung. Forcefully terminating.\n');
156-
process.exit();
157-
}, 1000 * 60 * 8); // 8 minutes
158-
}
159-
}
115+
config.customLaunchers = {
116+
'IE-9': {
117+
base: 'SauceLabs',
118+
platform: 'Windows 7',
119+
browserName: 'internet explorer',
120+
version: '9'
121+
},
122+
'IE-10': {
123+
base: 'SauceLabs',
124+
platform: 'Windows 7',
125+
browserName: 'internet explorer',
126+
version: '10'
127+
},
128+
'IE-11': {
129+
base: 'SauceLabs',
130+
platform: 'Windows 7',
131+
browserName: 'internet explorer',
132+
version: '11'
133+
},
134+
'Chrome-Latest': {
135+
base: 'SauceLabs',
136+
platform: 'Windows 7',
137+
browserName: 'chrome'
138+
},
139+
'Firefox-Latest': {
140+
base: 'SauceLabs',
141+
platform: 'Windows 7',
142+
browserName: 'firefox'
143+
},
144+
'Opera-Latest': {
145+
base: 'SauceLabs',
146+
platform: 'Windows 7',
147+
browserName: 'opera'
148+
},
149+
'Safari-Latest': {
150+
base: 'SauceLabs',
151+
platform: 'OS X 10.10',
152+
browserName: 'safari'
153+
},
154+
'iOS-6': {
155+
base: 'SauceLabs',
156+
platform: 'OS X 10.10',
157+
browserName: 'iphone',
158+
version: '6'
159+
},
160+
'iOS-8': {
161+
base: 'SauceLabs',
162+
platform: 'OS X 10.10',
163+
browserName: 'iphone',
164+
version: '8'
165+
},
166+
'Android-4-4': {
167+
base: 'SauceLabs',
168+
platform: 'Linux',
169+
browserName: 'android',
170+
version: '4.4'
171+
},
172+
'Android-5': {
173+
base: 'SauceLabs',
174+
platform: 'Linux',
175+
browserName: 'android',
176+
version: '5'
177+
}
178+
};
160179

161-
/**
162-
* Returns the Travis CI job number, or 1 if there is no job number.
163-
*
164-
* Examples:
165-
* - "4.1" -> 1
166-
* - "16.2" -> 2
167-
* - "16" -> 1
168-
* - "" -> 1
169-
* - null -> 1
170-
*/
171-
function getJobNumber(number) {
172-
var match = /\.(\d+)/.exec(number);
173-
var job = match ? match[1] || '1' : '1';
174-
return parseInt(job);
180+
config.reporters.push('saucelabs');
181+
config.browsers = Object.keys(config.customLaunchers);
175182
}

0 commit comments

Comments
 (0)