karma.conf.js 2.05 KB
Newer Older
1
/* eslint-env node */
XhmikosR's avatar
XhmikosR committed
2
/* eslint no-process-env: 0 */
Johann-S's avatar
Johann-S committed
3
4
const path = require('path')
const jsCoveragePath = path.resolve(__dirname, '../coverage')
5
6
7
8
9
10
11
12
13
14
15

module.exports = (config) => {
  const jqueryFile = process.env.USE_OLD_JQUERY ? 'js/tests/vendor/jquery-1.9.1.min.js' : 'assets/js/vendor/jquery-slim.min.js'

  config.set({
    basePath: '../..',
    frameworks: ['qunit', 'detectBrowsers'],
    plugins: [
      'karma-chrome-launcher',
      'karma-firefox-launcher',
      'karma-qunit',
Johann-S's avatar
Johann-S committed
16
17
      'karma-detect-browsers',
      'karma-coverage-istanbul-reporter'
18
19
20
21
22
    ],
    // list of files / patterns to load in the browser
    files: [
      jqueryFile,
      'assets/js/vendor/popper.min.js',
Johann-S's avatar
Johann-S committed
23
24
25
      'js/coverage/dist/util.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
26
27
      'js/tests/unit/*.js'
    ],
Johann-S's avatar
Johann-S committed
28
    reporters: ['dots', 'coverage-istanbul'],
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
    port: 9876,
    colors: true,
    // possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
    logLevel: config.LOG_ERROR || config.LOG_WARN,
    autoWatch: false,
    customLaunchers: {
      FirefoxHeadless: {
        base: 'Firefox',
        flags: ['-headless']
      }
    },
    singleRun: true,
    concurrency: Infinity,
    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')
      }
Johann-S's avatar
Johann-S committed
55
56
57
58
59
60
61
62
63
64
65
66
67
68
    },
    coverageIstanbulReporter: {
      dir: jsCoveragePath,
      reports: ['lcov', 'text-summary'],
      fixWebpackSourcePaths: true,
      thresholds: {
        emitWarning: true,
        global: {
          statements: 80,
          lines: 80,
          branches: 80,
          functions: 80
        }
      }
69
70
71
    }
  })
}