1
1
const chai = require ( "chai" ) ,
2
+ assert = chai . assert ,
3
+ expect = chai . expect ,
2
4
sinon = require ( "sinon" ) ,
3
5
chaiAsPromised = require ( "chai-as-promised" ) ,
6
+ rewire = require ( "rewire" ) ,
4
7
util = require ( "util" ) ;
5
8
6
9
const Constants = require ( "../../../../bin/helpers/constants" ) ,
7
10
logger = require ( "../../../../bin/helpers/logger" ) . winstonLogger ,
8
- testObjects = require ( "../../support/fixtures/testObjects" ) ;
11
+ testObjects = require ( "../../support/fixtures/testObjects" )
12
+ utils = require ( "../../../../bin/helpers/utils" ) ;
9
13
10
14
const proxyquire = require ( "proxyquire" ) . noCallThru ( ) ;
11
15
16
+ const get_path = rewire ( "../../../../bin/commands/init" ) . __get__ ( "get_path" ) ; ;
17
+
12
18
chai . use ( chaiAsPromised ) ;
13
19
logger . transports [ "console.info" ] . silent = true ;
14
20
@@ -29,6 +35,71 @@ describe("init", () => {
29
35
sinon . restore ( ) ;
30
36
} ) ;
31
37
38
+ describe ( "get_path" , ( ) => {
39
+ it ( "filename passed, -path passed" , ( ) => {
40
+ let args = {
41
+ _ : [ "init" , "filename.json" ] ,
42
+ p : '/sample-path' ,
43
+ path : '/sample-path' ,
44
+ $0 : "browserstack-cypress" ,
45
+ } ;
46
+
47
+ assert ( get_path ( args ) , '/sample-path/filename.json' ) ;
48
+ } ) ;
49
+
50
+ it ( "filename passed, -path not passed" , ( ) => {
51
+ let args = {
52
+ _ : [ "init" , "filename.json" ] ,
53
+ p : false ,
54
+ path : false ,
55
+ $0 : "browserstack-cypress" ,
56
+ } ;
57
+
58
+ assert ( get_path ( args ) , 'filename.json' ) ;
59
+ } ) ;
60
+
61
+ it ( "filepath passed, -path passed" , ( ) => {
62
+ let args = {
63
+ _ : [ "init" , "/sample-path/filename.json" ] ,
64
+ p : '/sample-path2' ,
65
+ path : '/sample-path2' ,
66
+ "disable-usage-reporting" : undefined ,
67
+ disableUsageReporting : undefined ,
68
+ $0 : "browserstack-cypress" ,
69
+ } ;
70
+
71
+ loggerStub = sandbox . stub ( logger , 'error' ) ;
72
+ usageStub = sandbox . stub ( utils , 'sendUsageReport' ) ;
73
+
74
+ expect ( get_path ( args ) ) . to . be . undefined ;
75
+ sinon . assert . calledOnce ( loggerStub ) ;
76
+ sinon . assert . calledOnce ( usageStub ) ;
77
+ } ) ;
78
+
79
+ it ( "filename not passed, -path passed" , ( ) => {
80
+ let args = {
81
+ _ : [ "init" ] ,
82
+ p : '/sample-path' ,
83
+ path : '/sample-path' ,
84
+ $0 : "browserstack-cypress" ,
85
+ } ;
86
+
87
+ assert ( get_path ( args ) , '/sample-path/browserstack.json' ) ;
88
+ } ) ;
89
+
90
+ it ( "filename not passed, -path not passed" , ( ) => {
91
+ let args = {
92
+ _ : [ "init" ] ,
93
+ p : false ,
94
+ path : false ,
95
+ $0 : "browserstack-cypress" ,
96
+ } ;
97
+
98
+ assert ( get_path ( args ) , 'browserstack.json' ) ;
99
+ } ) ;
100
+ } ) ;
101
+
102
+
32
103
describe ( "init" , ( ) => {
33
104
it ( "fail if given path is not present" , ( ) => {
34
105
dirExistsStub = sandbox . stub ( ) . yields ( false ) ;
0 commit comments