forked from digitalbazaar/jsonld.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
karma.conf.js
233 lines (212 loc) · 6.6 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
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
/**
* Karam configuration for jsonld.js.
*
* Set dirs, manifests, or js to run:
* JSONLD_TESTS="f1 f2 ..."
* Output an EARL report:
* EARL=filename
* Bail with tests fail:
* BAIL=true
*
* @author Dave Longley
* @author David I. Lehn
*
* Copyright (c) 2011-2017 Digital Bazaar, Inc. All rights reserved.
*/
const os = require('os');
const webpack = require('webpack');
module.exports = function(config) {
// bundler to test: webpack, browserify
const bundler = process.env.BUNDLER || 'webpack';
const frameworks = ['mocha', 'server-side'];
// main bundle preprocessors
const preprocessors = ['babel'];
if(bundler === 'browserify') {
frameworks.push(bundler);
preprocessors.push(bundler);
} else if(bundler === 'webpack') {
preprocessors.push(bundler);
preprocessors.push('sourcemap');
} else {
throw Error('Unknown bundler');
}
config.set({
// base path that will be used to resolve all patterns (eg. files, exclude)
basePath: '',
// frameworks to use
// available frameworks: https://npmjs.org/browse/keyword/karma-adapter
frameworks,
// list of files / patterns to load in the browser
files: [
{
pattern: 'tests/test-karma.js',
watched: false, served: true, included: true
}
],
// list of files to exclude
exclude: [],
// preprocess matching files before serving them to the browser
// available preprocessors:
// https://npmjs.org/browse/keyword/karma-preprocessor
preprocessors: {
//'tests/*.js': ['webpack', 'babel'] //preprocessors
'tests/*.js': preprocessors
},
webpack: {
mode: 'development',
devtool: 'inline-source-map',
plugins: [
new webpack.DefinePlugin({
'process.env.BAIL': JSON.stringify(process.env.BAIL),
'process.env.EARL': JSON.stringify(process.env.EARL),
'process.env.TEST_ENV': JSON.stringify(process.env.TEST_ENV),
'process.env.JSONLD_BENCHMARK':
JSON.stringify(process.env.JSONLD_BENCHMARK),
'process.env.JSONLD_TESTS': JSON.stringify(process.env.JSONLD_TESTS),
'process.env.TEST_ROOT_DIR': JSON.stringify(__dirname),
'process.env.VERBOSE_SKIP': JSON.stringify(process.env.VERBOSE_SKIP),
// for 'auto' test env
'process.env._TEST_ENV_ARCH': JSON.stringify(process.arch),
'process.env._TEST_ENV_CPU': JSON.stringify(os.cpus()[0].model),
'process.env._TEST_ENV_CPU_COUNT': JSON.stringify(os.cpus().length),
'process.env._TEST_ENV_PLATFORM': JSON.stringify(process.platform),
'process.env._TEST_VERSION':
JSON.stringify(require('./package.json').version)
})
],
module: {
rules: [
{
test: /\.js$/,
include: [{
// exclude node_modules by default
exclude: /(node_modules)/
}, {
// include specific packages
include: [
/(node_modules\/canonicalize)/,
/(node_modules\/lru-cache)/,
/(node_modules\/rdf-canonize)/,
/(node_modules\/yallist)/
]
}],
use: {
loader: 'babel-loader',
options: {
presets: [
[
'@babel/preset-env',
{
useBuiltIns: 'usage',
corejs: '3.9',
bugfixes: true,
//debug: true,
targets: {
// test with slightly looser browserslist defaults
browsers: 'defaults, > 0.25%'
}
}
]
],
plugins: [
[
'@babel/plugin-proposal-object-rest-spread',
{useBuiltIns: true}
],
'@babel/plugin-transform-modules-commonjs',
'@babel/plugin-transform-runtime'
]
}
}
}
],
noParse: [
// avoid munging internal benchmark script magic
/benchmark/
]
},
node: {
Buffer: false,
process: false,
crypto: false,
setImmediate: false
}
},
browserify: {
debug: false,
transform: [
//'uglifyify',
[
'envify', {
BAIL: process.env.BAIL,
EARL: process.env.EARL,
TEST_ENV: process.env.TEST_ENV,
JSONLD_BENCHMARK: process.env.JSONLD_BENCHMARK,
JSONLD_TESTS: process.env.JSONLD_TESTS,
TEST_ROOT_DIR: __dirname,
VERBOSE_SKIP: process.env.VERBOSE_SKIP,
// for 'auto' test env
_TEST_ENV_ARCH: process.arch,
_TEST_ENV_CPU: os.cpus()[0].model,
_TEST_ENV_CPU_COUNT: os.cpus().length,
_TEST_ENV_PLATFORM: process.platform,
_TEST_VERSION: require('./package.json').version
}
]
],
plugin: [
[
require('esmify')
]
]
},
// test results reporter to use
// possible values: 'dots', 'progress'
// available reporters: https://npmjs.org/browse/keyword/karma-reporter
//reporters: ['progress'],
reporters: ['mocha'],
// web server port
port: 9876,
// enable / disable colors in the output (reporters and logs)
colors: true,
// level of logging
// possible values: config.LOG_DISABLE || config.LOG_ERROR ||
// config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
logLevel: config.LOG_INFO,
// enable / disable watching file and executing tests whenever any file
// changes
autoWatch: false,
// start these browsers
// available browser launchers:
// https://npmjs.org/browse/keyword/karma-launcher
//browsers: ['ChromeHeadless', 'Chrome', 'Firefox', 'Safari'],
browsers: ['ChromeHeadless'],
customLaunchers: {
IE9: {
base: 'IE',
'x-ua-compatible': 'IE=EmulateIE9'
},
IE8: {
base: 'IE',
'x-ua-compatible': 'IE=EmulateIE8'
}
},
// 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,
// Mocha
client: {
mocha: {
// increase from default 2s
timeout: 10000,
reporter: 'html',
delay: true
}
},
// Proxied paths
proxies: {}
});
};