Skip to content

Commit e20a003

Browse files
committed
Travis + SauceLabs + Karma setup (second pass)
- add note about exporting `global` in `browser-entry.js` - remove too-short timeout for "throw" unit tests (because SauceLabs) - revert modification to `isatty()` function of `lib/browser/tty.js` - switch reporter to `karma-spec-reporter` - use custom `karma-no-mocha` package - fixtures in `test/browser-fixtures/` - use single `karma.conf.js`
1 parent c962a51 commit e20a003

File tree

14 files changed

+4729
-4459
lines changed

14 files changed

+4729
-4459
lines changed

.karma-config/fixture.js

Lines changed: 0 additions & 4 deletions
This file was deleted.

.karma-config/index.js

Lines changed: 0 additions & 74 deletions
This file was deleted.

Makefile

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,19 +48,19 @@ test: lint test-node test-browser
4848

4949
test-browser-unit: mocha.js
5050
@printf "==> [Test :: Browser]\n"
51-
@$(KARMA) start
51+
@NODE_PATH=. $(KARMA) start
5252

5353
test-browser-bdd:
5454
@printf "==> [Test :: Browser :: BDD]\n"
55-
@KARMA_INTERFACE=bdd $(MAKE) test-browser-unit
55+
@MOCHA_UI=bdd $(MAKE) test-browser-unit
5656

5757
test-browser-qunit:
5858
@printf "==> [Test :: Browser :: QUnit]\n"
59-
@KARMA_INTERFACE=qunit $(MAKE) test-browser-unit
59+
@MOCHA_UI=qunit $(MAKE) test-browser-unit
6060

6161
test-browser-tdd:
6262
@printf "==> [Test :: Browser :: TDD]\n"
63-
@KARMA_INTERFACE=tdd $(MAKE) test-browser-unit
63+
@MOCHA_UI=tdd $(MAKE) test-browser-unit
6464

6565
test-jsapi:
6666
@printf "==> [Test :: JS API]\n"

browser-entry.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,4 +160,7 @@ Mocha.process = process;
160160
global.Mocha = Mocha;
161161
global.mocha = mocha;
162162

163+
// this allows test/acceptance/required-tokens.js to pass; thus,
164+
// you can now do `const describe = require('mocha').describe` in a
165+
// browser context (assuming browserification). should fix #880
163166
module.exports = global;

karma.conf.js

Lines changed: 88 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,96 @@
1-
var getConfig = require('./.karma-config');
1+
'use strict';
22

33
module.exports = function(config) {
4-
var cfg = getConfig();
5-
var ui = process.env.KARMA_INTERFACE;
4+
var cfg = {
5+
frameworks: [
6+
'browserify',
7+
'expect',
8+
'mocha'
9+
],
10+
files: [
11+
'test/browser-fixtures/bdd.js',
12+
'test/acceptance/*.js'
13+
],
14+
exclude: [
15+
'test/acceptance/http.js',
16+
'test/acceptance/fs.js',
17+
'test/acceptance/lookup-files.js',
18+
'test/acceptance/require/**/*.js',
19+
'test/acceptance/misc/**/*.js'
20+
],
21+
preprocessors: {
22+
'test/**/*.js': ['browserify']
23+
},
24+
browserify: {
25+
debug: true,
26+
configure: function configure(b) {
27+
b.ignore('glob')
28+
.ignore('jade')
29+
.ignore('supports-color')
30+
.exclude('./lib-cov/mocha');
31+
}
32+
},
33+
reporters: ['spec'],
34+
colors: true,
35+
browsers: ['PhantomJS'],
36+
logLevel: config.LOG_INFO,
37+
singleRun: true
38+
};
39+
40+
// see https://github.com/saucelabs/karma-sauce-example
41+
// TO RUN LOCALLY:
42+
// Execute `CI=1 make test-browser`, once you've set the SAUCE_USERNAME and
43+
// SAUCE_ACCESS_KEY env vars.
44+
if (process.env.CI) {
45+
if (!(process.env.SAUCE_USERNAME || process.env.SAUCE_ACCESS_KEY)) {
46+
throw new Error('Must set SAUCE_USERNAME and SAUCE_ACCESS_KEY '
47+
+ 'environment variables!');
48+
}
49+
cfg.reporters.push('saucelabs');
50+
cfg.browsers.push('ie8');
51+
cfg.customLaunchers = {
52+
ie8: {
53+
base: 'SauceLabs',
54+
browserName: 'internet explorer',
55+
platform: 'Windows XP',
56+
version: '8.0'
57+
}
58+
};
59+
60+
cfg.sauceLabs = {
61+
public: 'public'
62+
};
63+
64+
if (process.env.TRAVIS) {
65+
// correlate build/tunnel with Travis
66+
cfg.sauceLabs.build = 'TRAVIS #' + process.env.TRAVIS_BUILD_NUMBER
67+
+ ' (' + process.env.TRAVIS_BUILD_ID + ')';
68+
cfg.sauceLabs.tunnelIdentifier = process.env.TRAVIS_JOB_NUMBER;
69+
cfg.sauceLabs.startConnect = false;
70+
} else {
71+
// otherwise just make something up
72+
cfg.sauceLabs.build = require('os').hostname() + ' (' + Date.now() + ')';
73+
}
74+
75+
// for slow browser booting, ostensibly
76+
cfg.captureTimeout = 120000;
77+
}
78+
79+
// the MOCHA_UI env var will determine if we're running interface-specific
80+
// tets. since you can only load one at a time, each must be run separately.
81+
// each has its own set of acceptance tests and a fixture.
82+
// the "bdd" fixture is used by default.
83+
var ui = process.env.MOCHA_UI;
684
if (ui) {
85+
if (cfg.sauceLabs) {
86+
cfg.sauceLabs.testName = 'Interface "' + ui + '" integration tests';
87+
}
788
cfg.files = [
8-
getConfig.uiFixturePaths[ui],
9-
'./test/acceptance/interfaces/' + ui + '.js'
89+
'test/browser-fixtures/' + ui + '.js',
90+
'test/acceptance/interfaces/' + ui + '.js'
1091
];
92+
} else if (cfg.sauceLabs) {
93+
cfg.sauceLabs.testName = 'Unit Tests';
1194
}
1295

1396
config.set(cfg);

lib/browser/tty.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
exports.isatty = function isatty() {
2-
return false;
2+
return true;
33
};
44

55
exports.getWindowSize = function getWindowSize() {

0 commit comments

Comments
 (0)