|
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 |
| 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 | + 'site/docs/4.1/assets/js/vendor/popper.min.js', |
| 76 | + 'dist/js/bootstrap.js' |
| 77 | + ]) |
| 78 | +} else if (browserStack) { |
| 79 | + conf.hostname = ip.address() |
| 80 | + conf.browserStack = { |
| 81 | + username: process.env.BROWSER_STACK_USERNAME, |
| 82 | + accessKey: process.env.BROWSER_STACK_ACCESS_KEY, |
| 83 | + build: `bootstrap-${new Date().toISOString()}`, |
| 84 | + project: 'Bootstrap', |
| 85 | + retryLimit: 2 |
| 86 | + } |
| 87 | + plugins.push('karma-browserstack-launcher') |
| 88 | + conf.customLaunchers = browsers |
| 89 | + conf.browsers = browsersKeys |
| 90 | + reporters.push('BrowserStack') |
| 91 | + files = files.concat([ |
| 92 | + 'site/docs/4.1/assets/js/vendor/jquery-slim.min.js', |
| 93 | + 'site/docs/4.1/assets/js/vendor/popper.min.js', |
| 94 | + 'js/dist/util.js', |
| 95 | + 'js/dist/tooltip.js', |
| 96 | + 'js/dist/!(util|index|tooltip).js' // include all of our js/dist files except util.js, index.js and tooltip.js |
| 97 | + ]) |
| 98 | +} else { |
| 99 | + frameworks.push('detectBrowsers') |
| 100 | + plugins.push( |
| 101 | + 'karma-chrome-launcher', |
| 102 | + 'karma-firefox-launcher', |
| 103 | + 'karma-detect-browsers', |
| 104 | + 'karma-coverage-istanbul-reporter' |
| 105 | + ) |
| 106 | + files = files.concat([ |
| 107 | + jqueryFile, |
| 108 | + 'site/docs/4.1/assets/js/vendor/popper.min.js', |
| 109 | + 'js/coverage/dist/util.js', |
| 110 | + 'js/coverage/dist/tooltip.js', |
| 111 | + 'js/coverage/dist/!(util|index|tooltip).js' // include all of our js/dist files except util.js, index.js and tooltip.js |
| 112 | + ]) |
| 113 | + reporters.push('coverage-istanbul') |
| 114 | + conf.customLaunchers = customLaunchers |
| 115 | + conf.detectBrowsers = detectBrowsers |
| 116 | + conf.coverageIstanbulReporter = { |
| 117 | + dir: jsCoveragePath, |
| 118 | + reports: ['lcov', 'text-summary'], |
| 119 | + thresholds: { |
| 120 | + emitWarning: false, |
| 121 | + global: { |
| 122 | + statements: 90, |
| 123 | + branches: 84, |
| 124 | + functions: 87, |
| 125 | + lines: 90 |
73 | 126 | } |
74 | 127 | } |
75 | | - }) |
| 128 | + } |
| 129 | +} |
| 130 | + |
| 131 | +files.push('js/tests/unit/*.js') |
| 132 | + |
| 133 | +conf.frameworks = frameworks |
| 134 | +conf.plugins = plugins |
| 135 | +conf.reporters = reporters |
| 136 | +conf.files = files |
| 137 | + |
| 138 | +module.exports = (karmaConfig) => { |
| 139 | + // possible values: karmaConfig.LOG_DISABLE || karmaConfig.LOG_ERROR || karmaConfig.LOG_WARN || karmaConfig.LOG_INFO || karmaConfig.LOG_DEBUG |
| 140 | + conf.logLevel = karmaConfig.LOG_ERROR || karmaConfig.LOG_WARN |
| 141 | + karmaConfig.set(conf) |
76 | 142 | } |
0 commit comments