karma.conf.js 3.98 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

11
const jqueryFile = process.env.USE_OLD_JQUERY ? 'https://code.jquery.com/jquery-1.9.1.min.js' : 'node_modules/jquery/dist/jquery.slim.min.js'
Johann-S's avatar
Johann-S committed
12
13
const bundle = process.env.BUNDLE === 'true'
const browserStack = process.env.BROWSER === 'true'
14

15
16
17
18
19
const frameworks = [
  'qunit',
  'sinon'
]

Johann-S's avatar
Johann-S committed
20
21
22
23
24
const plugins = [
  'karma-qunit',
  'karma-sinon'
]

Johann-S's avatar
Johann-S committed
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
const reporters = ['dots']

const detectBrowsers = {
  usePhantomJS: false,
  postDetection(availableBrowser) {
    if (typeof process.env.TRAVIS_JOB_ID !== 'undefined' || availableBrowser.includes('Chrome')) {
      return ['ChromeHeadless']
    }

    if (availableBrowser.includes('Firefox')) {
      return ['FirefoxHeadless']
    }

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

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

49
50
51
52
53
let files = [
  'node_modules/popper.js/dist/umd/popper.min.js',
  'node_modules/hammer-simulator/index.js'
]

Johann-S's avatar
Johann-S committed
54
55
56
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
82
83
84
85
86
87
88
89
90
91
92
93
94
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,
    'dist/js/bootstrap.js'
  ])
} else if (browserStack) {
  conf.hostname = ip.address()
  conf.browserStack = {
    username: process.env.BROWSER_STACK_USERNAME,
    accessKey: process.env.BROWSER_STACK_ACCESS_KEY,
    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([
95
    'node_modules/jquery/dist/jquery.slim.min.js',
96
97
98
99
100
101
102
103
104
105
    'js/coverage/dist/dom/eventHandler.js',
    'js/coverage/dist/dom/selectorEngine.js',
    'js/coverage/dist/dom/data.js',
    'js/coverage/dist/dom/manipulator.js',
    'js/coverage/dist/util.js',
    'js/coverage/dist/dom/*.js',
    '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
    'js/tests/unit/*.js',
    'js/tests/unit/dom/*.js'
Johann-S's avatar
Johann-S committed
106
107
108
109
110
111
112
113
114
115
116
  ])
} 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
117
118
119
120
    'js/coverage/dist/dom/eventHandler.js',
    'js/coverage/dist/dom/selectorEngine.js',
    'js/coverage/dist/dom/data.js',
    'js/coverage/dist/dom/manipulator.js',
Johann-S's avatar
Johann-S committed
121
    'js/coverage/dist/util.js',
122
    'js/coverage/dist/dom/*.js',
Johann-S's avatar
Johann-S committed
123
    'js/coverage/dist/tooltip.js',
124
125
126
    'js/coverage/dist/!(util|index|tooltip).js', // include all of our js/dist files except util.js, index.js and tooltip.js
    'js/tests/unit/*.js',
    'js/tests/unit/dom/*.js'
Johann-S's avatar
Johann-S committed
127
128
129
130
131
  ])
  reporters.push('coverage-istanbul')
  conf.customLaunchers = customLaunchers
  conf.detectBrowsers = detectBrowsers
  conf.coverageIstanbulReporter = {
132
    dir: path.resolve(__dirname, '../coverage/'),
Johann-S's avatar
Johann-S committed
133
134
135
136
137
    reports: ['lcov', 'text-summary'],
    thresholds: {
      emitWarning: false,
      global: {
        statements: 90,
138
139
        branches: 86,
        functions: 89,
Johann-S's avatar
Johann-S committed
140
        lines: 90
141
      }
142
    }
Johann-S's avatar
Johann-S committed
143
144
145
146
147
148
149
150
151
152
153
154
155
156
  }
}

files.push('js/tests/unit/*.js')

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

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 || karmaConfig.LOG_WARN
  karmaConfig.set(conf)
157
}