1
0
mirror of https://github.com/twbs/bootstrap.git synced 2025-08-07 14:16:47 +02:00

JS: update karma config (#32769)

* rename constants
* enforce the constants to be Boolean
* fix karma `logLevel`
This commit is contained in:
XhmikosR
2021-01-13 19:16:51 +02:00
committed by GitHub
parent 05249c8c04
commit cad88abdb0
2 changed files with 19 additions and 17 deletions

View File

@@ -1,5 +1,7 @@
/* eslint-env node */ /* eslint-env node */
'use strict'
const path = require('path') const path = require('path')
const ip = require('ip') const ip = require('ip')
const { babel } = require('@rollup/plugin-babel') const { babel } = require('@rollup/plugin-babel')
@@ -12,10 +14,11 @@ const {
browsersKeys browsersKeys
} = require('./browsers') } = require('./browsers')
const { env } = process const ENV = process.env
const browserStack = env.BROWSER === 'true' const BROWSERSTACK = Boolean(ENV.BROWSERSTACK)
const debug = env.DEBUG === 'true' const DEBUG = Boolean(ENV.DEBUG)
const jQueryTest = env.JQUERY === 'true' const JQUERY_TEST = Boolean(ENV.JQUERY)
const frameworks = [ const frameworks = [
'jasmine' 'jasmine'
] ]
@@ -30,16 +33,16 @@ const reporters = ['dots']
const detectBrowsers = { const detectBrowsers = {
usePhantomJS: false, usePhantomJS: false,
postDetection(availableBrowser) { postDetection(availableBrowser) {
if (env.CI === true || availableBrowser.includes('Chrome')) { if (ENV.CI === true || availableBrowser.includes('Chrome')) {
return debug ? ['Chrome'] : ['ChromeHeadless'] return DEBUG ? ['Chrome'] : ['ChromeHeadless']
} }
if (availableBrowser.includes('Chromium')) { if (availableBrowser.includes('Chromium')) {
return debug ? ['Chromium'] : ['ChromiumHeadless'] return DEBUG ? ['Chromium'] : ['ChromiumHeadless']
} }
if (availableBrowser.includes('Firefox')) { if (availableBrowser.includes('Firefox')) {
return debug ? ['Firefox'] : ['FirefoxHeadless'] return DEBUG ? ['Firefox'] : ['FirefoxHeadless']
} }
throw new Error('Please install Chrome, Chromium or Firefox') throw new Error('Please install Chrome, Chromium or Firefox')
@@ -67,7 +70,7 @@ const conf = {
'node_modules/hammer-simulator/index.js', 'node_modules/hammer-simulator/index.js',
{ {
pattern: 'js/tests/unit/**/!(jquery).spec.js', pattern: 'js/tests/unit/**/!(jquery).spec.js',
watched: !browserStack watched: !BROWSERSTACK
} }
], ],
preprocessors: { preprocessors: {
@@ -101,11 +104,11 @@ const conf = {
} }
} }
if (browserStack) { if (BROWSERSTACK) {
conf.hostname = ip.address() conf.hostname = ip.address()
conf.browserStack = { conf.browserStack = {
username: env.BROWSER_STACK_USERNAME, username: ENV.BROWSER_STACK_USERNAME,
accessKey: env.BROWSER_STACK_ACCESS_KEY, accessKey: ENV.BROWSER_STACK_ACCESS_KEY,
build: `bootstrap-${new Date().toISOString()}`, build: `bootstrap-${new Date().toISOString()}`,
project: 'Bootstrap', project: 'Bootstrap',
retryLimit: 2 retryLimit: 2
@@ -114,7 +117,7 @@ if (browserStack) {
conf.customLaunchers = browsers conf.customLaunchers = browsers
conf.browsers = browsersKeys conf.browsers = browsersKeys
reporters.push('BrowserStack', 'kjhtml') reporters.push('BrowserStack', 'kjhtml')
} else if (jQueryTest) { } else if (JQUERY_TEST) {
frameworks.push('detectBrowsers') frameworks.push('detectBrowsers')
plugins.push( plugins.push(
'karma-chrome-launcher', 'karma-chrome-launcher',
@@ -155,7 +158,7 @@ if (browserStack) {
} }
} }
if (debug) { if (DEBUG) {
conf.hostname = ip.address() conf.hostname = ip.address()
plugins.push('karma-jasmine-html-reporter') plugins.push('karma-jasmine-html-reporter')
reporters.push('kjhtml') reporters.push('kjhtml')
@@ -169,7 +172,6 @@ conf.plugins = plugins
conf.reporters = reporters conf.reporters = reporters
module.exports = karmaConfig => { 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
conf.logLevel = karmaConfig.LOG_ERROR || karmaConfig.LOG_WARN
karmaConfig.set(conf) karmaConfig.set(conf)
} }

View File

@@ -51,7 +51,7 @@
"js-test-karma": "karma start js/tests/karma.conf.js", "js-test-karma": "karma start js/tests/karma.conf.js",
"js-test-integration-bundle": "rollup --config js/tests/integration/rollup.bundle.js", "js-test-integration-bundle": "rollup --config js/tests/integration/rollup.bundle.js",
"js-test-integration-modularity": "rollup --config js/tests/integration/rollup.bundle-modularity.js", "js-test-integration-modularity": "rollup --config js/tests/integration/rollup.bundle-modularity.js",
"js-test-cloud": "cross-env BROWSER=true npm run js-test-karma", "js-test-cloud": "cross-env BROWSERSTACK=true npm run js-test-karma",
"js-test-jquery": "cross-env JQUERY=true npm run js-test-karma", "js-test-jquery": "cross-env JQUERY=true npm run js-test-karma",
"lint": "npm-run-all --parallel js-lint css-lint lockfile-lint", "lint": "npm-run-all --parallel js-lint css-lint lockfile-lint",
"docs": "npm-run-all docs-build docs-lint", "docs": "npm-run-all docs-build docs-lint",