forked from jwplayer/jwplayer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
karma.conf.js
167 lines (152 loc) · 5.57 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
'use strict';
/* eslint-env node */
/* eslint no-process-env: 0 */
const path = require('path');
const puppeteer = require('puppeteer');
const webpack = require('webpack');
const webpackConfig = require('./webpack.config.js')({ release: true });
const webpackKarmaConfig = Object.assign({}, webpackConfig, {
entry: null,
output: null,
mode: 'development',
devtool: false,
plugins: [
new webpack.DefinePlugin({
__SELF_HOSTED__: true,
__REPO__: '\'\'',
__DEBUG__: false,
__BUILD_VERSION__: '\'' + '8.2.2' + '\'',
__FLASH_VERSION__: 18.0
}),
],
externals: {
$: {
commonjs: 'jquery',
amd: 'jquery',
root: '$'
},
sinon: 'sinon'
},
resolve: Object.assign({}, webpackConfig.resolve, {
alias: Object.assign({}, webpackConfig.resolve.alias || {}, {
'test/underscore': path.resolve(__dirname + '/node_modules/underscore/underscore.js'),
'utils/video': path.resolve(__dirname + '/test/mock/video.js'),
// Tests using jQuery: api-test, jwplayer-selectplayer-test, setup-test
jquery: path.resolve(__dirname + '/node_modules/jquery/dist/jquery.js'),
sinon: path.resolve(__dirname + '/node_modules/sinon/pkg/sinon.js'),
data: path.resolve(__dirname + '/test/data'),
mock: path.resolve(__dirname + '/test/mock')
})
}),
module: Object.assign({}, webpackConfig.module, {
rules: [
{
enforce: 'post',
test: /\.js$/,
include: /(src)\/(js)\//,
loader: 'istanbul-instrumenter-loader'
}
].concat(webpackConfig.module.rules || []).map(rule => {
if (rule.options && rule.options.presets) {
rule.options.presets = rule.options.presets.map(preset => {
if (Array.isArray(preset) && preset[0] === 'env' && preset[1]) {
// karma-webpack fails if modules are not converted to commonjs by default
delete preset[1].modules;
}
return preset;
});
}
return rule;
}),
noParse: [
/node_modules\/sinon\//,
/node_modules\/jquery\//
].concat(webpackConfig.module.noParse || [])
})
});
module.exports = function(config) {
const env = process.env;
const isJenkins = !!env.JENKINS_HOME;
const serverPort = env.KARMA_PORT || 9876;
const testReporters = [
'mocha',
'coverage-istanbul'
];
let browsers = [
'ChromeHeadless',
'Chrome',
'Safari',
'Firefox',
'edge',
'ie11',
'iphone',
'android'
];
if (isJenkins) {
testReporters.push('junit');
process.env.CHROME_BIN = puppeteer.executablePath();
browsers = [
'ChromeHeadless',
'chrome',
'firefox',
'edge',
'ie11',
'iphone',
'android'
];
}
const packageInfo = JSON.parse(require('fs').readFileSync('package.json', 'utf8'));
config.set({
frameworks: ['mocha', 'sinon-chai'],
reporters: testReporters,
port: serverPort, // web server port
colors: true, // colors in the output (reporters and logs)
autoWatch: false, // watch file and execute tests whenever any file changes
singleRun: true, // if true, Karma captures browsers, runs the tests and exits
// Possible logLevel values:
// LOG_DISABLE
// LOG_ERROR
// LOG_WARN
// LOG_INFO
// LOG_DEBUG (useful for writing karma server network status messages to stdio)
logLevel: config.LOG_INFO,
browsers,
customLaunchers: require('./test/karma/browserstack-launchers'),
browserStack: {
username: env.BS_USERNAME || env.BROWSERSTACK_USERNAME,
accessKey: env.BS_AUTHKEY || env.BROWSERSTACK_ACCESS_KEY,
name: 'Unit Tests',
project: 'jwplayer',
build: env.BROWSERSTACK_BUILD || ('' + (env.JOB_NAME || 'local') + ' ' +
(env.BUILD_NUMBER || env.USER || env.GITHUB_USER) + ' ' +
(env.GIT_BRANCH || 'jwplayer') + ' ' + packageInfo.version) + ' ' +
(new Date()).toISOString(),
timeout: 300 // 5 minutes
},
// to avoid DISCONNECTED messages when connecting to BrowserStack
browserDisconnectTimeout: 20 * 1000, // default 2000
browserDisconnectTolerance: 1, // default 0
browserNoActivityTimeout: 10 * 1000, // default 10000
captureTimeout: 120 * 1000, // default 60000
files: [
{ pattern: './node_modules/intersection-observer/intersection-observer.js' },
{ pattern: './test/index.js' },
{ pattern: './test/files/**', included: false },
{ pattern: './src/js/*', included: false }
],
// preprocess matching files before serving them to the browser
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
preprocessors: {
'test/index.js': ['webpack']
},
coverageIstanbulReporter: {
reports: ['text-summary', 'html'],
dir: 'reports/coverage',
combineBrowserReports: true,
fixWebpackSourcePaths: true
},
webpack: webpackKarmaConfig,
// number of browsers to run at once
concurrency: Infinity
});
};