karma.conf.js 3.76 KB
Newer Older
1
/* eslint-env node */
2
const path = require('path')
Johann-S's avatar
Johann-S committed
3
const ip = require('ip')
XhmikosR's avatar
XhmikosR committed
4
5
6
7
const babel = require('rollup-plugin-babel')
const istanbul = require('rollup-plugin-istanbul')
const resolve = require('rollup-plugin-node-resolve')

Johann-S's avatar
Johann-S committed
8
9
10
11
const {
  browsers,
  browsersKeys
} = require('./browsers')
12

XhmikosR's avatar
XhmikosR committed
13
const { env } = process
14
15
const browserStack = env.BROWSER === 'true'
const debug = env.DEBUG === 'true'
16
const frameworks = [
Johann-S's avatar
Johann-S committed
17
  'jasmine'
18
19
]

Johann-S's avatar
Johann-S committed
20
const plugins = [
Johann-S's avatar
Johann-S committed
21
22
  'karma-jasmine',
  'karma-rollup-preprocessor'
Johann-S's avatar
Johann-S committed
23
24
]

Johann-S's avatar
Johann-S committed
25
26
27
28
29
const reporters = ['dots']

const detectBrowsers = {
  usePhantomJS: false,
  postDetection(availableBrowser) {
30
    if (env.CI === true || availableBrowser.includes('Chrome')) {
31
      return debug ? ['Chrome'] : ['ChromeHeadless']
Johann-S's avatar
Johann-S committed
32
33
34
    }

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

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

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

const conf = {
  basePath: '../..',
  port: 9876,
  colors: true,
  autoWatch: false,
  singleRun: true,
  concurrency: Infinity,
  client: {
Johann-S's avatar
Johann-S committed
57
    clearContext: false
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
  },
  files: [
    'node_modules/hammer-simulator/index.js',
    { pattern: 'js/tests/units/**/*.spec.js', watched: !browserStack }
  ],
  preprocessors: {
    'js/tests/units/**/*.spec.js': ['rollup']
  },
  rollupPreprocessor: {
    plugins: [
      istanbul({
        exclude: ['js/tests/units/**/*.spec.js', 'js/tests/helpers/**/*.js']
      }),
      babel({
        // Only transpile our source code
        exclude: 'node_modules/**',
        // Include only required helpers
        externalHelpersWhitelist: [
          'defineProperties',
          'createClass',
          'inheritsLoose',
          'defineProperty',
          'objectSpread2'
        ],
        plugins: [
          '@babel/plugin-proposal-object-rest-spread'
        ]
      }),
      resolve()
    ],
    output: {
      format: 'iife',
      name: 'bootstrapTest',
      sourcemap: 'inline'
    }
Johann-S's avatar
Johann-S committed
93
94
95
  }
}

Johann-S's avatar
Johann-S committed
96
if (browserStack) {
Johann-S's avatar
Johann-S committed
97
98
  conf.hostname = ip.address()
  conf.browserStack = {
99
100
    username: env.BROWSER_STACK_USERNAME,
    accessKey: env.BROWSER_STACK_ACCESS_KEY,
Johann-S's avatar
Johann-S committed
101
102
103
104
    build: `bootstrap-${new Date().toISOString()}`,
    project: 'Bootstrap',
    retryLimit: 2
  }
Johann-S's avatar
Johann-S committed
105
  plugins.push('karma-browserstack-launcher', 'karma-jasmine-html-reporter')
Johann-S's avatar
Johann-S committed
106
107
  conf.customLaunchers = browsers
  conf.browsers = browsersKeys
Johann-S's avatar
Johann-S committed
108
  reporters.push('BrowserStack', 'kjhtml')
Johann-S's avatar
Johann-S committed
109
110
111
112
113
114
115
116
117
118
119
120
} 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 = {
121
    dir: path.resolve(__dirname, '../coverage/'),
Johann-S's avatar
Johann-S committed
122
123
124
125
126
    reports: ['lcov', 'text-summary'],
    thresholds: {
      emitWarning: false,
      global: {
        statements: 90,
Johann-S's avatar
Johann-S committed
127
128
        branches: 90,
        functions: 90,
Johann-S's avatar
Johann-S committed
129
        lines: 90
130
131
132
133
134
135
136
137
138
139
      },
      each: {
        overrides: {
          'js/src/dom/polyfill.js': {
            statements: 39,
            lines: 37,
            branches: 19,
            functions: 50
          }
        }
140
      }
141
    }
Johann-S's avatar
Johann-S committed
142
143
  }

144
  if (debug) {
Johann-S's avatar
Johann-S committed
145
146
147
    conf.hostname = ip.address()
    plugins.push('karma-jasmine-html-reporter')
    reporters.push('kjhtml')
148
149
150
151
    conf.singleRun = false
    conf.autoWatch = true
  }
}
Johann-S's avatar
Johann-S committed
152
153
154
155
156

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

XhmikosR's avatar
XhmikosR committed
157
module.exports = karmaConfig => {
Johann-S's avatar
Johann-S committed
158
159
160
  // 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)
161
}