forked from heremaps/harp.gl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
karma.options.js
199 lines (181 loc) · 7.56 KB
/
karma.options.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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
/*
* Copyright (C) 2017-2020 HERE Europe B.V.
* Licensed under Apache 2.0, see full license in LICENSE
* SPDX-License-Identifier: Apache-2.0
*/
//@ts-check
const path = require("path");
/**
* @type {import("karma").ConfigOptions}
*/
const options = function (isCoverage, isMapSdk, prefixDirectory) {
const reports = isCoverage
? {
"text-summary": "",
// Needed for codecov.io, includes html as well
lcov: "coverage"
}
: {};
// Fixes the prefix to search for files, required for running the tests from sdk
const fixPrefix = function (file) {
const appendPrefix = file => {
if (file.startsWith("**") || file.startsWith("node_modules")) {
return file;
} else {
return path.join(prefixDirectory, file);
}
};
if (typeof file === "string") {
return appendPrefix(file);
} else {
return {
...{ pattern: appendPrefix(file.pattern) },
// Conditionally add this if not undefined.
...(file.included !== undefined && { included: file.included })
};
}
};
return {
browsers: [
'ChromeDebug'
],
customLaunchers: {
ChromeDebug: {
base: 'Chrome',
flags: ['--no-sandbox', '--remote-debugging-port=9333', 'http://localhost:9876/debug.html']
}
},
frameworks: ["mocha", "karma-typescript"],
// web server port
port: 9876,
// enable / disable watching file and executing tests whenever any file changes
autoWatch: false,
// Continuous Integration mode
// if true, Karma captures browsers, runs the tests and exits
singleRun: true,
// Concurrency level
// how many browser should be started simultaneous
concurrency: Infinity,
// List of files / patterns to load in the browser these files minus the ones specified
// in the `exclude` property and where `included` isn't false. This dictates the code we
// are to check its coverage. Note, the tests themselves don't count to code coverage and
// are excluded using the karmaTypescriptConfig.coverage.exclude property.
files: [
"@here/harp-datasource-protocol/**/*.ts",
"@here/harp-debug-datasource/**/*.ts",
"@here/harp-geometry/**/*.ts",
"@here/harp-fetch/**/*.ts",
"@here/harp-utils/**/*.ts",
"@here/harp-geoutils/**/*.ts",
"@here/harp-mapview/**/*.ts",
"@here/harp-mapview-decoder/**/*.ts",
"@here/harp-materials/**/*.ts",
"@here/harp-text-canvas/**/*.ts",
"@here/harp-lrucache/**/*.ts",
"@here/harp-transfer-manager/**/*.ts",
"@here/harp-lines/**/*.ts",
"@here/harp-test-utils/**/*.ts",
"@here/harp-map-controls/**/*.ts",
"@here/harp-olp-utils/**/*.ts",
"@here/harp-webtile-datasource/**/*.ts",
// Resources here are fetched by URL, note these require the correct proxy to be setup
// see "proxies" below.
{
pattern: "@here/harp-test-utils/test/resources/*.*",
included: false
},
// This is needed to access the font resources when running the repo separate from the
// sdk.
{
pattern: "node_modules/@here/harp-fontcatalog/resources/**/*.*",
included: false
},
// This is needed when this repo is managed with the repo tool
{
pattern: "@here/harp-text-canvas/resources/fonts/**/*.*",
included: false
},
{
pattern: "@here/harp-mapview/test/resources/*.*",
included: false
},
{
pattern: "@here/harp-datasource-protocol/theme.schema.json",
included: false
},
"@here/harp-vectortile-datasource/lib/adapters/omv/proto/vector_tile.js",
"@here/harp-vectortile-datasource/**/*.ts",
"@here/harp-map-theme/test/DefaultThemeTest.ts",
// These files are needed for the test above.
{
pattern: "@here/harp-map-theme/resources/*.json",
included: false
}
].map(file => fixPrefix(file)),
// Files that are to be excluded from the list included above.
exclude: [
"**/test/rendering/**/*.*",
"@here/harp-test-utils/lib/rendering/RenderingTestResultServer.ts",
"@here/harp-test-utils/lib/rendering/RenderingTestResultCli.ts",
"@here/harp-datasource-protocol/test/ThemeTypingsTest.ts",
"**/*.d.ts"
].map(file => fixPrefix(file)),
// source files, that you wanna generate coverage for
// do not include tests or libraries
// (these files will be instrumented by Istanbul)
preprocessors: {
"@here/harp-vectortile-datasource/lib/adapters/omv/proto/vector_tile.js": [
"karma-typescript"
],
"@here/**/*.ts": ["karma-typescript"]
},
// We use coverage-istanbul instead of karma-typescript because it can output json format
// which provides numbers similar to the previous report and not very conservative numbers.
reporters: ["progress", "coverage-istanbul"],
coverageIstanbulReporter: {
// reports can be any that are listed here: https://github.com/istanbuljs/istanbuljs/tree/73c25ce79f91010d1ff073aa6ff3fd01114f90db/packages/istanbul-reports/lib
reports: ["html", "text-summary", "json"],
dir: path.join(__dirname, "coverage"),
"report-config": {
html: {
// outputs the report in ./coverage/html
subdir: "html"
}
}
},
proxies: {
// How to access the local resources, normally this would handled by webpack, but we need to
// bundle the tests with karma-typescript, so we have to configure where the resources are,
// by default the resources relative to the root base folder.
"/@here": "/base/@here",
"/@here/harp-fontcatalog/resources/": isMapSdk
? "/base/@here/harp-text-canvas/resources/fonts/"
: "/base/node_modules/@here/harp-fontcatalog/resources/"
},
karmaTypescriptConfig: {
tsconfig: "./tsconfig.json",
// Don't try to compile the referenced
compilerOptions: {
skipLibCheck: true,
// This is needed because there is a Typescript file which references vector_tile.js
allowJs: true
},
coverageOptions: {
instrumentation: isCoverage ? true : false,
// This is needed otherwise the tests are included in the code coverage %.
exclude: [
/test\/+/,
/vector_tile\.js/,
/\.node\.ts/,
/index.*\.ts/,
/\.tsx/,
/coresdk\/@here\/harp-test-utils\/lib\/rendering/
]
},
reports,
// "allowJs" tries to compile all sorts of stuff, so we need to restrict it.
exclude: ["**/webpack.*.js", "**/karma.*js"]
}
};
};
module.exports = { options };