UNPKG

1.34 kBJavaScriptView Raw
1module.exports = (enhancementsOnly, babelConfig) => {
2 const {extensions: full = []} = babelConfig || {};
3
4 // Combine all extensions possible for testing. Remove duplicate extensions.
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 // Decide if and where to add the default `js` extension. Keep in mind it's not
16 // added if extensions have been explicitly given.
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 // If Babel is not disabled, and has the default extensions (or, explicitly,
29 // no configured extensions), thes the `js` extension must have come from
30 // the `enhancementsOnly` value. That's not allowed since it'd be a
31 // roundabout way of disabling Babel.
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};