1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 | 'use strict';
|
7 |
|
8 | const debug = require('debug')('loopback:build:merge-mocha-configs');
|
9 | const {assignWith} = require('lodash');
|
10 |
|
11 | module.exports = mergeMochaConfigs;
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 | function mergeMochaConfigs(...configs) {
|
20 | debug('Merging mocha configurations', ...configs);
|
21 | const result = assignWith({}, ...configs, assignMochaConfigEntry);
|
22 | debug('Merged config:', result);
|
23 | return result;
|
24 | }
|
25 |
|
26 | function assignMochaConfigEntry(targetValue, sourceValue, key) {
|
27 | switch (key) {
|
28 | case 'timeout':
|
29 | return Math.max(targetValue || 0, sourceValue);
|
30 | case 'require':
|
31 | if (Array.isArray(sourceValue)) {
|
32 | debug('Adding an array of files to require:', sourceValue);
|
33 | return [...(targetValue || []), ...sourceValue];
|
34 | } else {
|
35 | debug('Adding a single file to require:', sourceValue);
|
36 | return [...(targetValue || []), sourceValue];
|
37 | }
|
38 | }
|
39 | }
|