twbs--bootstrap/js/tests/karma.conf.js

176 lines
4.0 KiB
JavaScript
Raw Normal View History

/* eslint-env node */
'use strict'
const path = require('path')
2018-09-13 07:42:15 +00:00
const ip = require('ip')
const { babel } = require('@rollup/plugin-babel')
2019-08-29 13:20:49 +00:00
const istanbul = require('rollup-plugin-istanbul')
const { nodeResolve } = require('@rollup/plugin-node-resolve')
2020-06-19 08:17:01 +00:00
const replace = require('@rollup/plugin-replace')
2019-08-29 13:20:49 +00:00
2018-09-13 07:42:15 +00:00
const {
browsers,
browsersKeys
} = require('./browsers')
const ENV = process.env
const BROWSERSTACK = Boolean(ENV.BROWSERSTACK)
const DEBUG = Boolean(ENV.DEBUG)
const JQUERY_TEST = Boolean(ENV.JQUERY)
const frameworks = [
2019-03-13 14:23:50 +00:00
'jasmine'
]
2018-10-14 11:59:51 +00:00
const plugins = [
2019-03-13 14:23:50 +00:00
'karma-jasmine',
'karma-rollup-preprocessor'
2018-10-14 11:59:51 +00:00
]
2018-09-13 07:42:15 +00:00
const reporters = ['dots']
const detectBrowsers = {
usePhantomJS: false,
postDetection(availableBrowser) {
// On CI just use Chrome
if (ENV.CI === true) {
return ['ChromeHeadless']
}
if (availableBrowser.includes('Chrome')) {
return DEBUG ? ['Chrome'] : ['ChromeHeadless']
2018-09-13 07:42:15 +00:00
}
if (availableBrowser.includes('Chromium')) {
return DEBUG ? ['Chromium'] : ['ChromiumHeadless']
}
2018-09-13 07:42:15 +00:00
if (availableBrowser.includes('Firefox')) {
return DEBUG ? ['Firefox'] : ['FirefoxHeadless']
2018-09-13 07:42:15 +00:00
}
throw new Error('Please install Chrome, Chromium or Firefox')
2018-09-13 07:42:15 +00:00
}
}
const conf = {
basePath: '../..',
port: 9876,
colors: true,
autoWatch: false,
singleRun: true,
concurrency: Number.POSITIVE_INFINITY,
2018-09-13 07:42:15 +00:00
client: {
2019-03-13 14:23:50 +00:00
clearContext: false
},
files: [
'node_modules/hammer-simulator/index.js',
2020-11-09 18:33:20 +00:00
{
pattern: 'js/tests/unit/**/!(jquery).spec.js',
watched: !BROWSERSTACK
2020-11-09 18:33:20 +00:00
}
],
preprocessors: {
'js/tests/unit/**/*.spec.js': ['rollup']
},
rollupPreprocessor: {
plugins: [
2020-06-19 08:17:01 +00:00
replace({
'process.env.NODE_ENV': '"dev"',
preventAssignment: true
2020-06-19 08:17:01 +00:00
}),
istanbul({
2020-05-09 19:28:09 +00:00
exclude: [
'node_modules/**',
'js/tests/unit/**/*.spec.js',
'js/tests/helpers/**/*.js'
]
}),
babel({
// Only transpile our source code
exclude: 'node_modules/**',
// Inline the required helpers in each file
babelHelpers: 'inline'
}),
nodeResolve()
],
output: {
format: 'iife',
name: 'bootstrapTest',
sourcemap: 'inline',
generatedCode: 'es2015'
}
2018-09-13 07:42:15 +00:00
}
}
if (BROWSERSTACK) {
2018-09-13 07:42:15 +00:00
conf.hostname = ip.address()
conf.browserStack = {
username: ENV.BROWSER_STACK_USERNAME,
accessKey: ENV.BROWSER_STACK_ACCESS_KEY,
build: `bootstrap-${ENV.GITHUB_SHA ? ENV.GITHUB_SHA.slice(0, 7) + '-' : ''}${new Date().toISOString()}`,
2018-09-13 07:42:15 +00:00
project: 'Bootstrap',
retryLimit: 2
}
2019-03-13 14:23:50 +00:00
plugins.push('karma-browserstack-launcher', 'karma-jasmine-html-reporter')
2018-09-13 07:42:15 +00:00
conf.customLaunchers = browsers
conf.browsers = browsersKeys
2019-03-13 14:23:50 +00:00
reporters.push('BrowserStack', 'kjhtml')
} else if (JQUERY_TEST) {
frameworks.push('detectBrowsers')
plugins.push(
'karma-chrome-launcher',
'karma-firefox-launcher',
'karma-detect-browsers'
)
conf.detectBrowsers = detectBrowsers
conf.files = [
'node_modules/jquery/dist/jquery.slim.min.js',
2020-11-09 18:33:20 +00:00
{
pattern: 'js/tests/unit/jquery.spec.js',
watched: false
}
]
2018-09-13 07:42:15 +00:00
} else {
frameworks.push('detectBrowsers')
plugins.push(
'karma-chrome-launcher',
'karma-firefox-launcher',
'karma-detect-browsers',
'karma-coverage-istanbul-reporter'
)
reporters.push('coverage-istanbul')
conf.detectBrowsers = detectBrowsers
conf.coverageIstanbulReporter = {
dir: path.resolve(__dirname, '../coverage/'),
2018-09-13 07:42:15 +00:00
reports: ['lcov', 'text-summary'],
thresholds: {
emitWarning: false,
global: {
statements: 90,
branches: 89,
2019-03-13 14:23:50 +00:00
functions: 90,
2018-09-13 07:42:15 +00:00
lines: 90
}
}
2018-09-13 07:42:15 +00:00
}
if (DEBUG) {
2019-03-13 14:23:50 +00:00
conf.hostname = ip.address()
plugins.push('karma-jasmine-html-reporter')
reporters.push('kjhtml')
conf.singleRun = false
conf.autoWatch = true
}
}
2018-09-13 07:42:15 +00:00
conf.frameworks = frameworks
conf.plugins = plugins
conf.reporters = reporters
2019-02-26 11:20:34 +00:00
module.exports = karmaConfig => {
conf.logLevel = karmaConfig.LOG_ERROR
2018-09-13 07:42:15 +00:00
karmaConfig.set(conf)
}