|
1 | 1 | // Karma config |
2 | 2 | // https://karma-runner.github.io/0.12/config/configuration-file.html |
3 | | -"use strict"; |
4 | | - |
5 | | -module.exports = function (karma) { |
6 | | - var config = { |
7 | | - frameworks: ["mocha", "chai", "host-environment"], |
8 | | - reporters: ["verbose"], |
9 | | - |
10 | | - files: [ |
11 | | - // Polyfills for older browsers |
12 | | - "test/polyfills/promise.js", |
13 | | - "test/polyfills/typedarray.js", |
14 | | - |
15 | | - // Json Schema $Ref Parser |
16 | | - "dist/ref-parser.min.js", |
17 | | - { pattern: "dist/*.map", included: false, served: true }, |
18 | | - |
19 | | - // Test Fixtures |
20 | | - "test/fixtures/**/*.js", |
21 | | - |
22 | | - // Test Specs |
23 | | - "test/specs/**/*.parsed.js", |
24 | | - "test/specs/**/*.dereferenced.js", |
25 | | - "test/specs/**/*.bundled.js", |
26 | | - "test/specs/**/*.spec.js", |
27 | | - { pattern: "test/specs/**", included: false, served: true } |
28 | | - ] |
29 | | - }; |
30 | | - |
31 | | - configureCodeCoverage(config); |
32 | | - configureBrowsers(config); |
33 | | - |
34 | | - console.log("Karma Config:\n", JSON.stringify(config, null, 2)); |
35 | | - karma.set(config); |
36 | | -}; |
37 | | - |
38 | | -/** |
39 | | - * Configures the code-coverage reporter |
40 | | - */ |
41 | | -function configureCodeCoverage (config) { |
42 | | - if (process.argv.indexOf("--coverage") === -1) { |
43 | | - console.warn("Code-coverage is not enabled"); |
44 | | - return; |
45 | | - } |
46 | | - |
47 | | - config.reporters.push("coverage"); |
48 | | - config.coverageReporter = { |
49 | | - reporters: [ |
50 | | - { type: "text-summary" }, |
51 | | - { type: "lcov" } |
52 | | - ] |
53 | | - }; |
54 | | - |
55 | | - config.files = config.files.map(function (file) { |
56 | | - if (typeof file === "string") { |
57 | | - file = file.replace(/^dist\/(.*)\.min\.js$/, "dist/$1.coverage.js"); |
58 | | - } |
59 | | - return file; |
60 | | - }); |
61 | | -} |
62 | | - |
63 | | -/** |
64 | | - * Configures the browsers for the current platform |
65 | | - */ |
66 | | -function configureBrowsers (config) { |
67 | | - let isWindows = /^win/.test(process.platform) || process.env.WINDOWS === "true"; |
68 | | - let isMac = /^darwin/.test(process.platform); |
69 | | - let isLinux = !isMac && !isWindows; |
70 | | - let isCI = process.env.CI === "true"; |
71 | | - |
72 | | - if (isCI) { |
73 | | - if (isWindows) { |
74 | | - // IE and Edge aren't available in CI, so use SauceLabs |
75 | | - configureSauceLabs(config); |
76 | | - } |
77 | | - else if (isMac) { |
78 | | - config.browsers = ["FirefoxHeadless", "ChromeHeadless", "Safari"]; |
79 | | - } |
80 | | - else if (isLinux) { |
81 | | - config.browsers = ["FirefoxHeadless", "ChromeHeadless"]; |
82 | | - } |
83 | | - } |
84 | | - else if (isMac) { |
85 | | - config.browsers = ["Firefox", "Chrome", "Safari"]; |
86 | | - } |
87 | | - else if (isLinux) { |
88 | | - config.browsers = ["Firefox", "Chrome"]; |
89 | | - } |
90 | | - else if (isWindows) { |
91 | | - config.browsers = ["Firefox", "Chrome", "IE", "Edge"]; |
92 | | - } |
93 | | -} |
94 | | - |
95 | | -/** |
96 | | - * Configures Sauce Labs emulated browsers/devices. |
97 | | - * https://github.com/karma-runner/karma-sauce-launcher |
98 | | - */ |
99 | | -function configureSauceLabs (config) { |
100 | | - let username = process.env.SAUCE_USERNAME; |
101 | | - let accessKey = process.env.SAUCE_ACCESS_KEY; |
102 | | - |
103 | | - if (!username || !accessKey) { |
104 | | - throw new Error(`SAUCE_USERNAME and/or SAUCE_ACCESS_KEY is not set`); |
105 | | - } |
| 3 | +// https://jsdevtools.org/karma-config/ |
106 | 4 |
|
107 | | - let project = require("./package.json"); |
108 | | - |
109 | | - config.sauceLabs = { |
110 | | - build: `${project.name} v${project.version} Build #${process.env.TRAVIS_JOB_NUMBER}`, |
111 | | - testName: `${project.name} v${project.version}`, |
112 | | - tags: [project.name], |
113 | | - }; |
114 | | - |
115 | | - config.customLaunchers = { |
116 | | - IE_11: { |
117 | | - base: "SauceLabs", |
118 | | - platform: "Windows 7", |
119 | | - browserName: "internet explorer" |
120 | | - }, |
121 | | - Edge: { |
122 | | - base: "SauceLabs", |
123 | | - platform: "Windows 10", |
124 | | - browserName: "microsoftedge" |
125 | | - }, |
126 | | - }; |
127 | | - |
128 | | - config.reporters.push("saucelabs"); |
129 | | - config.browsers = Object.keys(config.customLaunchers); |
130 | | - // config.concurrency = 1; |
131 | | - config.captureTimeout = 60000; |
132 | | - config.browserDisconnectTolerance = 5, |
133 | | - config.browserDisconnectTimeout = 60000; |
134 | | - config.browserNoActivityTimeout = 60000; |
135 | | - // config.logLevel = "debug"; |
136 | | - |
137 | | - // The following tests tend to fail on SauceLabs, |
138 | | - // probably due to zero-byte files and special characters in the paths. |
139 | | - // So, exclude these tests when running on SauceLabs. |
140 | | - config.exclude = [ |
| 5 | +"use strict"; |
| 6 | +const { karmaConfig } = require("karma-config"); |
| 7 | +let exclude = []; |
| 8 | + |
| 9 | +if (process.env.WINDOWS && process.env.CI) { |
| 10 | + // We're running in a Windows CI/CD environment, so Karma-Config will use SauceLabs. |
| 11 | + // The following tests tend to fail on SauceLabs, probably due to zero-byte files |
| 12 | + // and special characters in the paths. So, exclude them. |
| 13 | + exclude.push( |
141 | 14 | "test/specs/__*/**", |
142 | 15 | "test/specs/blank/**/*.spec.js", |
143 | 16 | "test/specs/circular*/**/*.spec.js", |
144 | 17 | "test/specs/empty/**/*.spec.js", |
145 | 18 | "test/specs/invalid/**/*.spec.js", |
146 | 19 | "test/specs/parsers/**/*.spec.js" |
147 | | - ]; |
| 20 | + ); |
148 | 21 | } |
| 22 | + |
| 23 | +module.exports = karmaConfig({ |
| 24 | + sourceDir: "lib", |
| 25 | + fixtures: "test/fixtures/**/*.js", |
| 26 | + browsers: { |
| 27 | + ie: true, |
| 28 | + }, |
| 29 | + config: { |
| 30 | + exclude, |
| 31 | + } |
| 32 | +}); |
0 commit comments