2017-11-10 11:25:47 +01:00
|
|
|
/* eslint-env node */
|
2020-07-07 09:23:11 +02:00
|
|
|
|
2019-01-17 11:06:43 +01:00
|
|
|
const path = require('path')
|
2018-09-13 09:42:15 +02:00
|
|
|
const ip = require('ip')
|
2020-05-26 05:14:12 +02:00
|
|
|
const { babel } = require('@rollup/plugin-babel')
|
2019-08-29 15:20:49 +02:00
|
|
|
const istanbul = require('rollup-plugin-istanbul')
|
2020-07-07 09:23:11 +02:00
|
|
|
const { nodeResolve } = require('@rollup/plugin-node-resolve')
|
2020-06-19 10:17:01 +02:00
|
|
|
const replace = require('@rollup/plugin-replace')
|
2019-08-29 15:20:49 +02:00
|
|
|
|
2018-09-13 09:42:15 +02:00
|
|
|
const {
|
|
|
|
browsers,
|
|
|
|
browsersKeys
|
|
|
|
} = require('./browsers')
|
2017-11-10 11:25:47 +01:00
|
|
|
|
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'
|
2020-05-06 07:23:05 +02:00
|
|
|
const jQueryTest = env.JQUERY === 'true'
|
2018-03-03 22:04:11 +01:00
|
|
|
const frameworks = [
|
2019-03-13 15:23:50 +01:00
|
|
|
'jasmine'
|
2018-03-03 22:04:11 +01:00
|
|
|
]
|
|
|
|
|
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) {
|
2019-04-01 16:26:43 +02:00
|
|
|
if (env.CI === true || availableBrowser.includes('Chrome')) {
|
2019-02-22 23:37:55 +01:00
|
|
|
return debug ? ['Chrome'] : ['ChromeHeadless']
|
2018-09-13 09:42:15 +02:00
|
|
|
}
|
|
|
|
|
2020-11-18 12:06:04 +01:00
|
|
|
if (availableBrowser.includes('Chromium')) {
|
2020-11-17 20:42:55 +01:00
|
|
|
return debug ? ['Chromium'] : ['ChromiumHeadless']
|
|
|
|
}
|
|
|
|
|
2018-09-13 09:42:15 +02:00
|
|
|
if (availableBrowser.includes('Firefox')) {
|
2019-02-22 23:37:55 +01:00
|
|
|
return debug ? ['Firefox'] : ['FirefoxHeadless']
|
2018-09-13 09:42:15 +02:00
|
|
|
}
|
|
|
|
|
2020-11-17 20:42:55 +01:00
|
|
|
throw new Error('Please install Chrome, Chromium or Firefox')
|
2018-09-13 09:42:15 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const customLaunchers = {
|
|
|
|
FirefoxHeadless: {
|
|
|
|
base: 'Firefox',
|
|
|
|
flags: ['-headless']
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const conf = {
|
|
|
|
basePath: '../..',
|
|
|
|
port: 9876,
|
|
|
|
colors: true,
|
|
|
|
autoWatch: false,
|
|
|
|
singleRun: true,
|
|
|
|
concurrency: Infinity,
|
|
|
|
client: {
|
2019-03-13 15:23:50 +01:00
|
|
|
clearContext: false
|
2019-10-02 11:43:54 +02:00
|
|
|
},
|
|
|
|
files: [
|
|
|
|
'node_modules/hammer-simulator/index.js',
|
2020-11-09 19:33:20 +01:00
|
|
|
{
|
|
|
|
pattern: 'js/tests/unit/**/!(jquery).spec.js',
|
|
|
|
watched: !browserStack
|
|
|
|
}
|
2019-10-02 11:43:54 +02:00
|
|
|
],
|
|
|
|
preprocessors: {
|
2019-10-09 00:27:43 +02:00
|
|
|
'js/tests/unit/**/*.spec.js': ['rollup']
|
2019-10-02 11:43:54 +02:00
|
|
|
},
|
|
|
|
rollupPreprocessor: {
|
|
|
|
plugins: [
|
2020-06-19 10:17:01 +02:00
|
|
|
replace({
|
|
|
|
'process.env.NODE_ENV': '"dev"'
|
|
|
|
}),
|
2019-10-02 11:43:54 +02:00
|
|
|
istanbul({
|
2020-05-09 21:28:09 +02:00
|
|
|
exclude: [
|
|
|
|
'node_modules/**',
|
|
|
|
'js/tests/unit/**/*.spec.js',
|
|
|
|
'js/tests/helpers/**/*.js'
|
|
|
|
]
|
2019-10-02 11:43:54 +02:00
|
|
|
}),
|
|
|
|
babel({
|
|
|
|
// Only transpile our source code
|
|
|
|
exclude: 'node_modules/**',
|
2020-05-26 05:14:12 +02:00
|
|
|
// Inline the required helpers in each file
|
|
|
|
babelHelpers: 'inline'
|
2019-10-02 11:43:54 +02:00
|
|
|
}),
|
2020-07-07 09:23:11 +02:00
|
|
|
nodeResolve()
|
2019-10-02 11:43:54 +02:00
|
|
|
],
|
|
|
|
output: {
|
|
|
|
format: 'iife',
|
|
|
|
name: 'bootstrapTest',
|
|
|
|
sourcemap: 'inline'
|
|
|
|
}
|
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')
|
2020-05-06 07:23:05 +02:00
|
|
|
} else if (jQueryTest) {
|
|
|
|
frameworks.push('detectBrowsers')
|
|
|
|
plugins.push(
|
|
|
|
'karma-chrome-launcher',
|
|
|
|
'karma-firefox-launcher',
|
|
|
|
'karma-detect-browsers'
|
|
|
|
)
|
|
|
|
conf.customLaunchers = customLaunchers
|
|
|
|
conf.detectBrowsers = detectBrowsers
|
|
|
|
conf.files = [
|
|
|
|
'node_modules/jquery/dist/jquery.slim.min.js',
|
2020-11-09 19:33:20 +01:00
|
|
|
{
|
|
|
|
pattern: 'js/tests/unit/jquery.spec.js',
|
|
|
|
watched: false
|
|
|
|
}
|
2020-05-06 07:23:05 +02:00
|
|
|
]
|
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'
|
|
|
|
)
|
|
|
|
reporters.push('coverage-istanbul')
|
|
|
|
conf.customLaunchers = customLaunchers
|
|
|
|
conf.detectBrowsers = detectBrowsers
|
|
|
|
conf.coverageIstanbulReporter = {
|
2019-01-17 11:06:43 +01:00
|
|
|
dir: path.resolve(__dirname, '../coverage/'),
|
2018-09-13 09:42:15 +02:00
|
|
|
reports: ['lcov', 'text-summary'],
|
|
|
|
thresholds: {
|
|
|
|
emitWarning: false,
|
|
|
|
global: {
|
|
|
|
statements: 90,
|
2020-11-01 14:52:24 +01:00
|
|
|
branches: 89,
|
2019-03-13 15:23:50 +01:00
|
|
|
functions: 90,
|
2018-09-13 09:42:15 +02:00
|
|
|
lines: 90
|
2018-05-07 15:56:24 +02:00
|
|
|
}
|
2017-11-10 11:25:47 +01:00
|
|
|
}
|
2018-09-13 09:42:15 +02:00
|
|
|
}
|
|
|
|
|
2019-02-22 23:37:55 +01:00
|
|
|
if (debug) {
|
2019-03-13 15:23:50 +01:00
|
|
|
conf.hostname = ip.address()
|
|
|
|
plugins.push('karma-jasmine-html-reporter')
|
|
|
|
reporters.push('kjhtml')
|
2019-02-22 23:37:55 +01:00
|
|
|
conf.singleRun = false
|
|
|
|
conf.autoWatch = true
|
|
|
|
}
|
|
|
|
}
|
2018-09-13 09:42:15 +02:00
|
|
|
|
|
|
|
conf.frameworks = frameworks
|
|
|
|
conf.plugins = plugins
|
|
|
|
conf.reporters = reporters
|
|
|
|
|
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)
|
2017-11-10 11:25:47 +01:00
|
|
|
}
|