forked from APIDevTools/swagger-parser
-
Notifications
You must be signed in to change notification settings - Fork 0
/
karma.conf.js
152 lines (130 loc) · 3.97 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
// 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: [
// Third-Party Libraries
"https://cdn.rawgit.com/stephanebachelier/superagent-dist/1721239d/superagent.js",
// Polyfills for older browsers
"online/js/polyfills/promise.js",
"online/js/polyfills/typedarray.js",
// Swagger Parser
"dist/swagger-parser.min.js",
{ pattern: "dist/*.map", included: false, served: true },
// Test Fixtures
"test/fixtures/**/*.js",
// Tests
"test/specs/**/*.js",
{ pattern: "test/specs/**", included: false, served: true }
],
exclude: [
// Exclude these tests because some of the APIs are HUGE and cause timeouts.
// We still test them in Node though.
"test/specs/real-world/*",
]
};
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", "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`);
}
var 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;
// Exclude these tests when running on SauceLabs.
// For some reason, these tests seem to make SauceLabs unstable,
// and it frequently loses connection to the CI server, which causes the build to fail
config.exclude = [
"test/specs/invalid/*",
"test/specs/unknown/*",
"test/specs/validate-schema/*",
"test/specs/real-world/*",
];
}