1
0
Fork 0
mirror of https://github.com/twbs/bootstrap.git synced 2022-11-09 12:25:43 -05:00
twbs--bootstrap/js/tests/karma.conf.js

170 lines
4.3 KiB
JavaScript
Raw Normal View History

/* eslint-env node */
/* eslint no-process-env: 0 */
const path = require('path')
2018-09-13 03:42:15 -04:00
const ip = require('ip')
const {
browsers,
browsersKeys
} = require('./browsers')
const jqueryFile = process.env.USE_OLD_JQUERY ? 'https://code.jquery.com/jquery-1.9.1.min.js' : 'node_modules/jquery/dist/jquery.slim.min.js'
2018-09-13 03:42:15 -04:00
const bundle = process.env.BUNDLE === 'true'
const browserStack = process.env.BROWSER === 'true'
const frameworks = [
'qunit',
'sinon'
]
2018-10-14 07:59:51 -04:00
const plugins = [
'karma-qunit',
'karma-sinon'
]
2018-09-13 03:42:15 -04:00
const reporters = ['dots']
const detectBrowsers = {
usePhantomJS: false,
postDetection(availableBrowser) {
if (typeof process.env.TRAVIS_JOB_ID !== 'undefined' || availableBrowser.includes('Chrome')) {
return ['ChromeHeadless']
}
if (availableBrowser.includes('Firefox')) {
return ['FirefoxHeadless']
}
throw new Error('Please install Firefox or Chrome')
}
}
const customLaunchers = {
FirefoxHeadless: {
base: 'Firefox',
flags: ['-headless']
}
}
let files = [
'node_modules/popper.js/dist/umd/popper.min.js',
'node_modules/hammer-simulator/index.js'
]
2018-09-13 03:42:15 -04:00
const conf = {
basePath: '../..',
port: 9876,
colors: true,
autoWatch: false,
singleRun: true,
concurrency: Infinity,
client: {
qunit: {
showUI: true
}
}
}
if (bundle) {
frameworks.push('detectBrowsers')
plugins.push(
'karma-chrome-launcher',
'karma-firefox-launcher',
'karma-detect-browsers'
)
conf.customLaunchers = customLaunchers
conf.detectBrowsers = detectBrowsers
files = files.concat([
jqueryFile,
'dist/js/bootstrap.js'
])
} else if (browserStack) {
conf.hostname = ip.address()
conf.browserStack = {
username: process.env.BROWSER_STACK_USERNAME,
accessKey: process.env.BROWSER_STACK_ACCESS_KEY,
build: `bootstrap-${new Date().toISOString()}`,
project: 'Bootstrap',
retryLimit: 2
}
plugins.push('karma-browserstack-launcher')
conf.customLaunchers = browsers
conf.browsers = browsersKeys
reporters.push('BrowserStack')
files = files.concat([
'node_modules/jquery/dist/jquery.slim.min.js',
2018-07-25 05:29:16 -04:00
'js/coverage/dist/util.js',
'js/coverage/dist/dom/polyfill.js',
2018-06-09 12:23:13 -04:00
'js/coverage/dist/dom/eventHandler.js',
'js/coverage/dist/dom/selectorEngine.js',
'js/coverage/dist/dom/data.js',
'js/coverage/dist/dom/manipulator.js',
'js/coverage/dist/dom/!(polyfill).js',
2018-06-09 12:23:13 -04:00
'js/coverage/dist/tooltip.js',
'js/coverage/dist/!(util|index|tooltip).js', // include all of our js/dist files except util.js, index.js and tooltip.js
'js/tests/unit/*.js',
'js/tests/unit/dom/*.js'
2018-09-13 03:42:15 -04:00
])
} else {
frameworks.push('detectBrowsers')
plugins.push(
'karma-chrome-launcher',
'karma-firefox-launcher',
'karma-detect-browsers',
'karma-coverage-istanbul-reporter'
)
files = files.concat([
jqueryFile,
2018-07-25 05:29:16 -04:00
'js/coverage/dist/util.js',
'js/coverage/dist/dom/polyfill.js',
2017-11-24 04:23:31 -05:00
'js/coverage/dist/dom/eventHandler.js',
'js/coverage/dist/dom/selectorEngine.js',
'js/coverage/dist/dom/data.js',
'js/coverage/dist/dom/manipulator.js',
'js/coverage/dist/dom/!(polyfill).js',
2018-09-13 03:42:15 -04:00
'js/coverage/dist/tooltip.js',
2018-06-09 12:23:13 -04:00
'js/coverage/dist/!(util|index|tooltip).js', // include all of our js/dist files except util.js, index.js and tooltip.js
'js/tests/unit/*.js',
'js/tests/unit/dom/*.js'
2018-09-13 03:42:15 -04:00
])
reporters.push('coverage-istanbul')
conf.customLaunchers = customLaunchers
conf.detectBrowsers = detectBrowsers
conf.coverageIstanbulReporter = {
dir: path.resolve(__dirname, '../coverage/'),
2018-09-13 03:42:15 -04:00
reports: ['lcov', 'text-summary'],
thresholds: {
emitWarning: false,
global: {
statements: 90,
branches: 86,
functions: 89,
2018-09-13 03:42:15 -04:00
lines: 90
},
each: {
overrides: {
'js/src/dom/polyfill.js': {
statements: 39,
lines: 37,
branches: 19,
functions: 50
}
}
}
}
2018-09-13 03:42:15 -04:00
}
}
files.push('js/tests/unit/*.js')
conf.frameworks = frameworks
conf.plugins = plugins
conf.reporters = reporters
conf.files = files
module.exports = (karmaConfig) => {
// possible values: karmaConfig.LOG_DISABLE || karmaConfig.LOG_ERROR || karmaConfig.LOG_WARN || karmaConfig.LOG_INFO || karmaConfig.LOG_DEBUG
conf.logLevel = karmaConfig.LOG_ERROR || karmaConfig.LOG_WARN
karmaConfig.set(conf)
}