|
1 | | -module.exports = [ |
2 | | - [/(aaa)/, /resolve 'bbb'/], |
3 | | - [/(aaa)/, /resolve 'ccc'/], |
4 | | - [/(aaa)/, /resolve 'ddd'/], |
5 | | - [/(bbbccc)/, /resolve 'aaa'/], |
6 | | - [/(bbbccc)/, /resolve 'ddd'/], |
7 | | - [/(ddd)/, /resolve 'aaa'/], |
8 | | - [/(ddd)/, /resolve 'bbb'/], |
9 | | - [/(ddd)/, /resolve 'ccc'/], |
10 | | - [/(ddd)/, /resolve 'ddd'/], |
11 | | -]; |
| 1 | +const variables = ['aaa', 'bbb', 'ccc', 'ddd']; |
| 2 | +const modules = [{ |
| 3 | + name: 'aaa', |
| 4 | + variables: ['aaa'] |
| 5 | +}, { |
| 6 | + name: 'bbbccc', |
| 7 | + variables: ['bbb', 'ccc'] |
| 8 | +}, { |
| 9 | + name: 'ddd', |
| 10 | + variables: [] |
| 11 | +}]; |
| 12 | + |
| 13 | +// build an array of regular expressions of expected errors |
| 14 | +const regex = []; |
| 15 | +modules.forEach(module => { |
| 16 | + variables.forEach(variable => { |
| 17 | + if (module.variables.indexOf(variable) === -1) { |
| 18 | + // the module doesn't include the env variable, an error is expected when requiring the variable |
| 19 | + regex.push([ |
| 20 | + new RegExp(`(${module.name})`), |
| 21 | + new RegExp(`Can't resolve '${variable}'`), |
| 22 | + ]); |
| 23 | + } |
| 24 | + }); |
| 25 | +}); |
| 26 | + |
| 27 | +module.exports = regex; |
0 commit comments