0
0
mirror of https://github.com/twbs/bootstrap.git synced 2024-12-10 22:24:19 +01:00
Bootstrap/js/tests/karma.conf.js

176 lines
4.0 KiB
JavaScript
Raw Normal View History

/* eslint-env node */
/* eslint no-process-env: 0 */
const path = require('path')
2018-09-13 09:42:15 +02:00
const ip = require('ip')
const {
browsers,
browsersKeys
} = require('./browsers')
2019-03-13 15:23:50 +01:00
const babel = require('rollup-plugin-babel')
const istanbul = require('rollup-plugin-istanbul')
2019-04-10 10:46:50 +02:00
const resolve = require('rollup-plugin-node-resolve')
2019-02-26 12:20:34 +01:00
const { env } = process
2019-02-24 14:34:36 +01:00
const browserStack = env.BROWSER === 'true'
const debug = env.DEBUG === 'true'
const frameworks = [
2019-03-13 15:23:50 +01:00
'jasmine'
]
2018-10-14 13:59:51 +02:00
const plugins = [
2019-03-13 15:23:50 +01:00
'karma-jasmine',
'karma-rollup-preprocessor'
2018-10-14 13:59:51 +02:00
]
2018-09-13 09:42:15 +02:00
const reporters = ['dots']
const detectBrowsers = {
usePhantomJS: false,
postDetection(availableBrowser) {
if (env.CI === true || availableBrowser.includes('Chrome')) {
return debug ? ['Chrome'] : ['ChromeHeadless']
2018-09-13 09:42:15 +02:00
}
if (availableBrowser.includes('Firefox')) {
return debug ? ['Firefox'] : ['FirefoxHeadless']
2018-09-13 09:42:15 +02:00
}
throw new Error('Please install Firefox or Chrome')
}
}
const customLaunchers = {
FirefoxHeadless: {
base: 'Firefox',
flags: ['-headless']
}
}
2019-03-13 15:23:50 +01:00
const rollupPreprocessor = {
plugins: [
istanbul({
exclude: ['js/src/**/*.spec.js']
}),
babel({
// Only transpile our source code
exclude: 'node_modules/**',
// Include only required helpers
externalHelpersWhitelist: [
'defineProperties',
'createClass',
'inheritsLoose',
'defineProperty',
'objectSpread2'
],
plugins: [
'@babel/plugin-proposal-object-rest-spread'
]
2019-04-10 10:46:50 +02:00
}),
resolve()
2019-03-13 15:23:50 +01:00
],
output: {
format: 'iife',
name: 'bootstrapTest',
sourcemap: 'inline'
}
}
2019-03-27 11:58:00 +01:00
let files = [
'node_modules/hammer-simulator/index.js'
]
2018-09-13 09:42:15 +02:00
const conf = {
basePath: '../..',
port: 9876,
colors: true,
autoWatch: false,
singleRun: true,
concurrency: Infinity,
client: {
2019-03-13 15:23:50 +01:00
clearContext: false
2018-09-13 09:42:15 +02:00
}
}
2019-03-13 15:23:50 +01:00
if (browserStack) {
2018-09-13 09:42:15 +02:00
conf.hostname = ip.address()
conf.browserStack = {
2019-02-24 14:34:36 +01:00
username: env.BROWSER_STACK_USERNAME,
accessKey: env.BROWSER_STACK_ACCESS_KEY,
2018-09-13 09:42:15 +02:00
build: `bootstrap-${new Date().toISOString()}`,
project: 'Bootstrap',
retryLimit: 2
}
2019-03-13 15:23:50 +01:00
plugins.push('karma-browserstack-launcher', 'karma-jasmine-html-reporter')
2018-09-13 09:42:15 +02:00
conf.customLaunchers = browsers
conf.browsers = browsersKeys
2019-03-13 15:23:50 +01:00
reporters.push('BrowserStack', 'kjhtml')
2018-09-13 09:42:15 +02:00
files = files.concat([
2019-03-13 15:23:50 +01:00
{ pattern: 'js/src/**/*.spec.js', watched: false }
2018-09-13 09:42:15 +02:00
])
2019-03-13 15:23:50 +01:00
conf.preprocessors = {
'js/src/**/*.spec.js': ['rollup']
}
conf.rollupPreprocessor = rollupPreprocessor
2018-09-13 09:42:15 +02:00
} else {
frameworks.push('detectBrowsers')
plugins.push(
'karma-chrome-launcher',
'karma-firefox-launcher',
'karma-detect-browsers',
'karma-coverage-istanbul-reporter'
)
files = files.concat([
2019-03-13 15:23:50 +01:00
{ pattern: 'js/src/**/*.spec.js', watched: true }
2018-09-13 09:42:15 +02:00
])
reporters.push('coverage-istanbul')
2019-03-13 15:23:50 +01:00
conf.preprocessors = {
'js/src/**/*.spec.js': ['rollup']
}
conf.rollupPreprocessor = rollupPreprocessor
2018-09-13 09:42:15 +02:00
conf.customLaunchers = customLaunchers
conf.detectBrowsers = detectBrowsers
conf.coverageIstanbulReporter = {
dir: path.resolve(__dirname, '../coverage/'),
2018-09-13 09:42:15 +02:00
reports: ['lcov', 'text-summary'],
thresholds: {
emitWarning: false,
global: {
statements: 90,
2019-03-13 15:23:50 +01:00
branches: 90,
functions: 90,
2018-09-13 09:42:15 +02:00
lines: 90
},
each: {
overrides: {
'js/src/dom/polyfill.js': {
statements: 39,
lines: 37,
branches: 19,
functions: 50
}
}
}
}
2018-09-13 09:42:15 +02:00
}
if (debug) {
2019-03-13 15:23:50 +01:00
conf.hostname = ip.address()
plugins.push('karma-jasmine-html-reporter')
reporters.push('kjhtml')
conf.singleRun = false
conf.autoWatch = true
}
}
2018-09-13 09:42:15 +02:00
conf.frameworks = frameworks
conf.plugins = plugins
conf.reporters = reporters
conf.files = files
2019-02-26 12:20:34 +01:00
module.exports = karmaConfig => {
2018-09-13 09:42:15 +02:00
// 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)
}