-
-
Notifications
You must be signed in to change notification settings - Fork 3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make CI run browser tests #2231
Changes from all commits
3ad9c4e
2ead281
e7e8554
8ee7795
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,7 @@ | |
|
||
process.stdout = require('browser-stdout')(); | ||
|
||
var Mocha = require('../'); | ||
var Mocha = require('./lib/mocha'); | ||
|
||
/** | ||
* Create a Mocha instance. | ||
|
@@ -159,3 +159,8 @@ Mocha.process = process; | |
|
||
global.Mocha = Mocha; | ||
global.mocha = mocha; | ||
|
||
// this allows test/acceptance/required-tokens.js to pass; thus, | ||
// you can now do `const describe = require('mocha').describe` in a | ||
// browser context (assuming browserification). should fix #880 | ||
module.exports = global; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this needs explanation. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
'use strict'; | ||
|
||
module.exports = function(config) { | ||
var cfg = { | ||
frameworks: [ | ||
'browserify', | ||
'expect', | ||
'mocha' | ||
], | ||
files: [ | ||
'test/browser-fixtures/bdd.js', | ||
'test/acceptance/*.js' | ||
], | ||
exclude: [ | ||
'test/acceptance/http.js', | ||
'test/acceptance/fs.js', | ||
'test/acceptance/lookup-files.js', | ||
'test/acceptance/require/**/*.js', | ||
'test/acceptance/misc/**/*.js' | ||
], | ||
preprocessors: { | ||
'test/**/*.js': ['browserify'] | ||
}, | ||
browserify: { | ||
debug: true, | ||
configure: function configure(b) { | ||
b.ignore('glob') | ||
.ignore('jade') | ||
.ignore('supports-color') | ||
.exclude('./lib-cov/mocha'); | ||
} | ||
}, | ||
reporters: ['spec'], | ||
colors: true, | ||
browsers: ['PhantomJS'], | ||
logLevel: config.LOG_INFO, | ||
singleRun: true | ||
}; | ||
|
||
// see https://github.com/saucelabs/karma-sauce-example | ||
// TO RUN LOCALLY: | ||
// Execute `CI=1 make test-browser`, once you've set the SAUCE_USERNAME and | ||
// SAUCE_ACCESS_KEY env vars. | ||
if (process.env.CI) { | ||
if (!(process.env.SAUCE_USERNAME || process.env.SAUCE_ACCESS_KEY)) { | ||
throw new Error('Must set SAUCE_USERNAME and SAUCE_ACCESS_KEY ' | ||
+ 'environment variables!'); | ||
} | ||
cfg.reporters.push('saucelabs'); | ||
cfg.browsers.push('ie8'); | ||
cfg.customLaunchers = { | ||
ie8: { | ||
base: 'SauceLabs', | ||
browserName: 'internet explorer', | ||
platform: 'Windows XP', | ||
version: '8.0' | ||
} | ||
}; | ||
|
||
cfg.sauceLabs = { | ||
public: 'public' | ||
}; | ||
|
||
if (process.env.TRAVIS) { | ||
// correlate build/tunnel with Travis | ||
cfg.sauceLabs.build = 'TRAVIS #' + process.env.TRAVIS_BUILD_NUMBER | ||
+ ' (' + process.env.TRAVIS_BUILD_ID + ')'; | ||
cfg.sauceLabs.tunnelIdentifier = process.env.TRAVIS_JOB_NUMBER; | ||
cfg.sauceLabs.startConnect = false; | ||
} else { | ||
// otherwise just make something up | ||
cfg.sauceLabs.build = require('os').hostname() + ' (' + Date.now() + ')'; | ||
} | ||
|
||
// for slow browser booting, ostensibly | ||
cfg.captureTimeout = 120000; | ||
} | ||
|
||
// the MOCHA_UI env var will determine if we're running interface-specific | ||
// tets. since you can only load one at a time, each must be run separately. | ||
// each has its own set of acceptance tests and a fixture. | ||
// the "bdd" fixture is used by default. | ||
var ui = process.env.MOCHA_UI; | ||
if (ui) { | ||
if (cfg.sauceLabs) { | ||
cfg.sauceLabs.testName = 'Interface "' + ui + '" integration tests'; | ||
} | ||
cfg.files = [ | ||
'test/browser-fixtures/' + ui + '.js', | ||
'test/acceptance/interfaces/' + ui + '.js' | ||
]; | ||
} else if (cfg.sauceLabs) { | ||
cfg.sauceLabs.testName = 'Unit Tests'; | ||
} | ||
|
||
config.set(cfg); | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -99,22 +99,6 @@ function Mocha(options) { | |
if (options.slow) { | ||
this.slow(options.slow); | ||
} | ||
|
||
this.suite.on('pre-require', function(context) { | ||
exports.afterEach = context.afterEach || context.teardown; | ||
exports.after = context.after || context.suiteTeardown; | ||
exports.beforeEach = context.beforeEach || context.setup; | ||
exports.before = context.before || context.suiteSetup; | ||
exports.describe = context.describe || context.suite; | ||
exports.it = context.it || context.test; | ||
exports.setup = context.setup || context.beforeEach; | ||
exports.suiteSetup = context.suiteSetup || context.before; | ||
exports.suiteTeardown = context.suiteTeardown || context.after; | ||
exports.suite = context.suite || context.describe; | ||
exports.teardown = context.teardown || context.afterEach; | ||
exports.test = context.test || context.it; | ||
exports.run = context.run; | ||
}); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this by any chance related to #2207? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What this code is doing is making these functions available via |
||
|
||
/** | ||
|
@@ -202,6 +186,23 @@ Mocha.prototype.ui = function(name) { | |
} | ||
} | ||
this._ui = this._ui(this.suite); | ||
|
||
this.suite.on('pre-require', function(context) { | ||
exports.afterEach = context.afterEach || context.teardown; | ||
exports.after = context.after || context.suiteTeardown; | ||
exports.beforeEach = context.beforeEach || context.setup; | ||
exports.before = context.before || context.suiteSetup; | ||
exports.describe = context.describe || context.suite; | ||
exports.it = context.it || context.test; | ||
exports.setup = context.setup || context.beforeEach; | ||
exports.suiteSetup = context.suiteSetup || context.before; | ||
exports.suiteTeardown = context.suiteTeardown || context.after; | ||
exports.suite = context.suite || context.describe; | ||
exports.teardown = context.teardown || context.afterEach; | ||
exports.test = context.test || context.it; | ||
exports.run = context.run; | ||
}); | ||
|
||
return this; | ||
}; | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we could also add an
osx
target here, if anyone cares.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Worth trying, but probably best done after we get the basic browser testing merged.