@@ -15,20 +15,41 @@ describe("init", () => {
15
15
let args = testObjects . initSampleArgs ;
16
16
var sandbox ;
17
17
18
- before ( ( ) => {
18
+ beforeEach ( ( ) => {
19
19
sandbox = sinon . createSandbox ( ) ;
20
20
sendUsageReportStub = sandbox . stub ( ) . callsFake ( function ( ) {
21
21
return "end" ;
22
22
} ) ;
23
23
} ) ;
24
24
25
- after ( ( ) => {
25
+ afterEach ( ( ) => {
26
26
sandbox . restore ( ) ;
27
27
sinon . restore ( ) ;
28
28
} ) ;
29
29
30
30
describe ( "init" , ( ) => {
31
+ it ( "fail if given path is not present" , ( ) => {
32
+ dirExistsStub = sandbox . stub ( ) . yields ( false ) ;
33
+ writeStub = sandbox . stub ( ) ;
34
+
35
+ const init = proxyquire ( "../../../../bin/commands/init" , {
36
+ "../helpers/utils" : {
37
+ sendUsageReport : sendUsageReportStub ,
38
+ } ,
39
+ "../helpers/fileHelpers" : {
40
+ dirExists : dirExistsStub ,
41
+ write : writeStub ,
42
+ } ,
43
+ } ) ;
44
+
45
+ init ( args ) ;
46
+ sinon . assert . calledOnce ( dirExistsStub ) ;
47
+ sinon . assert . notCalled ( writeStub ) ;
48
+ sinon . assert . calledOnceWithExactly ( sendUsageReportStub , null , args , Constants . userMessages . DIR_NOT_FOUND , Constants . messageTypes . ERROR , 'path_to_init_not_found' ) ;
49
+ } ) ;
50
+
31
51
it ( "fail if browserstack.json is already present" , ( ) => {
52
+ dirExistsStub = sandbox . stub ( ) . yields ( true ) ;
32
53
fileExistsStub = sandbox . stub ( ) . yields ( true ) ;
33
54
writeStub = sandbox . stub ( ) ;
34
55
@@ -37,18 +58,21 @@ describe("init", () => {
37
58
sendUsageReport : sendUsageReportStub ,
38
59
} ,
39
60
"../helpers/fileHelpers" : {
61
+ dirExists : dirExistsStub ,
40
62
fileExists : fileExistsStub ,
41
63
write : writeStub ,
42
64
} ,
43
65
} ) ;
44
66
45
67
init ( args ) ;
68
+ sinon . assert . calledOnce ( dirExistsStub ) ;
46
69
sinon . assert . calledOnce ( fileExistsStub ) ;
47
70
sinon . assert . notCalled ( writeStub ) ;
48
71
sinon . assert . calledOnceWithExactly ( sendUsageReportStub , null , args , Constants . userMessages . CONFIG_FILE_EXISTS , Constants . messageTypes . ERROR , 'bstack_json_already_exists' ) ;
49
72
} ) ;
50
73
51
74
it ( "create browserstack.json if not already present" , ( ) => {
75
+ dirExistsStub = sandbox . stub ( ) . yields ( true ) ;
52
76
fileExistsStub = sandbox . stub ( ) . yields ( false ) ;
53
77
writeStub = sandbox . stub ( ) ;
54
78
@@ -57,12 +81,14 @@ describe("init", () => {
57
81
sendUsageReport : sendUsageReportStub ,
58
82
} ,
59
83
"../helpers/fileHelpers" : {
84
+ dirExists : dirExistsStub ,
60
85
fileExists : fileExistsStub ,
61
86
write : writeStub ,
62
87
} ,
63
88
} ) ;
64
89
65
90
init ( args ) ;
91
+ sinon . assert . calledOnce ( dirExistsStub ) ;
66
92
sinon . assert . calledOnce ( fileExistsStub ) ;
67
93
sinon . assert . calledOnce ( writeStub ) ;
68
94
} ) ;
0 commit comments