Skip to content

Commit 0787748

Browse files
author
Federico Bertolini
committed
EnvironmentPlugin: test constructor passing an array and an object with default values
1 parent d4b2151 commit 0787748

3 files changed

Lines changed: 45 additions & 5 deletions

File tree

test/configCases/plugins/environment-plugin/errors.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const variables = ['aaa', 'bbb', 'ccc', 'ddd'];
1+
const variables = ['aaa', 'bbb', 'ccc', 'ddd', 'eee', 'fff', 'ggg', 'hhh'];
22
const modules = [{
33
name: 'aaa',
44
variables: ['aaa']
@@ -8,6 +8,12 @@ const modules = [{
88
}, {
99
name: 'ddd',
1010
variables: []
11+
}, {
12+
name: 'eeefff',
13+
variables: ['eee', 'fff']
14+
}, {
15+
name: 'ggghhh',
16+
variables: ['ggg', 'hhh']
1117
}];
1218

1319
// build an array of regular expressions of expected errors
Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,30 @@
1-
it("should import a single process.env var", function() {
1+
it("should import a single process.env var", () => {
22
if(process.env.AAA !== "aaa")
33
require.include("aaa");
44
});
55

6-
it("should import multiple process.env vars", function() {
6+
it("should import multiple process.env vars", () => {
77
if(process.env.BBB !== "bbb")
88
require.include("bbb");
99
if(process.env.CCC !== "ccc")
1010
require.include("ccc");
1111
});
1212

13-
it("should warn when a process.env variable is undefined", function() {
13+
it("should warn when a process.env variable is undefined", () => {
1414
if(process.env.DDD !== "ddd")
1515
require.include("ddd");
1616
});
17+
18+
it("should import an array of process.env vars", () => {
19+
if(process.env.EEE !== "eee")
20+
require.include("eee");
21+
if(process.env.FFF !== "fff")
22+
require.include("fff");
23+
});
24+
25+
it("should import multiple process.env var with default values", () => {
26+
if(process.env.GGG !== "ggg")
27+
require.include("ggg");
28+
if(process.env.HHH !== "hhh")
29+
require.include("hhh");
30+
});

test/configCases/plugins/environment-plugin/webpack.config.js

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
1-
var EnvironmentPlugin = require("../../../../lib/EnvironmentPlugin");
1+
const EnvironmentPlugin = require("../../../../lib/EnvironmentPlugin");
2+
23
process.env.AAA = "aaa";
34
process.env.BBB = "bbb";
45
process.env.CCC = "ccc";
6+
process.env.EEE = "eee";
7+
process.env.FFF = "fff";
8+
process.env.GGG = "ggg";
9+
510
module.exports = [{
611
name: "aaa",
712
module: { unknownContextRegExp: /$^/, unknownContextCritical: false },
@@ -20,4 +25,19 @@ module.exports = [{
2025
plugins: [
2126
new EnvironmentPlugin("DDD")
2227
]
28+
}, {
29+
name: "eeefff",
30+
module: { unknownContextRegExp: /$^/, unknownContextCritical: false },
31+
plugins: [
32+
new EnvironmentPlugin(["EEE", "FFF"])
33+
]
34+
}, {
35+
name: "ggghhh",
36+
module: { unknownContextRegExp: /$^/, unknownContextCritical: false },
37+
plugins: [
38+
new EnvironmentPlugin({
39+
GGG: 'ggg-default',
40+
HHH: 'hhh'
41+
})
42+
]
2343
}];

0 commit comments

Comments
 (0)