Repository navigation
Expand file tree
/
Copy pathkarma.conf.js
More file actions
278 lines (274 loc) · 9.37 KB
/
Copy pathkarma.conf.js
File metadata and controls
278 lines (274 loc) · 9.37 KB
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
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
// @ts-check
const path = require('path');
const os = require('os');
const fs = require('fs');
/**
* Resolve the Chrome/Chromium binary that karma-chrome-launcher should use.
*
* Historically this unconditionally set CHROME_BIN to puppeteer's bundled
* Chromium path. Under pnpm, puppeteer's optional download (an install script)
* may not have run, in which case `executablePath()` still returns a path that
* does not exist on disk - karma then fails with "Cannot start ChromeHeadless /
* Can not find the binary ...". To stay robust:
* 1. Honor a CHROME_BIN already provided by the environment (e.g. a system
* Chrome installed by CI).
* 2. Otherwise fall back to puppeteer's Chromium, but only if it actually
* exists on disk.
* 3. Otherwise leave CHROME_BIN unset so karma-chrome-launcher can auto-detect
* an installed Chrome.
*/
if (!process.env.CHROME_BIN) {
try {
const puppeteerChrome = require('puppeteer').executablePath();
if (puppeteerChrome && fs.existsSync(puppeteerChrome)) {
process.env.CHROME_BIN = puppeteerChrome;
}
} catch (err) {
// puppeteer not installed / no bundled Chromium - rely on a system Chrome.
}
}
/**
*
* Tests for the dicomImageLoaders require support for Web Workers and loading
* wasm files required for image decoding.
*
* In order to support this, the karma config requires some customisation. This
* is based on
* https://github.com/codymikol/karma-webpack/issues/498#issuecomment-790040818
*
* The changes are:
* - Define a custom output path for webpack to emit files to
* - Serve the output path via a `files` entry in the karma config
*
* Without this, webpack correctly bundles and outputs the worker and wasm
* files, but they can't be loaded by the tests. Trying to load the worker or
* wasm files returns a 404.
*
* Manually create an output path. This is the same as the default
* karma-webpack config
* https://github.com/codymikol/karma-webpack?tab=readme-ov-file#default-webpack-configuration
*/
const outputPath =
path.join(os.tmpdir(), '_karma_webpack_') +
Math.floor(Math.random() * 1000000);
const forceCompat = process.env.FORCE_COMPAT === 'true';
const forceCpuRendering = process.env.FORCE_CPU_RENDERING === 'true';
const grepPattern = process.env.KARMA_GREP;
/** @param {import('karma').Config} config */
module.exports = function (config) {
config.set({
reporters: ['junit', 'coverage', 'spec'],
client: {
forceCpuRendering,
forceCompat,
args: grepPattern ? ['--grep', grepPattern] : [],
jasmine: {
random: false, // don't randomize the order of tests
stopOnFailure: false,
failFast: false,
},
// Set to true to capture WARN level logging
// See browserConsoleLogOptions for setting other log levels
captureConsole: true,
clearContext: false,
},
concurrency: 1,
browserConsoleLogOptions: {
terminal: true,
level: 'log',
},
specReporter: {
maxLogLines: 5, // limit number of lines logged per test
suppressSummary: true, // do not print summary
suppressErrorSummary: true, // do not print error summary
suppressFailed: false, // do not print information about failed tests
suppressPassed: false, // do not print information about passed tests
suppressSkipped: true, // do not print information about skipped tests
showSpecTiming: false, // print the time elapsed for each spec
failFast: false, // test would finish with error when a first fail occurs
prefixes: {
success: ' PASS: ', // override prefix for passed tests, default is '✓ '
failure: 'FAILED: ', // override prefix for failed tests, default is '✗ '
skipped: 'SKIPPED: ', // override prefix for skipped tests, default is '- '
},
},
junitReporter: {
outputDir: 'junit',
outputFile: 'test-results.xml',
},
plugins: [
'karma-webpack',
'karma-jasmine',
'karma-chrome-launcher',
// Reports / Output
'karma-junit-reporter',
'karma-coverage',
'karma-spec-reporter',
],
frameworks: ['jasmine', 'webpack'],
files: [
...(process.env.KARMA_PACKAGE === 'core'
? []
: ['packages/tools/test/**/*_test.js']),
...(process.env.KARMA_PACKAGE === 'tools'
? []
: ['packages/core/test/**/*_test.js']),
// Named individually rather than globbed: the rest of
// packages/dicomImageLoader/test predates the move to jasmine and still
// uses mocha's before()/chai, so a glob would switch on suites that
// cannot run.
'packages/dicomImageLoader/test/decoders_test.ts',
// Serve dicomImageLoad test images
{
pattern: 'packages/dicomImageLoader/testImages/**/*',
watched: false,
included: false,
served: true,
},
// Compat-mode baselines for dynamic comparison
{
pattern: 'karma-baselines/**/*.png',
watched: false,
included: false,
served: true,
},
/**
* Required to allow karma to load wasm and worker files built via webpack.
* See the comment at the top of this file for more details.
*/
{
pattern: `${outputPath}/**/*`,
included: false,
served: true,
watched: false,
},
],
proxies: {
'/testImages/': '/base/packages/dicomImageLoader/testImages/',
'/karma-baselines/': '/base/karma-baselines/',
},
preprocessors: {
'packages/core/test/**/*_test.js': ['webpack'],
'packages/tools/test/**/*_test.js': ['webpack'],
'packages/dicomImageLoader/test/decoders_test.ts': ['webpack'],
},
coverageReporter: {
type: 'html',
dir: 'coverage/',
},
// The default of 2 seconds is a bit short for some tests
browserNoActivityTimeout: 6000,
browserDisconnectTimeout: 6000,
/*webpackMiddleware: {
noInfo: true
},*/
webpack: {
devtool: 'eval-source-map',
mode: 'development',
output: {
/**
* Override default karma-webpack output path with the one we defined
* above this allows webpack generated files including wasm and workers
* to be served by karma without this, the default config won't allow
* tests to load web workers or wasm files.
*/
path: outputPath,
},
module: {
rules: [
{
test: /\.(js|jsx|ts|tsx)$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
options: {
plugins: [['babel-plugin-istanbul', {}]],
},
},
},
{
test: /\.wasm/,
type: 'asset/inline',
},
{
test: /\.png$/i,
use: [
{
loader: 'url-loader',
},
],
},
{
test: /\.wasm/,
type: 'asset/resource',
},
// NOTE: For better debugging you can comment out the
// istanbul-instrumenter-loader below
// {
// test: /\.ts$/,
// exclude: [path.resolve(__dirname, 'test')],
// enforce: 'post',
// use: {
// loader: 'istanbul-instrumenter-loader',
// options: { esModules: true },
// },
// },
],
},
experiments: {
asyncWebAssembly: true,
},
resolve: {
extensions: ['.ts', '.tsx', '.js', '.jsx'],
fallback: {
fs: false,
path: require.resolve('path-browserify'),
// vtk.js 36 pulls in xmlbuilder2@4 -> @oozcitak/url, which requires
// node's built-in 'url' module. It isn't needed for the XML parsing
// exercised by the tests, so stub it out for the browser bundle.
url: false,
},
alias: {
'@cornerstonejs/core': path.resolve('packages/core/src/index'),
'@cornerstonejs/tools': path.resolve('packages/tools/src/index'),
'@cornerstonejs/dicom-image-loader': path.resolve(
'packages/dicomImageLoader/src/index'
),
'@cornerstonejs/metadata': path.resolve(
'packages/metadata/src/index'
),
'@cornerstonejs/utils': path.resolve('packages/utils/src/index'),
},
},
},
webpackMiddleware: {
noInfo: false,
},
customLaunchers: {
ChromeHeadlessNoSandbox: {
base: 'ChromeHeadless',
flags: [
'--disable-translate',
'--disable-extensions',
'--no-sandbox',
'--ignore-gpu-blacklist',
'--remote-debugging-port=9229',
// vtk.js needs a WebGL context. Headless Chrome only provides one via
// a software (SwiftShader) GL backend. Older bundled Chromium enabled
// this by default, but Chrome 110+ requires it to be explicitly opted
// into - without these flags vtk.js' get3DContext() returns null and
// tests fail with "no webgl context". Unknown flags are ignored by
// older Chrome, so this is safe across versions.
'--use-gl=angle',
'--use-angle=swiftshader',
'--enable-unsafe-swiftshader',
],
},
},
browsers: ['ChromeHeadlessNoSandbox'],
// browsers: ['Chrome'],
// singleRun: true,
// colors: true,
// autoWatch: true,
});
};