|
1 | 1 | /* eslint-env node */
|
2 | 2 | /* eslint no-process-env: 0 */
|
| 3 | +const ip = require('ip') |
| 4 | +const { |
| 5 | + browsers, |
| 6 | + browsersKeys |
| 7 | +} = require('./browsers') |
3 | 8 | const path = require('path')
|
4 | 9 | const jsCoveragePath = path.resolve(__dirname, '../coverage')
|
5 | 10 |
|
6 |
| -module.exports = (config) => { |
7 |
| - const jqueryFile = process.env.USE_OLD_JQUERY ? 'https://code.jquery.com/jquery-1.9.1.min.js' : 'site/docs/4.1/assets/js/vendor/jquery-slim.min.js' |
| 11 | +const jqueryFile = process.env.USE_OLD_JQUERY ? 'https://code.jquery.com/jquery-1.9.1.min.js' : 'site/docs/4.1/assets/js/vendor/jquery-slim.min.js' |
| 12 | +const bundle = process.env.BUNDLE === 'true' |
| 13 | +const browserStack = process.env.BROWSER === 'true' |
8 | 14 |
|
9 |
| - config.set({ |
10 |
| - basePath: '../..', |
11 |
| - frameworks: ['qunit', 'sinon', 'detectBrowsers'], |
12 |
| - plugins: [ |
13 |
| - 'karma-chrome-launcher', |
14 |
| - 'karma-firefox-launcher', |
15 |
| - 'karma-qunit', |
16 |
| - 'karma-sinon', |
17 |
| - 'karma-detect-browsers', |
18 |
| - 'karma-coverage-istanbul-reporter' |
19 |
| - ], |
20 |
| - // list of files / patterns to load in the browser |
21 |
| - files: [ |
22 |
| - jqueryFile, |
23 |
| - 'site/docs/4.1/assets/js/vendor/popper.min.js', |
24 |
| - 'js/coverage/dist/util.js', |
25 |
| - 'js/coverage/dist/tooltip.js', |
26 |
| - 'js/coverage/dist/!(util|index|tooltip).js', // include all of our js/dist files except util.js, index.js and tooltip.js |
27 |
| - 'js/tests/unit/*.js' |
28 |
| - ], |
29 |
| - reporters: ['dots', 'coverage-istanbul'], |
30 |
| - port: 9876, |
31 |
| - colors: true, |
32 |
| - // possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG |
33 |
| - logLevel: config.LOG_ERROR || config.LOG_WARN, |
34 |
| - autoWatch: false, |
35 |
| - customLaunchers: { |
36 |
| - FirefoxHeadless: { |
37 |
| - base: 'Firefox', |
38 |
| - flags: ['-headless'] |
39 |
| - } |
40 |
| - }, |
41 |
| - singleRun: true, |
42 |
| - concurrency: Infinity, |
43 |
| - detectBrowsers: { |
44 |
| - usePhantomJS: false, |
45 |
| - postDetection(availableBrowser) { |
46 |
| - if (typeof process.env.TRAVIS_JOB_ID !== 'undefined' || availableBrowser.includes('Chrome')) { |
47 |
| - return ['ChromeHeadless'] |
48 |
| - } |
| 15 | +const frameworks = [ |
| 16 | + 'qunit', |
| 17 | + 'sinon' |
| 18 | +] |
49 | 19 |
|
50 |
| - if (availableBrowser.includes('Firefox')) { |
51 |
| - return ['FirefoxHeadless'] |
52 |
| - } |
| 20 | +const plugins = [ |
| 21 | + 'karma-qunit', |
| 22 | + 'karma-sinon' |
| 23 | +] |
53 | 24 |
|
54 |
| - throw new Error('Please install Firefox or Chrome') |
55 |
| - } |
56 |
| - }, |
57 |
| - coverageIstanbulReporter: { |
58 |
| - dir: jsCoveragePath, |
59 |
| - reports: ['lcov', 'text-summary'], |
60 |
| - thresholds: { |
61 |
| - emitWarning: false, |
62 |
| - global: { |
63 |
| - statements: 90, |
64 |
| - branches: 84, |
65 |
| - functions: 87, |
66 |
| - lines: 90 |
67 |
| - } |
68 |
| - } |
69 |
| - }, |
70 |
| - client: { |
71 |
| - qunit: { |
72 |
| - showUI: true |
| 25 | +const reporters = ['dots'] |
| 26 | + |
| 27 | +const detectBrowsers = { |
| 28 | + usePhantomJS: false, |
| 29 | + postDetection(availableBrowser) { |
| 30 | + if (typeof process.env.TRAVIS_JOB_ID !== 'undefined' || availableBrowser.includes('Chrome')) { |
| 31 | + return ['ChromeHeadless'] |
| 32 | + } |
| 33 | + |
| 34 | + if (availableBrowser.includes('Firefox')) { |
| 35 | + return ['FirefoxHeadless'] |
| 36 | + } |
| 37 | + |
| 38 | + throw new Error('Please install Firefox or Chrome') |
| 39 | + } |
| 40 | +} |
| 41 | + |
| 42 | +const customLaunchers = { |
| 43 | + FirefoxHeadless: { |
| 44 | + base: 'Firefox', |
| 45 | + flags: ['-headless'] |
| 46 | + } |
| 47 | +} |
| 48 | + |
| 49 | +let files = ['site/docs/4.1/assets/js/vendor/popper.min.js'] |
| 50 | +const conf = { |
| 51 | + basePath: '../..', |
| 52 | + port: 9876, |
| 53 | + colors: true, |
| 54 | + autoWatch: false, |
| 55 | + singleRun: true, |
| 56 | + concurrency: Infinity, |
| 57 | + client: { |
| 58 | + qunit: { |
| 59 | + showUI: true |
| 60 | + } |
| 61 | + } |
| 62 | +} |
| 63 | + |
| 64 | +if (bundle) { |
| 65 | + frameworks.push('detectBrowsers') |
| 66 | + plugins.push( |
| 67 | + 'karma-chrome-launcher', |
| 68 | + 'karma-firefox-launcher', |
| 69 | + 'karma-detect-browsers' |
| 70 | + ) |
| 71 | + conf.customLaunchers = customLaunchers |
| 72 | + conf.detectBrowsers = detectBrowsers |
| 73 | + files = files.concat([ |
| 74 | + jqueryFile, |
| 75 | + 'dist/js/bootstrap.js' |
| 76 | + ]) |
| 77 | +} else if (browserStack) { |
| 78 | + conf.hostname = ip.address() |
| 79 | + conf.browserStack = { |
| 80 | + username: process.env.BROWSER_STACK_USERNAME, |
| 81 | + accessKey: process.env.BROWSER_STACK_ACCESS_KEY, |
| 82 | + build: `bootstrap-${new Date().toISOString()}`, |
| 83 | + project: 'Bootstrap', |
| 84 | + retryLimit: 2 |
| 85 | + } |
| 86 | + plugins.push('karma-browserstack-launcher') |
| 87 | + conf.customLaunchers = browsers |
| 88 | + conf.browsers = browsersKeys |
| 89 | + reporters.push('BrowserStack') |
| 90 | + files = files.concat([ |
| 91 | + 'site/docs/4.1/assets/js/vendor/jquery-slim.min.js', |
| 92 | + 'js/dist/util.js', |
| 93 | + 'js/dist/tooltip.js', |
| 94 | + 'js/dist/!(util|index|tooltip).js' // include all of our js/dist files except util.js, index.js and tooltip.js |
| 95 | + ]) |
| 96 | +} else { |
| 97 | + frameworks.push('detectBrowsers') |
| 98 | + plugins.push( |
| 99 | + 'karma-chrome-launcher', |
| 100 | + 'karma-firefox-launcher', |
| 101 | + 'karma-detect-browsers', |
| 102 | + 'karma-coverage-istanbul-reporter' |
| 103 | + ) |
| 104 | + files = files.concat([ |
| 105 | + jqueryFile, |
| 106 | + 'js/coverage/dist/util.js', |
| 107 | + 'js/coverage/dist/tooltip.js', |
| 108 | + 'js/coverage/dist/!(util|index|tooltip).js' // include all of our js/dist files except util.js, index.js and tooltip.js |
| 109 | + ]) |
| 110 | + reporters.push('coverage-istanbul') |
| 111 | + conf.customLaunchers = customLaunchers |
| 112 | + conf.detectBrowsers = detectBrowsers |
| 113 | + conf.coverageIstanbulReporter = { |
| 114 | + dir: jsCoveragePath, |
| 115 | + reports: ['lcov', 'text-summary'], |
| 116 | + thresholds: { |
| 117 | + emitWarning: false, |
| 118 | + global: { |
| 119 | + statements: 90, |
| 120 | + branches: 84, |
| 121 | + functions: 87, |
| 122 | + lines: 90 |
73 | 123 | }
|
74 | 124 | }
|
75 |
| - }) |
| 125 | + } |
| 126 | +} |
| 127 | + |
| 128 | +files.push('js/tests/unit/*.js') |
| 129 | + |
| 130 | +conf.frameworks = frameworks |
| 131 | +conf.plugins = plugins |
| 132 | +conf.reporters = reporters |
| 133 | +conf.files = files |
| 134 | + |
| 135 | +module.exports = (karmaConfig) => { |
| 136 | + // possible values: karmaConfig.LOG_DISABLE || karmaConfig.LOG_ERROR || karmaConfig.LOG_WARN || karmaConfig.LOG_INFO || karmaConfig.LOG_DEBUG |
| 137 | + conf.logLevel = karmaConfig.LOG_ERROR || karmaConfig.LOG_WARN |
| 138 | + karmaConfig.set(conf) |
76 | 139 | }
|
0 commit comments