karma.conf.js 4.62 KB
Newer Older
1
/* eslint-env node */
XhmikosR's avatar
XhmikosR committed
2
/* eslint no-process-env: 0 */
3

4
const path = require('path')
Johann-S's avatar
Johann-S committed
5
6
7
8
9
const ip = require('ip')
const {
  browsers,
  browsersKeys
} = require('./browsers')
10

XhmikosR's avatar
XhmikosR committed
11
const { env } = process
12
13
14
15
const bundle = env.BUNDLE === 'true'
const browserStack = env.BROWSER === 'true'
const debug = env.DEBUG === 'true'

16
const jqueryFile = 'node_modules/jquery/dist/jquery.slim.min.js'
17

18
19
20
21
22
const frameworks = [
  'qunit',
  'sinon'
]

Johann-S's avatar
Johann-S committed
23
24
25
26
27
const plugins = [
  'karma-qunit',
  'karma-sinon'
]

Johann-S's avatar
Johann-S committed
28
29
30
31
32
const reporters = ['dots']

const detectBrowsers = {
  usePhantomJS: false,
  postDetection(availableBrowser) {
33
    if (typeof env.TRAVIS_JOB_ID !== 'undefined' || availableBrowser.includes('Chrome')) {
34
      return debug ? ['Chrome'] : ['ChromeHeadless']
Johann-S's avatar
Johann-S committed
35
36
37
    }

    if (availableBrowser.includes('Firefox')) {
38
      return debug ? ['Firefox'] : ['FirefoxHeadless']
Johann-S's avatar
Johann-S committed
39
40
41
42
43
44
45
46
47
48
49
50
51
    }

    throw new Error('Please install Firefox or Chrome')
  }
}

const customLaunchers = {
  FirefoxHeadless: {
    base: 'Firefox',
    flags: ['-headless']
  }
}

52
53
54
55
56
let files = [
  'node_modules/popper.js/dist/umd/popper.min.js',
  'node_modules/hammer-simulator/index.js'
]

Johann-S's avatar
Johann-S committed
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
const conf = {
  basePath: '../..',
  port: 9876,
  colors: true,
  autoWatch: false,
  singleRun: true,
  concurrency: Infinity,
  client: {
    qunit: {
      showUI: true
    }
  }
}

if (bundle) {
  frameworks.push('detectBrowsers')
  plugins.push(
    'karma-chrome-launcher',
    'karma-firefox-launcher',
    'karma-detect-browsers'
  )
  conf.customLaunchers = customLaunchers
  conf.detectBrowsers = detectBrowsers
  files = files.concat([
    jqueryFile,
Johann-S's avatar
Johann-S committed
82
    'js/tests/unit/tests-polyfills.js',
83
    'dist/js/bootstrap.js',
Johann-S's avatar
Johann-S committed
84
    'js/tests/unit/!(tests-polyfills).js'
Johann-S's avatar
Johann-S committed
85
86
87
88
  ])
} else if (browserStack) {
  conf.hostname = ip.address()
  conf.browserStack = {
89
90
    username: env.BROWSER_STACK_USERNAME,
    accessKey: env.BROWSER_STACK_ACCESS_KEY,
Johann-S's avatar
Johann-S committed
91
92
93
94
95
96
97
98
99
    build: `bootstrap-${new Date().toISOString()}`,
    project: 'Bootstrap',
    retryLimit: 2
  }
  plugins.push('karma-browserstack-launcher')
  conf.customLaunchers = browsers
  conf.browsers = browsersKeys
  reporters.push('BrowserStack')
  files = files.concat([
100
    jqueryFile,
Johann-S's avatar
Johann-S committed
101
    'js/tests/unit/tests-polyfills.js',
102
103
    'js/coverage/dist/util/util.js',
    'js/coverage/dist/util/sanitizer.js',
Johann-S's avatar
Johann-S committed
104
    'js/coverage/dist/dom/polyfill.js',
105
106
107
108
    'js/coverage/dist/dom/eventHandler.js',
    'js/coverage/dist/dom/selectorEngine.js',
    'js/coverage/dist/dom/data.js',
    'js/coverage/dist/dom/manipulator.js',
109
    'js/coverage/dist/dom/!(polyfill).js',
110
111
    'js/coverage/dist/tooltip.js',
    'js/coverage/dist/!(util|index|tooltip).js', // include all of our js/dist files except util.js, index.js and tooltip.js
Johann-S's avatar
Johann-S committed
112
    'js/tests/unit/!(tests-polyfills).js',
113
114
    'js/tests/unit/dom/*.js',
    'js/tests/unit/util/*.js'
Johann-S's avatar
Johann-S committed
115
116
117
118
119
120
121
122
123
124
125
  ])
} else {
  frameworks.push('detectBrowsers')
  plugins.push(
    'karma-chrome-launcher',
    'karma-firefox-launcher',
    'karma-detect-browsers',
    'karma-coverage-istanbul-reporter'
  )
  files = files.concat([
    jqueryFile,
Johann-S's avatar
Johann-S committed
126
    'js/tests/unit/tests-polyfills.js',
127
128
    'js/coverage/dist/util/util.js',
    'js/coverage/dist/util/sanitizer.js',
Johann-S's avatar
Johann-S committed
129
    'js/coverage/dist/dom/polyfill.js',
Johann-S's avatar
Johann-S committed
130
131
132
133
    'js/coverage/dist/dom/eventHandler.js',
    'js/coverage/dist/dom/selectorEngine.js',
    'js/coverage/dist/dom/data.js',
    'js/coverage/dist/dom/manipulator.js',
134
    'js/coverage/dist/dom/!(polyfill).js',
Johann-S's avatar
Johann-S committed
135
    'js/coverage/dist/tooltip.js',
136
    'js/coverage/dist/!(util|index|tooltip).js', // include all of our js/dist files except util.js, index.js and tooltip.js
Johann-S's avatar
Johann-S committed
137
    'js/tests/unit/!(tests-polyfills).js',
138
139
    'js/tests/unit/dom/*.js',
    'js/tests/unit/util/*.js'
Johann-S's avatar
Johann-S committed
140
141
142
143
144
  ])
  reporters.push('coverage-istanbul')
  conf.customLaunchers = customLaunchers
  conf.detectBrowsers = detectBrowsers
  conf.coverageIstanbulReporter = {
145
    dir: path.resolve(__dirname, '../coverage/'),
Johann-S's avatar
Johann-S committed
146
147
148
149
150
    reports: ['lcov', 'text-summary'],
    thresholds: {
      emitWarning: false,
      global: {
        statements: 90,
151
152
        branches: 86,
        functions: 89,
Johann-S's avatar
Johann-S committed
153
        lines: 90
154
155
156
157
158
159
160
161
162
163
      },
      each: {
        overrides: {
          'js/src/dom/polyfill.js': {
            statements: 39,
            lines: 37,
            branches: 19,
            functions: 50
          }
        }
164
      }
165
    }
Johann-S's avatar
Johann-S committed
166
167
  }

168
169
170
171
172
  if (debug) {
    conf.singleRun = false
    conf.autoWatch = true
  }
}
Johann-S's avatar
Johann-S committed
173
174
175
176
177
178

conf.frameworks = frameworks
conf.plugins = plugins
conf.reporters = reporters
conf.files = files

XhmikosR's avatar
XhmikosR committed
179
module.exports = karmaConfig => {
Johann-S's avatar
Johann-S committed
180
181
182
  // 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)
183
}