-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathkarma.common.conf.js
131 lines (122 loc) · 4.27 KB
/
karma.common.conf.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
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
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
/**
* Copyright (c) 2021, Diabeloop
* Karma test configuration file
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
const path = require('path')
const _ = require('lodash')
const isWSL = _.isString(process.env.WSL_DISTRO_NAME)
const browsers = ['CustomChromeHeadless']
if (!isWSL) {
browsers.push('FirefoxHeadless')
}
const defaultConfig = {
autoWatch: false,
port: '8080',
browserNoActivityTimeout: 60000,
captureTimeout: 60000,
colors: true,
concurrency: 1,
singleRun: true,
browsers,
customLaunchers: {
CustomChromeHeadless: {
base: 'ChromeHeadless',
flags: [
'--enable-automation',
'--no-default-browser-check',
'--no-first-run',
'--disable-default-apps',
'--disable-popup-blocking',
'--disable-translate',
'--disable-background-timer-throttling',
'--disable-renderer-backgrounding',
'--disable-device-discovery-notifications',
'--disable-dev-shm-usage',
'--disable-gpu',
'--headless',
'--no-sandbox',
'--remote-debugging-port=9222'
]
}
},
junitReporter: {
logReport: false,
name: 'yourloops',
filename: 'junit.xml'
},
mime: {
'text/x-typescript': ['ts', 'tsx']
},
frameworks: ['mocha'],
reporters: ['mocha', 'junit'],
webpackMiddleware: {
noInfo: true,
stats: 'errors-only'
},
plugins: [
'karma-*',
require('./karma.junit.reporter')
]
}
let updatedConfig = null
/**
* @param {string} projectName "yourloops" | "blip" | "viz" | "tideline"
* @param {object} karmaConfig To override the default config
* @param {object} webpackConfig Project webpack config
* @param {boolean} typescriptProject true for typescript project
*/
function updateDefaultConfig(projectName, karmaConfig, webpackConfig, typescriptProject = false) {
delete webpackConfig.entry
delete webpackConfig.output
webpackConfig.devtool = 'inline-source-map'
if (typescriptProject) {
webpackConfig.module.rules[0].options = { configFile: 'test/tsconfig.test.json' }
}
updatedConfig = _.defaultsDeep(karmaConfig, defaultConfig)
// special config for unit test debug
if (process.env.DEBUG_UNIT_TEST === 'true') {
// since we're in debug, we do not want to run tests in headless
// we wait for a manual chrome visit to localhost:9876 to start tests
updatedConfig.browsers = []
updatedConfig.customLaunchers = {}
updatedConfig.port = '9876'
updatedConfig.reporters = ['mocha', 'junit', 'progress']
}
updatedConfig.files.unshift('../../node-compat.js')
updatedConfig.files.unshift('../../branding/**/*.css')
updatedConfig.webpack = webpackConfig
updatedConfig.junitReporter.name = projectName
updatedConfig.junitReporter.filename = path.join(__dirname, `reports/${projectName}.junit.xml`)
}
/**
* The export function to return by karma.conf.js
* @param {object} config
*/
function setKarmaConfig(config) {
updatedConfig.logLevel = config.LOG_INFO
config.set(updatedConfig)
}
module.exports = { updateDefaultConfig, setKarmaConfig }