1 | module.exports = (enhancementsOnly, babelConfig) => {
|
2 | const {extensions: full = []} = babelConfig || {};
|
3 |
|
4 |
|
5 | const duplicates = [];
|
6 | const seen = new Set();
|
7 | for (const ext of [...enhancementsOnly, ...full]) {
|
8 | if (seen.has(ext)) {
|
9 | duplicates.push(ext);
|
10 | } else {
|
11 | seen.add(ext);
|
12 | }
|
13 | }
|
14 |
|
15 |
|
16 |
|
17 | if (!seen.has('js')) {
|
18 | if (babelConfig && full.length === 0) {
|
19 | seen.add('js');
|
20 | full.push('js');
|
21 | }
|
22 |
|
23 | if (!babelConfig && enhancementsOnly.length === 0) {
|
24 | seen.add('js');
|
25 | enhancementsOnly.push('js');
|
26 | }
|
27 | } else if (babelConfig && full.length === 0) {
|
28 |
|
29 |
|
30 |
|
31 |
|
32 | throw new Error('Cannot specify generic \'js\' extension without disabling AVA\'s Babel usage.');
|
33 | }
|
34 |
|
35 | if (duplicates.length > 0) {
|
36 | throw new Error(`Unexpected duplicate extensions in options: '${duplicates.join('\', \'')}'.`);
|
37 | }
|
38 |
|
39 | const all = [...seen];
|
40 | return {all, enhancementsOnly, full};
|
41 | };
|