forked from JamesMessinger/json-schema-lib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
karma.conf.js
160 lines (140 loc) · 3.88 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
// Karma config
// https://karma-runner.github.io/0.12/config/configuration-file.html
'use strict';
module.exports = function (karma) {
var config = {
frameworks: ['mocha', 'chai', 'sinon', 'host-environment'],
reporters: ['verbose'],
files: [
// JsonSchemaLib
'dist/json-schema-lib.min.js',
{ pattern: '*.map', included: false, served: true },
// Test Fixtures
'test/fixtures/*.js',
{ pattern: 'test/schemas/**', included: false, served: true },
// Test Specs
'test/specs/**/*.spec.js',
]
};
exitIfDisabled();
configureCodeCoverage(config);
configureLocalBrowsers(config);
configureSauceLabs(config);
console.log('Karma Config:\n', JSON.stringify(config, null, 2));
karma.set(config);
};
/**
* If this is a CI job, and Karma is not enabled, then exit.
* (useful for CI jobs that are only testing Node.js, not web browsers)
*/
function exitIfDisabled () {
var CI = process.env.CI === 'true';
var KARMA = process.env.KARMA === 'true';
if (CI && !KARMA) {
console.warn('Karma is not enabled');
process.exit();
}
}
/**
* Configures the code-coverage reporter
*/
function configureCodeCoverage (config) {
if (process.argv.indexOf('--cover') === -1) {
console.warn('Code-coverage is not enabled');
return;
}
config.reporters.push('coverage');
config.coverageReporter = {
reporters: [
{ type: 'text-summary' },
{ type: 'lcov' }
]
};
config.files = config.files.map(function (file) {
if (typeof file === 'string') {
file = file.replace(/^dist\/(.*?)(\.min)?\.js$/, 'dist/$1.test.js');
}
return file;
});
}
/**
* Configures the browsers for the current platform
*/
function configureLocalBrowsers (config) {
var isMac = /^darwin/.test(process.platform);
var isWindows = /^win/.test(process.platform);
var isLinux = !isMac && !isWindows;
if (isMac) {
config.browsers = ['Firefox', 'Chrome', 'Safari'];
}
else if (isLinux) {
config.browsers = ['Firefox', 'ChromeHeadless'];
}
else if (isWindows) {
config.browsers = ['Firefox', 'Chrome', 'IE9', 'IE10', 'IE'];
// NOTE: IE 6, 7, 8 are not supported by Chai
config.customLaunchers = {
IE9: {
base: 'IE',
'x-ua-compatible': 'IE=EmulateIE9'
},
IE10: {
base: 'IE',
'x-ua-compatible': 'IE=EmulateIE10'
}
};
}
}
/**
* Configures Sauce Labs emulated browsers/devices.
* https://github.com/karma-runner/karma-sauce-launcher
*/
function configureSauceLabs (config) {
var SAUCE = process.env.SAUCE === 'true';
var username = process.env.SAUCE_USERNAME;
var accessKey = process.env.SAUCE_ACCESS_KEY;
if (!SAUCE || !username || !accessKey) {
console.warn('SauceLabs is not enabled');
return;
}
var project = require('./package.json');
var testName = project.name + ' v' + project.version;
var build = testName + ' Build #' + process.env.TRAVIS_JOB_NUMBER + ' @ ' + new Date();
/* eslint camelcase:off */
var sauceLaunchers = {
SauceLabs_Chrome_Latest: {
base: 'SauceLabs',
platform: 'Windows 10',
browserName: 'chrome'
},
SauceLabs_Firefox_Latest: {
base: 'SauceLabs',
platform: 'Windows 10',
browserName: 'firefox'
},
SauceLabs_Safari_Latest: {
base: 'SauceLabs',
platform: 'macOS 10.12',
browserName: 'safari'
},
SauceLabs_IE_9: {
base: 'SauceLabs',
platform: 'Windows 7',
browserName: 'internet explorer',
version: '9'
},
SauceLabs_IE_Edge: {
base: 'SauceLabs',
platform: 'Windows 10',
browserName: 'microsoftedge'
},
};
config.reporters.push('saucelabs');
config.browsers = Object.keys(sauceLaunchers);
config.customLaunchers = Object.assign(config.customLaunchers || {}, sauceLaunchers);
config.sauceLabs = {
build: build,
testName: testName,
tags: [project.name],
};
}