1
1
const { onPreBuild} = require ( "./../index" ) ;
2
2
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
+ } ;
3
20
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
+
5
23
6
24
test ( "normal configuration" , ( ) => {
7
25
// Prepares data
@@ -22,7 +40,7 @@ test("normal configuration", () => {
22
40
) ) ;
23
41
} ) ;
24
42
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" , ( ) => {
26
44
// Prepares data
27
45
const [ prefix , def ] = [
28
46
"REACT_APP" ,
@@ -38,3 +56,20 @@ test("fails to use env with no def argument, should throw error", () => {
38
56
// Checks if the error is correct
39
57
expect ( t ) . toThrow ( ) ;
40
58
} ) ;
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