-
Notifications
You must be signed in to change notification settings - Fork 4
/
index.js
38 lines (36 loc) · 917 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
module.exports = function( options, callback ) {
var option, spider,
startTime = new Date(),
findup = require( "findup-sync" ),
duration = require( "duration" ),
spawn = require( "child_process" ).spawn,
casperPath = findup( "node_modules/.bin/casperjs", {
cwd: __dirname
} ),
args = [ "test", __dirname + "/lib/tests.js" ];
for ( option in options ) {
if ( options.hasOwnProperty( option ) ) {
args.push( "--" + option + "=" + options[ option ] );
}
}
spider = spawn(
casperPath,
args,
{
stdio: "pipe"
}
);
spider.stdout.on( "data", function( data ) {
process.stdout.write( data );
} );
spider.stderr.on( "data", function( data ) {
process.stderr.write( data );
} );
spider.on( "close", function( code ) {
process.stdout.write( "Spider completed in ~" +
new duration( startTime ).milliseconds + "ms \n" );
if ( callback ) {
callback( code );
}
} );
};