-
Notifications
You must be signed in to change notification settings - Fork 27
/
karma.config.js
95 lines (83 loc) · 2.77 KB
/
karma.config.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
/* eslint-disable import/no-extraneous-dependencies */
'use strict';
const globby = require('globby');
const istanbul = require('rollup-plugin-istanbul');
const { nodeResolve } = require('@rollup/plugin-node-resolve');
const path = require('node:path');
process.env.CHROME_BIN = require('puppeteer').executablePath();
let testFilesPattern = './test/**/*.spec.js';
const basePath = path.resolve(__dirname, './');
const matchArg = process.argv.indexOf('--match');
if (matchArg > -1) {
testFilesPattern = process.argv[matchArg + 1] || '';
}
if (globby.sync(testFilesPattern).length) {
// eslint-disable-next-line no-console
console.log(`\nTesting files matching "${testFilesPattern}"\n`);
} else {
// eslint-disable-next-line no-console
console.error(`\nNo test files matching "${testFilesPattern}"\n`);
process.exit(0);
}
const coverage = process.argv.includes('--coverage');
const customLaunchers = {
ChromeHeadlessNoSandbox: {
base: 'ChromeHeadless',
flags: ['--disable-gpu', '--no-sandbox'],
},
};
module.exports = function (config) {
const bootstrapFilesPattern = 'test/__bootstrap__/**/*.js';
const karmaConfig = {
basePath,
browsers: Object.keys(customLaunchers),
browserConsoleLogOptions: { level: config.LOG_ERROR, format: '%m', terminal: true },
browserDisconnectTimeout: 10000,
browserDisconnectTolerance: 3,
browserNoActivityTimeout: 100000,
client: {
captureConsole: false,
},
concurrency: 1,
customLaunchers,
files: [
bootstrapFilesPattern,
{ pattern: testFilesPattern, watched: true, type: 'module' },
],
frameworks: ['jasmine'],
logLevel: config.LOG_ERROR,
preprocessors: {
[bootstrapFilesPattern]: ['rollup'],
[testFilesPattern]: ['rollup'],
},
reporters: ['progress'],
rollupPreprocessor: {
/**
* This is just a normal Rollup config object,
* except that `input` is handled for you.
*/
output: {
format: 'es',
sourcemap: 'inline',
},
plugins: [
nodeResolve({
preferBuiltins: true,
}),
],
},
};
if (coverage) {
karmaConfig.reporters.push('coverage');
karmaConfig.rollupPreprocessor.plugins.push(
istanbul({
exclude: ['packages/near-membrane-node', 'test/**/*.spec.js'],
})
);
karmaConfig.coverageReporter = {
dir: 'karma-coverage/',
reporters: [{ type: 'json', subdir: 'json', file: 'coverage-final.json' }],
};
}
config.set(karmaConfig);
};