forked from sweetalert2/sweetalert2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkarma.conf.js
165 lines (143 loc) · 3.28 KB
/
karma.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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
const noLaunch = process.argv.includes('--no-launch')
const testMinified = process.argv.includes('--minified')
const isSauce = process.argv.includes('--sauce')
const isNetlify = process.argv.includes('--netlify')
if (isNetlify) {
process.env.CHROME_BIN = require('puppeteer').executablePath()
}
const webpackConfig = {
devtool: 'inline-source-map',
module: {
rules: [
{
test: /\.js$/,
exclude: /(node_modules|dist)/,
use: {
loader: 'babel-loader',
options: {/* babel options */}
}
}
]
}
}
const karmaPlugins = [
'karma-coverage',
'karma-webpack',
'karma-qunit',
'karma-spec-reporter',
'karma-sourcemap-loader',
'karma-chrome-launcher',
'karma-firefox-launcher',
'karma-ie-launcher',
'karma-sauce-launcher'
]
const preprocessors = {
'test/qunit/**/*.js': [
'webpack',
'sourcemap'
],
'dist/*.js': [
'coverage'
]
}
const coverageReporter = {
dir: 'coverage',
reporters: [
{ type: 'html', subdir: '.' },
{ type: 'lcov', subdir: '.' }
]
}
const sauceLabsLaunchers = {
safari: {
base: 'SauceLabs',
browserName: 'Safari',
version: 'latest',
// TODO(@limonte): remove this line, the current latest 10.14 doesn't work (#1349)
platform: 'macOS 10.13'
},
// TODO(@limonte): doesn't work, revisit
// edge: {
// base: 'SauceLabs',
// browserName: 'MicrosoftEdge',
// version: 'latest'
// },
ie: {
base: 'SauceLabs',
browserName: 'internet explorer',
platformVersion: '11.0',
platform: 'Windows 7'
},
iphone: {
base: 'SauceLabs',
browserName: 'Safari',
deviceName: 'iPhone Simulator',
platformName: 'iOS',
platformVersion: 'latest'
},
}
function checkSauceCredentials () {
if (!process.env.SAUCE_USERNAME || !process.env.SAUCE_ACCESS_KEY) {
console.error('SAUCE_USERNAME and SAUCE_ACCESS_KEY environment variables must be set')
process.exit(1)
}
}
function getFiles () {
let files
if (testMinified) {
files = [
'dist/sweetalert2.all.min.js'
]
} else {
files = [
'dist/sweetalert2.css',
'dist/sweetalert2.js'
]
}
return files.concat([
'node_modules/promise-polyfill/dist/polyfill.min.js',
'test/qunit/**/*.js'
])
}
function getBrowsers () {
if (noLaunch) {
return []
}
let browsers = ['ChromeHeadless']
// Cron on GitHub Actions or check:qunit --sauce
if (isSauce) {
checkSauceCredentials()
browsers = Object.keys(sauceLabsLaunchers)
// GitHub Actions
} else if (process.env.GITHUB_ACTION) {
browsers = ['ChromeHeadless', 'FirefoxHeadless']
}
return browsers
}
function getReporters () {
const reporters = ['spec', 'saucelabs']
// GitHub Actions
if (process.env.GITHUB_ACTION && !testMinified) {
reporters.push('coverage')
}
return reporters
}
module.exports = function (config) {
config.set({
port: 3000,
plugins: karmaPlugins,
frameworks: ['qunit'],
qunit: { reorder: false },
customLaunchers: sauceLabsLaunchers,
files: getFiles(),
browsers: getBrowsers(),
reporters: getReporters(),
preprocessors,
coverageReporter,
webpack: webpackConfig,
webpackMiddleware: {
stats: 'errors-only'
},
captureTimeout: 360000,
browserNoActivityTimeout: 360000
})
}