1 |
|
2 |
|
3 |
|
4 | var P = require( "l8/lib/whisper" ).parole;
|
5 |
|
6 | console.log( "Starting Parole test" );
|
7 |
|
8 | var p = P().will( function(){
|
9 | console.log( "start" );
|
10 | setTimeout( this, 1000 );
|
11 | }).will( function(){
|
12 | console.log( "first next " );
|
13 | setTimeout( this, 1000 );
|
14 | }).will( function(){
|
15 | console.log( "second next " );
|
16 | this( 0, "hello ", "world!" );
|
17 | }).will( function( err, hello, world ){
|
18 | console.log( "third next: ", err, hello, world );
|
19 | setTimeout( this, 1000 );
|
20 | }).will( function(){
|
21 | console.log( "4th next" );
|
22 | this.exit();
|
23 | }).will( function skipped_step(){
|
24 | console.log( "!!! skipped step !!!" );
|
25 | throw "Parole error";
|
26 | }).then( function done(){
|
27 | console.log( "done" );
|
28 | var p = P();
|
29 | setTimeout( p, 1000 );
|
30 | return p;
|
31 | }).then( function(){
|
32 | console.log( "Very done" );
|
33 | }, function(){
|
34 | console.log( "Unexpected error" );
|
35 | process.exit( 1 );
|
36 | });
|
37 |
|
38 | p.then( function(){
|
39 | console.log( "END" );
|
40 | }).then( function(){
|
41 | throw "ERR1";
|
42 | }).then().then( null, function( err ){
|
43 | console.log( "Expected error: ", err );
|
44 | console.assert( err === "ERR1" );
|
45 | return "OK";
|
46 | }).then( function( ok ){
|
47 | console.log( "ok: ", ok );
|
48 | console.assert( ok === "OK" );
|
49 | throw "ERR2";
|
50 | }).then( null, function( err ){
|
51 | console.log( "Expected error 2: ", err );
|
52 | console.assert( err === "ERR2" );
|
53 | console.log( "TEST SUCCESS" );
|
54 | process.exit( 0 );
|
55 | });
|
56 |
|
57 | p.then( function(){
|
58 | console.log( "Branch" );
|
59 | }).then( function(){ console.log( "Branch done" ); } );
|
60 |
|
61 | p.then( function(){
|
62 | console.log( "Another Branch" );
|
63 | }).then( function(){ console.log( "Another Branch done" ); } );
|
64 |
|
65 | var l8 = require( "l8/lib/l8.js" );
|
66 | l8.countdown( 10 );
|
67 |
|