@@ -12,13 +12,10 @@ describe("E2E TLS proxy test", function () {
1212
1313 this . timeout ( 15000 ) ;
1414
15- var bs , app ;
16-
17- before ( function ( done ) {
18-
15+ it ( "Set's a HTTPS url" , function ( done ) {
1916 browserSync . reset ( ) ;
2017
21- app = testUtils . getApp ( Immutable . Map ( { scheme : "https" } ) ) ;
18+ var app = testUtils . getApp ( Immutable . Map ( { scheme : "https" } ) ) ;
2219
2320 app . server . listen ( ) ;
2421
@@ -28,66 +25,83 @@ describe("E2E TLS proxy test", function () {
2825 logLevel : "silent"
2926 } ;
3027
31- bs = browserSync . init ( config , done ) . instance ;
32- } ) ;
28+ browserSync . init ( config , function ( err , bs ) {
29+ bs . cleanup ( ) ;
30+ app . server . close ( ) ;
3331
34- after ( function ( ) {
35- bs . cleanup ( ) ;
36- app . server . close ( ) ;
37- } ) ;
32+ var local = bs . options . getIn ( [ "urls" , "local" ] ) ;
33+ assert . equal ( "https://localhost:" + bs . options . get ( "port" ) , local ) ;
3834
39- it ( "Set's a HTTPS url" , function ( ) {
40- var local = bs . options . getIn ( [ "urls" , "local" ] ) ;
41- assert . equal ( "https://localhost:" + bs . options . get ( "port" ) , local ) ;
35+ done ( ) ;
36+ } ) ;
4237 } ) ;
4338
44- it ( "proxies over https and injects snippet" , function ( done ) {
39+ it ( "Set's a HTTPS url with none-https proxy target" , function ( done ) {
40+ browserSync . reset ( ) ;
4541
46- assert . isString ( bs . options . get ( "snippet" ) ) ;
42+ var app = testUtils . getApp ( Immutable . Map ( { scheme : "http" } ) ) ;
4743
48- var expected = app . html . replace ( "BS" , bs . options . get ( "snippet" ) + "BS" ) ;
44+ app . server . listen ( ) ;
4945
50- request ( bs . options . getIn ( [ "urls" , "local" ] ) )
51- . get ( "/index.html" )
52- . set ( "accept" , "text/html" )
53- . expect ( 200 , expected , done ) ;
54- } ) ;
55- } ) ;
46+ var config = {
47+ proxy : "http://localhost:" + app . server . address ( ) . port ,
48+ open : false ,
49+ logLevel : "silent" ,
50+ https : true
51+ } ;
5652
57- describe ( "E2E TLS proxy Options test" , function ( ) {
53+ browserSync . init ( config , function ( err , bs ) {
5854
59- this . timeout ( 15000 ) ;
55+ if ( err ) {
56+ throw err ;
57+ }
6058
61- var app ;
59+ var local = bs . options . getIn ( [ "urls" , "local" ] ) ;
60+ var expected = app . html . replace ( "BS" , bs . options . get ( "snippet" ) + "BS" ) ;
6261
63- before ( function ( ) {
62+ assert . equal ( "https://localhost:" + bs . options . get ( "port" ) , local ) ;
63+
64+ request ( bs . options . getIn ( [ "urls" , "local" ] ) )
65+ . get ( "/index.html" )
66+ . set ( "accept" , "text/html" )
67+ . expect ( 200 , function ( err , res ) {
68+ assert . equal ( res . text , expected ) ;
69+ bs . cleanup ( ) ;
70+ app . server . close ( ) ;
71+ done ( ) ;
72+ } ) ;
73+ } ) ;
74+ } ) ;
75+
76+ it ( "proxies over https and injects snippet" , function ( done ) {
6477
6578 browserSync . reset ( ) ;
6679
67- app = testUtils . getApp ( Immutable . Map ( { scheme : "https" } ) ) ;
80+ var app = testUtils . getApp ( Immutable . Map ( { scheme : "https" } ) ) ;
6881
6982 app . server . listen ( ) ;
70- } ) ;
71-
72- after ( function ( ) {
73- app . server . close ( ) ;
74- } ) ;
7583
76- it ( "Exits if https specified in options, but not in target" , function ( done ) {
77- var utils = require ( "../../../../lib/utils" ) ;
78- var errors = require ( "../../../../lib/config" ) . errors ;
79- var sinon = require ( "sinon" ) ;
8084 var config = {
81- proxy : "http://localhost:" + app . server . address ( ) . port ,
82- https : true ,
85+ proxy : "https://localhost:" + app . server . address ( ) . port ,
8386 open : false ,
8487 logLevel : "silent"
8588 } ;
86- var stub = sinon . stub ( utils , "fail" ) ;
87- browserSync . init ( config ) ;
88- sinon . assert . called ( stub ) ;
89- assert . include ( stub . getCall ( 0 ) . args [ 1 ] , errors [ "proxy+https" ] ) ;
90- utils . fail . restore ( ) ;
91- done ( ) ;
89+
90+ browserSync . init ( config , function ( err , bs ) {
91+
92+ assert . isString ( bs . options . get ( "snippet" ) ) ;
93+
94+ var expected = app . html . replace ( "BS" , bs . options . get ( "snippet" ) + "BS" ) ;
95+
96+ request ( bs . options . getIn ( [ "urls" , "local" ] ) )
97+ . get ( "/index.html" )
98+ . set ( "accept" , "text/html" )
99+ . expect ( 200 , expected , function ( ) {
100+ bs . cleanup ( ) ;
101+ app . server . close ( ) ;
102+ done ( ) ;
103+ } ) ;
104+ } ) ;
105+
92106 } ) ;
93107} ) ;
0 commit comments