Skip to content

Commit

Permalink
Use karma-detect-browsers to run only one browser
Browse files Browse the repository at this point in the history
  • Loading branch information
Johann-S committed Nov 16, 2017
1 parent a1b850b commit 1c88c55
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 20 deletions.
33 changes: 22 additions & 11 deletions karma.conf.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
module.exports = function (config) {
const jqueryFile = process.env.USE_OLD_JQUERY === 'true' ? 'js/tests/vendor/jquery-1.9.1.min.js' : 'assets/js/vendor/jquery-slim.min.js'

// available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
const browsers = ['ChromeHeadless', 'FirefoxHeadless']
// if we run our test on Travis we just use ChromeHeadless because Firefox isn't well supported
if (typeof process.env.TRAVIS_JOB_ID !== 'undefined') {
browsers.pop()
}

config.set({
frameworks: ['qunit'],
plugins: ['karma-chrome-launcher', 'karma-firefox-launcher', 'karma-qunit'],
frameworks: ['qunit', 'detectBrowsers'],
plugins: [
'karma-chrome-launcher',
'karma-firefox-launcher',
'karma-qunit',
'karma-detect-browsers'
],
// list of files / patterns to load in the browser
files: [
jqueryFile,
Expand All @@ -26,14 +24,27 @@ module.exports = function (config) {
// possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
logLevel: config.LOG_ERROR || config.LOG_WARN,
autoWatch: false,
browsers,
customLaunchers: {
FirefoxHeadless: {
base: 'Firefox',
flags: ['-headless'],
},
},
singleRun: true,
concurrency: Infinity
concurrency: Infinity,
detectBrowsers: {
usePhantomJS: false,
postDetection: function (availableBrowser) {
if (typeof process.env.TRAVIS_JOB_ID !== 'undefined' || availableBrowser.indexOf('Chrome') !== -1) {
return ['ChromeHeadless']
}

if (availableBrowser.indexOf('Firefox') !== -1) {
return ['FirefoxHeadless']
}

throw new Error('Please install Firefox or Chrome')
}
}
})
}
27 changes: 18 additions & 9 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@
"jsunitsaucelabs": "^1.3.0",
"karma": "^1.7.1",
"karma-chrome-launcher": "^2.2.0",
"karma-detect-browsers": "^2.2.6",
"karma-firefox-launcher": "^1.0.1",
"karma-qunit": "^1.2.1",
"node-sass": "^4.6.1",
Expand Down

0 comments on commit 1c88c55

Please sign in to comment.