forked from knockout/tko
-
Notifications
You must be signed in to change notification settings - Fork 0
/
karma.conf.js
196 lines (177 loc) Β· 5.13 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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
const fs = require('fs')
const path = require('path')
const nodeResolve = require('rollup-plugin-node-resolve')
const rollupCommonJS = require('rollup-plugin-commonjs')
const rollupVisualizer = require('rollup-plugin-visualizer')
const typescript = require('typescript')
const pkg = JSON.parse(fs.readFileSync('package.json'))
const {SAUCE_USERNAME, SAUCE_ACCESS_KEY} = process.env
const root = path.join(process.cwd(), 'spec')
const {argv} = process
const VERSIONS_SYM = Symbol('Versions List')
// For options, see https://saucelabs.com/platforms
// https://wiki.saucelabs.com/display/DOCS/Platform+Configurator#/
//
// NOTE: When a selection below is unavailable the following unhelpful error
// is produced from webdriver.js:
//
// TypeError: Cannot read property 'value' of undefined
//
const SL_BROWSERS = {
CHROME: {
base: 'SauceLabs',
browserName: 'chrome',
[VERSIONS_SYM]: ['latest', 60, 55]//, 50, 45, 40, 35, 30]
},
FIREFOX: {
base: 'SauceLabs',
browserName: 'firefox',
[VERSIONS_SYM]: ['latest', 55, 50]
},
SAFARI: {
base: 'SauceLabs',
browserName: 'safari',
[VERSIONS_SYM]: ['latest']
},
EDGE: {
base: 'SauceLabs',
browserName: 'microsoftedge',
[VERSIONS_SYM]: ['latest']
},
IE: {
base: 'SauceLabs',
browserName: 'internet explorer',
[VERSIONS_SYM]: [11, 10, 9]
},
// π¨ The iPhone emulater on SauceLabs requires a huge connectionRetryTimeout
// because its startup time is around 90 seconds.
// IOS_SAFARI: {
// base: 'SauceLabs',
// browserName: 'iphone',
// version: 'latest'
// },
launchersFor (browser) {
const BROWSER = SL_BROWSERS[browser]
return BROWSER[VERSIONS_SYM].map(
v => ({ [`SL_${browser}_${v}`]: Object.assign({version: v}, BROWSER) })
)
}
}
const SAUCE_LAUNCHERS = Object.assign(
...SL_BROWSERS.launchersFor('CHROME'),
...SL_BROWSERS.launchersFor('FIREFOX'),
...SL_BROWSERS.launchersFor('SAFARI')
// ...SL_BROWSERS.launchersFor('EDGE'),
// ...SL_BROWSERS.launchersFor('IE')
)
console.log(`
π Karma being loaded at:
${process.cwd()}
`)
if (!pkg.karma || !pkg.karma.frameworks) {
console.warn(`
β οΈ package.json at ${process.cwd()} does not have "karma.frameworks"
`)
process.exit(0)
}
const replacerPlugin = {
name: 'tko-package-imports',
/**
* Resolve the path of tko.* packages, so
*
* tko.utils => packages/tko.utils/src/index.js
*
* We use sources so that we don't have multiple references
* from different sources e.g. `tko.computed` and `tko.observable`
* both importing `tko.utils` would generate multiple versions
* of objectMap that rollup transpiles as objectMap$1 and
* objectMap$2.
*
* Plus by doing this we won't need to rebuild dist/ files
* whenever we make changes to the source.
*/
resolveId (importee, importer) {
if (importee.includes('/')) { return }
const packagePath = path.join(__dirname, 'packages', importee, 'src/index.js')
if (fs.existsSync(packagePath)) { return packagePath }
}
}
const rollupPreprocessor = {
format: 'iife',
name: pkg.name,
plugins: [
replacerPlugin,
nodeResolve({ module: true }),
rollupCommonJS(),
rollupVisualizer({ filename: './visual.html' })
],
/**
* Source maps often link multiple files (e.g. tko.utils/src/object.js)
* from different spec/ files. This causes problems e.g. a breakpoints
* occur in the wrong spec/ file.
*
* Nevertheless enabling source maps when there's only one test file
* can be illuminating, so it's an option.
*/
sourcemap: argv.includes('--sourcemap') ? 'inline' : false
}
const typescriptPreprocessor = {
typescript,
options: {
target: 'ES5',
lib: ['DOM', 'ES5', 'ES6', 'ScriptHost', 'ES2015', 'ES2016', 'ES2017'],
removeComments: false,
downlevelIteration: true
}
}
const COMMON_CONFIG = {
rollupPreprocessor,
typescriptPreprocessor,
basePath: process.cwd(),
frameworks: pkg.karma.frameworks,
resolve: { root },
files: [
{ pattern: 'spec/*.js', watched: false }
],
preprocessors: {
'spec/**/*.js': ['rollup', 'typescript']
}
}
module.exports = (config) => {
if (argv.includes('--sauce')) {
if (!SAUCE_USERNAME) {
throw new Error('Environment needs SAUCE_USERNAME')
}
if (!SAUCE_ACCESS_KEY) {
throw new Error('Environment needs SAUCE_ACCESS_KEY')
}
config.set(Object.assign({
sauceLabs: {
testName: `${pkg.name} @ ${pkg.version}`,
startConnect: !argv.includes('--noStartConnect'),
public: 'public'
},
colors: true,
captureTimeout: 120000,
browserDisconnectTimeout: 100000,
browserNoActivityTimeout: 100000,
customLaunchers: SAUCE_LAUNCHERS,
browsers: Object.keys(SAUCE_LAUNCHERS),
reporters: ['dots', 'saucelabs'],
singleRun: true
}, COMMON_CONFIG))
} else {
config.set(Object.assign({
electronOpts: {
frame: false,
resizable: false,
focusable: false,
show: false,
fullscreenable: false,
hasShadow: false
},
browsers: ['Electron'],
singleRun: argv.includes('--once')
}, COMMON_CONFIG))
}
}