-
-
Notifications
You must be signed in to change notification settings - Fork 234
/
Copy pathkarma.conf.js
148 lines (129 loc) · 3.89 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
// Karma config
// https://karma-runner.github.io/0.12/config/configuration-file.html
"use strict";
module.exports = function (karma) {
var config = {
frameworks: ["mocha", "chai", "host-environment"],
reporters: ["verbose"],
files: [
// Polyfills for older browsers
"test/polyfills/promise.js",
"test/polyfills/typedarray.js",
// Json Schema $Ref Parser
"dist/ref-parser.min.js",
{ pattern: "dist/*.map", included: false, served: true },
// Test Fixtures
"test/fixtures/**/*.js",
// Test Specs
"test/specs/**/*.parsed.js",
"test/specs/**/*.dereferenced.js",
"test/specs/**/*.bundled.js",
"test/specs/**/*.spec.js",
{ pattern: "test/specs/**", included: false, served: true }
]
};
configureCodeCoverage(config);
configureBrowsers(config);
console.log("Karma Config:\n", JSON.stringify(config, null, 2));
karma.set(config);
};
/**
* Configures the code-coverage reporter
*/
function configureCodeCoverage (config) {
if (process.argv.indexOf("--coverage") === -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.coverage.js");
}
return file;
});
}
/**
* Configures the browsers for the current platform
*/
function configureBrowsers (config) {
let isWindows = /^win/.test(process.platform) || process.env.WINDOWS === "true";
let isMac = /^darwin/.test(process.platform);
let isLinux = !isMac && !isWindows;
let isCI = process.env.CI === "true";
if (isCI) {
if (isWindows) {
// IE and Edge aren't available in CI, so use SauceLabs
configureSauceLabs(config);
}
else if (isMac) {
config.browsers = ["FirefoxHeadless", "ChromeHeadless", "Safari"];
}
else if (isLinux) {
config.browsers = ["FirefoxHeadless", "ChromeHeadless"];
}
}
else if (isMac) {
config.browsers = ["Firefox", "Chrome", "Safari"];
}
else if (isLinux) {
config.browsers = ["Firefox", "Chrome"];
}
else if (isWindows) {
config.browsers = ["Firefox", "Chrome", "IE", "Edge"];
}
}
/**
* Configures Sauce Labs emulated browsers/devices.
* https://github.com/karma-runner/karma-sauce-launcher
*/
function configureSauceLabs (config) {
let username = process.env.SAUCE_USERNAME;
let accessKey = process.env.SAUCE_ACCESS_KEY;
if (!username || !accessKey) {
throw new Error(`SAUCE_USERNAME and/or SAUCE_ACCESS_KEY is not set`);
}
let project = require("./package.json");
config.sauceLabs = {
build: `${project.name} v${project.version} Build #${process.env.TRAVIS_JOB_NUMBER}`,
testName: `${project.name} v${project.version}`,
tags: [project.name],
};
config.customLaunchers = {
IE_11: {
base: "SauceLabs",
platform: "Windows 7",
browserName: "internet explorer"
},
Edge: {
base: "SauceLabs",
platform: "Windows 10",
browserName: "microsoftedge"
},
};
config.reporters.push("saucelabs");
config.browsers = Object.keys(config.customLaunchers);
// config.concurrency = 1;
config.captureTimeout = 60000;
config.browserDisconnectTolerance = 5,
config.browserDisconnectTimeout = 60000;
config.browserNoActivityTimeout = 60000;
// config.logLevel = "debug";
// The following tests tend to fail on SauceLabs,
// probably due to zero-byte files and special characters in the paths.
// So, exclude these tests when running on SauceLabs.
config.exclude = [
"test/specs/__*/**",
"test/specs/blank/**/*.spec.js",
"test/specs/circular*/**/*.spec.js",
"test/specs/empty/**/*.spec.js",
"test/specs/invalid/**/*.spec.js",
"test/specs/parsers/**/*.spec.js"
];
}