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