UNPKG

1.53 kBJavaScriptView Raw
1// test/node.js
2// This is a test for the remote access to node.js API from a node_client.js
3// powered client to a node_server.js powered server.
4//
5// 2013/02/08 by JHR
6//
7
8// Embbed server
9var l8 = require( "l8/lib/node_server.js" )
10l8.http_port = parseInt( process.env.PORT, 10) || 8080 // 80 requires sudo
11l8.node_api_server( l8.http_port, "no credentials" )
12
13// But behave as a client
14require( "l8/lib/node_client.js" )
15l8.node_api_client( "http://localhost:" + l8.http_port, "no credentials" )
16
17// Let's create a task, blocking activities need a task.
18l8.task( function(){
19
20 // Open a file, truncated, write into it, close it, read content, check
21
22 var fs
23 var Buffer
24 var fd
25
26 l8.step( function ( ) { l8.require( "fs" );
27 }).step( function (m) { fs = m;
28 l8.require( "buffer" );
29 }).step( function (m) { Buffer = m.Buffer;
30 fs.open( "node.js.test_file.txt", "w" );
31 }).step( function (f) { fd = f;
32 new Buffer( "Hello, world!", "utf8" );
33 }).step( function (b) { fs.write( fd, b, 0, b.length, null );
34 }).step( function ( ) { fs.close( fd );
35 }).step( function ( ) { fs.readFile( "node.js.test_file.txt", "utf8" );
36 }).step( function (r) { l8.assert( r === "Hello, world!" );
37 l8.trace( "TEST SUCCESS");
38 process.exit( 0 )
39 }).failure( function (e) { l8.trace( "Unexpected error", e, e.stack ); })
40
41}) // end of task
42
43l8.countdown( 100 )
44