@@ -5,32 +5,35 @@ var assert = require("chai").assert;
55var File = require ( "vinyl" ) ;
66
77describe ( "API: .stream()" , function ( ) {
8- var emitterStub , clock , bs ;
8+ var emitterStub , bs , scheduler ;
99
1010 before ( function ( done ) {
1111 browserSync . reset ( ) ;
12- bs = browserSync ( { logLevel : "silent" } , function ( ) {
13- emitterStub = sinon . spy ( bs . emitter , "emit" ) ;
14- done ( ) ;
15- } ) ;
16- clock = sinon . useFakeTimers ( ) ;
12+ scheduler = require ( "../../utils" ) . getScheduler ( ) ;
13+ bs = browserSync (
14+ { logLevel : "silent" , debug : { scheduler : scheduler } } ,
15+ function ( ) {
16+ emitterStub = sinon . spy ( bs . emitter , "emit" ) ;
17+ done ( ) ;
18+ }
19+ ) ;
1720 } ) ;
1821
1922 afterEach ( function ( ) {
2023 emitterStub . reset ( ) ;
21- clock . now = 0 ;
24+ scheduler . clock = 0 ;
2225 } ) ;
2326
2427 after ( function ( ) {
2528 bs . cleanup ( ) ;
26- clock . restore ( ) ;
2729 emitterStub . restore ( ) ;
2830 } ) ;
2931
3032 it ( "should handle a single file changed" , function ( ) {
3133 var stream = browserSync . stream ( ) ;
3234 stream . write ( new File ( { path : "styles.css" } ) ) ;
3335 stream . end ( ) ;
36+ scheduler . advanceTo ( 600 ) ;
3437 sinon . assert . calledWithExactly ( emitterStub , "file:changed" , {
3538 path : "styles.css" ,
3639 basename : "styles.css" ,
@@ -45,6 +48,7 @@ describe("API: .stream()", function() {
4548 stream . write ( new File ( { path : "styles.css" } ) ) ;
4649 stream . write ( new File ( { path : "styles2.css" } ) ) ;
4750 stream . end ( ) ;
51+ scheduler . advanceTo ( 600 ) ;
4852 sinon . assert . calledWithExactly ( emitterStub , "file:changed" , {
4953 path : "styles.css" ,
5054 basename : "styles.css" ,
@@ -70,6 +74,7 @@ describe("API: .stream()", function() {
7074 stream . write ( new File ( { path : "styles.css" } ) ) ;
7175 stream . write ( new File ( { path : "styles2.css" } ) ) ;
7276 stream . write ( new File ( { path : "styles3.css" } ) ) ;
77+ scheduler . advanceTo ( 600 ) ;
7378 stream . end ( ) ;
7479 sinon . assert . calledWithExactly ( emitterStub , "_browser:reload" ) ;
7580 sinon . assert . calledWithExactly ( emitterStub , "browser:reload" ) ;
@@ -80,6 +85,7 @@ describe("API: .stream()", function() {
8085 stream . write ( new File ( { path : "styles2.js" } ) ) ;
8186 stream . write ( new File ( { path : "styles3.js" } ) ) ;
8287 stream . end ( ) ;
88+ scheduler . advanceTo ( 600 ) ;
8389 sinon . assert . calledWithExactly ( emitterStub , "_browser:reload" ) ;
8490 sinon . assert . calledWithExactly ( emitterStub , "browser:reload" ) ;
8591 } ) ;
@@ -88,14 +94,15 @@ describe("API: .stream()", function() {
8894 stream . write ( new File ( { path : "/users/shane/styles.js" } ) ) ;
8995 stream . write ( new File ( { path : "core.css" } ) ) ;
9096 stream . end ( ) ;
97+ scheduler . advanceTo ( 8000 ) ;
9198 sinon . assert . calledThrice ( emitterStub ) ;
9299 sinon . assert . calledWithExactly ( emitterStub , "file:changed" , {
93100 event : "change" ,
94101 log : false ,
95102 namespace : "core" ,
96103 path : "/users/shane/styles.js"
97104 } ) ;
98- sinon . assert . calledWithExactly ( emitterStub , "browser:reload" ) ;
105+ sinon . assert . calledWith ( emitterStub , "browser:reload" ) ;
99106 sinon . assert . calledWithExactly ( emitterStub , "stream:changed" , {
100107 changed : [ "styles.js" ]
101108 } ) ;
@@ -106,7 +113,7 @@ describe("API: .stream()", function() {
106113 stream . write ( new File ( { path : "core.css" } ) ) ;
107114 stream . write ( new File ( { path : "index.html" } ) ) ;
108115 stream . end ( ) ;
109- clock . tick ( ) ;
116+ scheduler . advanceTo ( 600 ) ;
110117 sinon . assert . notCalled ( emitterStub ) ;
111118 } ) ;
112119 it ( "accepts file paths beginning with dots" , function ( ) {
@@ -116,7 +123,7 @@ describe("API: .stream()", function() {
116123 new File ( { path : "/users/shakyshane/.tmp/css/core.css.map" } )
117124 ) ;
118125 stream . end ( ) ;
119- clock . tick ( ) ;
126+ scheduler . advanceTo ( 600 ) ;
120127 sinon . assert . calledWithExactly ( emitterStub , "file:changed" , {
121128 path : "/users/shakyshane/.tmp/css/core.css" ,
122129 basename : "core.css" ,
@@ -145,18 +152,17 @@ describe("API: .stream()", function() {
145152 stream . write ( new File ( { path : "index.html" } ) ) ;
146153
147154 stream . end ( ) ;
148- clock . tick ( ) ;
155+ scheduler . advanceTo ( 1000 ) ;
149156
150- assert . isFalse ( emitterStub . getCall ( 0 ) . args [ 1 ] . log ) ;
151-
152- assert . equal ( emitterStub . getCall ( 1 ) . args [ 0 ] , "browser:reload" ) ;
153-
154- assert . isFalse ( emitterStub . getCall ( 2 ) . args [ 1 ] . log ) ;
157+ assert . equal ( emitterStub . getCall ( 0 ) . args [ 0 ] , "file:changed" ) ;
158+ assert . equal ( emitterStub . getCall ( 1 ) . args [ 0 ] , "file:changed" ) ;
155159 assert . equal ( emitterStub . getCall ( 2 ) . args [ 0 ] , "file:changed" ) ;
156- assert . equal ( emitterStub . getCall ( 3 ) . args [ 0 ] , "file:reload" ) ;
157- assert . equal ( emitterStub . getCall ( 3 ) . args [ 1 ] . path , "core.css" ) ;
158160
159- assert . equal ( emitterStub . getCall ( 4 ) . args [ 0 ] , "file:changed" ) ;
160- assert . equal ( emitterStub . getCall ( 5 ) . args , "browser:reload" ) ;
161+ assert . deepEqual ( emitterStub . getCall ( 3 ) . args , [
162+ "stream:changed" ,
163+ { changed : [ "styles.js" , "core.css" , "index.html" ] }
164+ ] ) ;
165+
166+ assert . equal ( emitterStub . getCall ( 4 ) . args [ 0 ] , "browser:reload" ) ;
161167 } ) ;
162168} ) ;
0 commit comments