Skip to content

Commit d4b2151

Browse files
author
Federico Bertolini
committed
EnvironmentPlugin tests: refactored the regular expressions of the expected errors to allow adding more tests easily
1 parent b7d0155 commit d4b2151

1 file changed

Lines changed: 27 additions & 11 deletions

File tree

  • test/configCases/plugins/environment-plugin
Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,27 @@
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

Comments
 (0)