1
1
'use strict' ;
2
2
3
- global . logLevel = " silent" ;
3
+ global . logLevel = ' silent' ;
4
4
5
- let assert = require ( 'assert' ) ,
5
+ var assert = require ( 'assert' ) ,
6
6
sinon = require ( 'sinon' ) ,
7
7
path = require ( 'path' ) ,
8
- browserstackRunner = require ( '../../bin/cli.js' ) ;
8
+ http = require ( 'http' ) ,
9
+ browserstackRunner = require ( '../../bin/cli.js' ) ,
10
+ Tunnel = require ( '../../lib/local.js' ) . Tunnel ;
9
11
10
- let getBaseConfig = function ( ) {
12
+ var getBaseConfig = function ( ) {
11
13
return {
12
14
username : 'BROWSERSTACK_USER' ,
13
15
key : 'BROWSERSTACK_KEY' ,
14
16
test_framework : 'qunit' ,
15
17
test_path : path . resolve ( __dirname , 'resources' , 'qunit_sample.html' ) ,
16
- build : " BrowserStack Runner Behaviour Tests" ,
18
+ build : ' BrowserStack Runner Behaviour Tests' ,
17
19
browsers : [ {
18
20
browser : 'firefox' ,
19
21
browser_version : '47.0' ,
@@ -38,26 +40,26 @@ describe('Config Assertions', function() {
38
40
} ) ;
39
41
} ) ;
40
42
it ( 'should have an error if test path is not valid' , function ( done ) {
41
- let config = getBaseConfig ( ) ;
42
- config . test_path = " Some invalid path" ;
43
+ var config = getBaseConfig ( ) ;
44
+ config . test_path = ' Some invalid path' ;
43
45
browserstackRunner . run ( config , function ( err ) {
44
- assert . equal ( err . message , " Test path: " + config . test_path + " is invalid." ) ;
46
+ assert . equal ( err . message , ' Test path: ' + config . test_path + ' is invalid.' ) ;
45
47
done ( ) ;
46
48
} ) ;
47
49
} ) ;
48
50
it ( 'should have an error if config does not have a browsers key' , function ( done ) {
49
- let config = getBaseConfig ( ) ;
51
+ var config = getBaseConfig ( ) ;
50
52
delete ( config . browsers ) ;
51
53
browserstackRunner . run ( config , function ( err ) {
52
- assert . equal ( err . message , " Configuration parameter browsers is required." ) ;
54
+ assert . equal ( err . message , ' Configuration parameter browsers is required.' ) ;
53
55
done ( ) ;
54
56
} ) ;
55
57
} ) ;
56
58
it ( 'should have an error if config does not have a test_path key' , function ( done ) {
57
- let config = getBaseConfig ( ) ;
59
+ var config = getBaseConfig ( ) ;
58
60
delete ( config . test_path ) ;
59
61
browserstackRunner . run ( config , function ( err ) {
60
- assert . equal ( err . message , " Configuration parameter test_path is required." ) ;
62
+ assert . equal ( err . message , ' Configuration parameter test_path is required.' ) ;
61
63
done ( ) ;
62
64
} ) ;
63
65
} ) ;
@@ -70,18 +72,18 @@ describe('Config Assertions', function() {
70
72
} ) ;
71
73
72
74
it ( 'should have an error if config does not have a username' , function ( done ) {
73
- let config = getBaseConfig ( ) ;
75
+ var config = getBaseConfig ( ) ;
74
76
delete ( config . username ) ;
75
77
browserstackRunner . run ( config , function ( err ) {
76
- assert . equal ( err . message , " Configuration parameter username is required." ) ;
78
+ assert . equal ( err . message , ' Configuration parameter username is required.' ) ;
77
79
done ( ) ;
78
80
} ) ;
79
81
} ) ;
80
82
it ( 'should have an error if config does not have a key' , function ( done ) {
81
- let config = getBaseConfig ( ) ;
83
+ var config = getBaseConfig ( ) ;
82
84
delete ( config . key ) ;
83
85
browserstackRunner . run ( config , function ( err ) {
84
- assert . equal ( err . message , " Configuration parameter key is required." ) ;
86
+ assert . equal ( err . message , ' Configuration parameter key is required.' ) ;
85
87
done ( ) ;
86
88
} ) ;
87
89
} ) ;
@@ -96,47 +98,43 @@ describe('Pass/Fail reporting', function() {
96
98
this . timeout ( 0 ) ;
97
99
98
100
it ( 'report keys should have browser names' , function ( done ) {
99
- let config = getBaseConfig ( ) ;
101
+ var config = getBaseConfig ( ) ;
100
102
browserstackRunner . run ( config , function ( err , report ) {
101
103
assert . equal ( err , null ) ;
102
- var parsedReport = JSON . parse ( report ) ;
103
- assert . notEqual ( parsedReport [ "Windows 7, Chrome 52.0" ] , null ) ;
104
- assert . notEqual ( parsedReport [ "Windows 7, Firefox 47.0" ] , null ) ;
104
+ assert . notEqual ( report [ 'Windows 7, Chrome 52.0' ] , null ) ;
105
+ assert . notEqual ( report [ 'Windows 7, Firefox 47.0' ] , null ) ;
105
106
done ( ) ;
106
107
} ) ;
107
108
} ) ;
108
109
it ( 'report keys should have assertions and tests' , function ( done ) {
109
- let config = getBaseConfig ( ) ;
110
+ var config = getBaseConfig ( ) ;
110
111
browserstackRunner . run ( config , function ( err , report ) {
111
112
assert . equal ( err , null ) ;
112
- var parsedReport = JSON . parse ( report ) ;
113
- assert . notEqual ( parsedReport [ "Windows 7, Chrome 52.0" ] . assertions , null ) ;
114
- assert . notEqual ( parsedReport [ "Windows 7, Chrome 52.0" ] . tests , null ) ;
115
- assert . notEqual ( parsedReport [ "Windows 7, Firefox 47.0" ] . assertions , null ) ;
116
- assert . notEqual ( parsedReport [ "Windows 7, Firefox 47.0" ] . tests , null ) ;
113
+ assert . notEqual ( report [ 'Windows 7, Chrome 52.0' ] . assertions , null ) ;
114
+ assert . notEqual ( report [ 'Windows 7, Chrome 52.0' ] . tests , null ) ;
115
+ assert . notEqual ( report [ 'Windows 7, Firefox 47.0' ] . assertions , null ) ;
116
+ assert . notEqual ( report [ 'Windows 7, Firefox 47.0' ] . tests , null ) ;
117
117
done ( ) ;
118
118
} ) ;
119
119
} ) ;
120
120
describe ( 'Test Assertions' , function ( ) {
121
121
it ( 'report should have proper number of assertions for tests' , function ( done ) {
122
- let config = getBaseConfig ( ) ;
122
+ var config = getBaseConfig ( ) ;
123
123
browserstackRunner . run ( config , function ( err , report ) {
124
124
assert . equal ( err , null ) ;
125
- var parsedReport = JSON . parse ( report ) ;
126
125
// Only failed assertions are emitted
127
- assert . equal ( parsedReport [ " Windows 7, Chrome 52.0" ] . assertions . length , 8 ) ;
128
- assert . equal ( parsedReport [ " Windows 7, Firefox 47.0" ] . assertions . length , 8 ) ;
126
+ assert . equal ( report [ ' Windows 7, Chrome 52.0' ] . assertions . length , 8 ) ;
127
+ assert . equal ( report [ ' Windows 7, Firefox 47.0' ] . assertions . length , 8 ) ;
129
128
done ( ) ;
130
129
} ) ;
131
130
} ) ;
132
131
it ( 'report should have specific keys' , function ( done ) {
133
- let config = getBaseConfig ( ) ;
132
+ var config = getBaseConfig ( ) ;
134
133
browserstackRunner . run ( config , function ( err , report ) {
135
134
assert . equal ( err , null ) ;
136
- var parsedReport = JSON . parse ( report ) ;
137
- Object . keys ( parsedReport ) . forEach ( function ( reportKey ) {
138
- parsedReport [ reportKey ] . assertions . forEach ( function ( assertion ) {
139
- [ "actual" , "expected" , "message" , "source" ] . forEach ( function ( key ) {
135
+ Object . keys ( report ) . forEach ( function ( reportKey ) {
136
+ report [ reportKey ] . assertions . forEach ( function ( assertion ) {
137
+ [ 'actual' , 'expected' , 'message' , 'source' ] . forEach ( function ( key ) {
140
138
assert . notEqual ( assertion [ key ] , null ) ;
141
139
} ) ;
142
140
} ) ;
@@ -145,13 +143,12 @@ describe('Pass/Fail reporting', function() {
145
143
} ) ;
146
144
} ) ;
147
145
it ( 'report should have message in assertions' , function ( done ) {
148
- let config = getBaseConfig ( ) ;
146
+ var config = getBaseConfig ( ) ;
149
147
browserstackRunner . run ( config , function ( err , report ) {
150
148
assert . equal ( err , null ) ;
151
- var parsedReport = JSON . parse ( report ) ;
152
- Object . keys ( parsedReport ) . forEach ( function ( reportKey ) {
153
- parsedReport [ reportKey ] . assertions . forEach ( function ( assertion ) {
154
- assert . notEqual ( assertion [ "message" ] . match ( / \d + i s .* a n .* n u m b e r / ) , null ) ;
149
+ Object . keys ( report ) . forEach ( function ( reportKey ) {
150
+ report [ reportKey ] . assertions . forEach ( function ( assertion ) {
151
+ assert . notEqual ( assertion [ 'message' ] . match ( / \d + i s .* a n .* n u m b e r / ) , null ) ;
155
152
} ) ;
156
153
} ) ;
157
154
done ( ) ;
@@ -160,23 +157,21 @@ describe('Pass/Fail reporting', function() {
160
157
} ) ;
161
158
describe ( 'Test tests' , function ( ) {
162
159
it ( 'report should have proper number of tests' , function ( done ) {
163
- let config = getBaseConfig ( ) ;
160
+ var config = getBaseConfig ( ) ;
164
161
browserstackRunner . run ( config , function ( err , report ) {
165
162
assert . equal ( err , null ) ;
166
- var parsedReport = JSON . parse ( report ) ;
167
- assert . equal ( parsedReport [ "Windows 7, Chrome 52.0" ] . tests . length , 1 ) ;
168
- assert . equal ( parsedReport [ "Windows 7, Firefox 47.0" ] . tests . length , 1 ) ;
163
+ assert . equal ( report [ 'Windows 7, Chrome 52.0' ] . tests . length , 1 ) ;
164
+ assert . equal ( report [ 'Windows 7, Firefox 47.0' ] . tests . length , 1 ) ;
169
165
done ( ) ;
170
166
} ) ;
171
167
} ) ;
172
168
it ( 'report should have specific keys' , function ( done ) {
173
- let config = getBaseConfig ( ) ;
169
+ var config = getBaseConfig ( ) ;
174
170
browserstackRunner . run ( config , function ( err , report ) {
175
171
assert . equal ( err , null ) ;
176
- var parsedReport = JSON . parse ( report ) ;
177
- Object . keys ( parsedReport ) . forEach ( function ( reportKey ) {
178
- parsedReport [ reportKey ] . tests . forEach ( function ( test ) {
179
- [ "runtime" , "total" , "passed" , "failed" , "url" ] . forEach ( function ( key ) {
172
+ Object . keys ( report ) . forEach ( function ( reportKey ) {
173
+ report [ reportKey ] . tests . forEach ( function ( test ) {
174
+ [ 'runtime' , 'total' , 'passed' , 'failed' , 'url' ] . forEach ( function ( key ) {
180
175
assert . notEqual ( test [ key ] , null ) ;
181
176
} ) ;
182
177
} ) ;
@@ -185,15 +180,14 @@ describe('Pass/Fail reporting', function() {
185
180
} ) ;
186
181
} ) ;
187
182
it ( 'report should have message in assertions' , function ( done ) {
188
- let config = getBaseConfig ( ) ;
183
+ var config = getBaseConfig ( ) ;
189
184
browserstackRunner . run ( config , function ( err , report ) {
190
185
assert . equal ( err , null ) ;
191
- var parsedReport = JSON . parse ( report ) ;
192
- Object . keys ( parsedReport ) . forEach ( function ( reportKey ) {
193
- parsedReport [ reportKey ] . tests . forEach ( function ( test ) {
194
- assert . equal ( test [ "total" ] , 3 ) ;
195
- assert . equal ( test [ "passed" ] , 1 ) ;
196
- assert . equal ( test [ "failed" ] , 2 ) ;
186
+ Object . keys ( report ) . forEach ( function ( reportKey ) {
187
+ report [ reportKey ] . tests . forEach ( function ( test ) {
188
+ assert . equal ( test [ 'total' ] , 3 ) ;
189
+ assert . equal ( test [ 'passed' ] , 1 ) ;
190
+ assert . equal ( test [ 'failed' ] , 2 ) ;
197
191
} ) ;
198
192
} ) ;
199
193
done ( ) ;
0 commit comments