-
Notifications
You must be signed in to change notification settings - Fork 483
Expand file tree
/
Copy pathkarma.conf.js
More file actions
210 lines (206 loc) · 6.44 KB
/
karma.conf.js
File metadata and controls
210 lines (206 loc) · 6.44 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
// @ts-check
const path = require('path');
const os = require('os');
process.env.CHROME_BIN = require('puppeteer').executablePath();
/**
*
* 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)
/** @param {import('karma').Config} config */
module.exports = function (config) {
config.set({
reporters: ['junit', 'coverage', 'spec'],
client: {
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,
// Uncomment this out to capture all logging
// browserConsoleLogOptions: {
// terminal: true,
// level: '',
// },
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: [
'packages/core/test/**/*_test.js',
'packages/tools/test/**/*_test.js',
// Serve dicomImageLoad test images
{
pattern: 'packages/dicomImageLoader/testImages/**/*',
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: {
// Simplified path to access test images in tests
'/testImages/': '/base/packages/dicomImageLoader/testImages/',
},
preprocessors: {
'packages/core/test/**/*_test.js': ['webpack'],
'packages/tools/test/**/*_test.js': ['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'),
},
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'),
},
},
},
webpackMiddleware: {
noInfo: false,
},
customLaunchers: {
ChromeHeadlessNoSandbox: {
base: 'ChromeHeadless',
flags: [
'--disable-translate',
'--disable-extensions',
'--no-sandbox',
'--ignore-gpu-blacklist',
'--remote-debugging-port=9229',
],
},
},
browsers: ['ChromeHeadlessNoSandbox'],
// browsers: ['Chrome'],
// singleRun: true,
// colors: true,
// autoWatch: true,
});
};