Skip to content

Commit 6dba91f

Browse files
author
Ben Lmsc
committed
test: add test and mocked methods through utils object
1 parent bfd305a commit 6dba91f

File tree

1 file changed

+37
-2
lines changed

1 file changed

+37
-2
lines changed

tests/index.test.js

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,25 @@
11
const {onPreBuild} = require("./../index");
22

3+
const utils = {
4+
run : {
5+
command() {},
6+
},
7+
build : {
8+
failBuild(message) {
9+
throw new Error(message);
10+
},
11+
},
12+
cache : {
13+
save() {},
14+
restore() {},
15+
},
16+
status: {
17+
show() {},
18+
},
19+
};
320
const addProcessEnv = (...envVars) => { envVars.forEach(envVar => process.env[envVar] = `Test for ${envVar}`); };
4-
const preCallback = (prefix, def) => onPreBuild({inputs: {prefix, def}});
21+
const preCallback = (prefix, def) => onPreBuild({inputs: {prefix, def}, utils});
22+
523

624
test("normal configuration", () => {
725
// Prepares data
@@ -22,7 +40,7 @@ test("normal configuration", () => {
2240
));
2341
});
2442

25-
test("fails to use env with no def argument, should throw error", () => {
43+
test("fails to use env with def no argument, should throw error", () => {
2644
// Prepares data
2745
const [prefix, def] = [
2846
"REACT_APP",
@@ -38,3 +56,20 @@ test("fails to use env with no def argument, should throw error", () => {
3856
// Checks if the error is correct
3957
expect(t).toThrow();
4058
});
59+
60+
test("fails to use env with bad def argument, should throw error", () => {
61+
// Prepares data
62+
const [prefix, def] = [
63+
"REACT_APP",
64+
["VAR_1", "VAR_2"],
65+
];
66+
67+
// adds the raw data to process env
68+
addProcessEnv(...def);
69+
70+
// Prepares onPreBuild callback w/o def argument
71+
const t = () => preCallback(prefix, 123);
72+
73+
// Checks if the error is correct
74+
expect(t).toThrow();
75+
});

0 commit comments

Comments
 (0)