1- import 'babel-polyfill' ;
21import './other' ;
3- import 'mocha/mocha.css' ;
4- import mocha from 'exports-loader?mocha!mocha/mocha' ;
5- import chai , { expect } from 'chai' ;
6- import chaiAsPromised from 'chai-as-promised' ;
72import Worker from 'workerize-loader?ready&name=test!./worker' ;
83import InlineWorker from 'workerize-loader?ready&inline&name=test!./worker' ;
94
10- document . body . appendChild ( document . createElement ( 'div' ) ) . id = 'mocha' ;
11- mocha . setup ( 'bdd' ) ;
12- setTimeout ( mocha . run ) ;
13-
14- chai . use ( chaiAsPromised ) ;
15-
16- let worker = window . worker = new Worker ( ) ;
17- console . log ( worker ) ;
18-
195describe ( 'worker' , ( ) => {
6+ let worker ;
7+
208 it ( 'should be an instance of Worker' , ( ) => {
21- expect ( worker ) . to . be . an . instanceof ( window . Worker ) ;
9+ worker = new Worker ( ) ;
10+ expect ( worker ) . toEqual ( jasmine . any ( window . Worker ) ) ;
2211 } ) ;
23- it ( 'worker.foo()' , ( ) => {
24- expect ( worker . foo ( ) ) . to . eventually . equal ( 1 ) ;
12+
13+ it ( 'worker.foo()' , async ( ) => {
14+ expect ( await worker . foo ( ) ) . toBe ( 1 ) ;
2515 } ) ;
26- it ( 'worker.bar()' , ( ) => {
27- expect ( worker . bar ( 'a' , 'b' ) ) . to . eventually . equal ( 'a [bar:3] b' ) ;
16+
17+ it ( 'worker.bar()' , async ( ) => {
18+ let out = await worker . bar ( 'a' , 'b' ) ;
19+ expect ( out ) . toEqual ( 'a [bar:3] b' ) ;
2820 } ) ;
2921
3022 it ( 'should fire ready event' , done => {
@@ -34,7 +26,7 @@ describe('worker', () => {
3426 function fin ( ) {
3527 if ( isDone ) return ;
3628 isDone = true ;
37- expect ( called ) . to . equal ( true , 'fired "ready" event' ) ;
29+ expect ( called ) . toEqual ( true ) ;
3830 done ( ) ;
3931 }
4032 worker . addEventListener ( 'ready' , ( ) => {
@@ -54,20 +46,20 @@ describe('async/await demo', () => {
5446 await worker . ready ;
5547 elapsed = Date . now ( ) - start ;
5648 console . log ( `new Worker() [${ elapsed } ms]` ) ;
57- expect ( elapsed ) . to . be . lessThan ( 300 ) ;
49+ expect ( elapsed ) . toBeLessThan ( 300 ) ;
5850
5951 let one = await worker . foo ( ) ;
6052 elapsed = Date . now ( ) - start ;
6153 console . log ( `await worker.foo() [${ elapsed } ms]: ` , one ) ;
62- expect ( one ) . to . equal ( 1 ) ;
63- expect ( Date . now ( ) - start ) . to . be . lessThan ( 300 ) ; // @todo why the overhead here?
54+ expect ( one ) . toEqual ( 1 ) ;
55+ expect ( Date . now ( ) - start ) . toBeLessThan ( 300 ) ; // @todo why the overhead here?
6456
6557 start = Date . now ( ) ;
6658 let two = await worker . bar ( 1 , 2 ) ;
6759 elapsed = Date . now ( ) - start ;
6860 console . log ( `await worker.bar(1, 2) [${ elapsed } ms]: ` , two ) ;
69- expect ( two ) . to . equal ( '1 [bar:3] 2' ) ;
70- expect ( Date . now ( ) - start ) . to . be . lessThan ( 20 ) ;
61+ expect ( two ) . toEqual ( '1 [bar:3] 2' ) ;
62+ expect ( Date . now ( ) - start ) . toBeLessThan ( 20 ) ;
7163 } ) ;
7264
7365 it ( 'inline worker' , async ( ) => {
@@ -77,20 +69,20 @@ describe('async/await demo', () => {
7769 await worker . ready ;
7870 elapsed = Date . now ( ) - start ;
7971 console . log ( `new InlineWorker() [${ elapsed } ms]` ) ;
80- expect ( elapsed ) . to . be . lessThan ( 300 ) ;
72+ expect ( elapsed ) . toBeLessThan ( 300 ) ;
8173
8274 start = Date . now ( ) ;
8375 let one = await worker . foo ( ) ;
8476 elapsed = Date . now ( ) - start ;
8577 console . log ( `await worker.foo() [${ elapsed } ms]: ` , one ) ;
86- expect ( one ) . to . equal ( 1 ) ;
87- expect ( elapsed ) . to . be . lessThan ( 20 ) ;
78+ expect ( one ) . toEqual ( 1 ) ;
79+ expect ( elapsed ) . toBeLessThan ( 20 ) ;
8880
8981 start = Date . now ( ) ;
9082 let two = await worker . bar ( 1 , 2 ) ;
9183 elapsed = Date . now ( ) - start ;
9284 console . log ( `await worker.bar(1, 2) [${ elapsed } ms]: ` , two ) ;
93- expect ( two ) . to . equal ( '1 [bar:3] 2' ) ;
94- expect ( elapsed ) . to . be . lessThan ( 20 ) ;
85+ expect ( two ) . toEqual ( '1 [bar:3] 2' ) ;
86+ expect ( elapsed ) . toBeLessThan ( 20 ) ;
9587 } ) ;
9688} ) ;
0 commit comments