@samitouri / QOS-React-2 / commits / 71772e763a

grunt task launch phantomjs as a webdriver server

Thomas Aylott committed Nov 6, 2013 at 15:12 UTC 71772e763a929bbc3dba0b4c6f8de895a3a7d385
2 files changed +40
Gruntfile.js
+3
@@ -5,6 +5,7 @@ var jsxTask = require('./grunt/tasks/jsx');
5 var browserifyTask = require('./grunt/tasks/browserify');
6 var populistTask = require('./grunt/tasks/populist');
7 var phantomTask = require('./grunt/tasks/phantom');
8 +var webdriverPhantomJSTask = require('./grunt/tasks/webdriver-phantomjs');
9 var webdriverJasmineTasks = require('./grunt/tasks/webdriver-jasmine');
10 var npmTask = require('./grunt/tasks/npm');
11 var releaseTasks = require('./grunt/tasks/release');
@@ -76,6 +77,8 @@ module.exports = function(grunt) {
77 'populist:test'
78 ]);
79
80 + grunt.registerTask('webdriver-phantomjs', webdriverPhantomJSTask);
81 +
82 grunt.registerTask('test:webdriver', [
83 'connect',
84 'webdriver-jasmine:local'
grunt/tasks/webdriver-phantomjs.js new
+37
@@ -0,0 +1,37 @@
1 +var grunt = require('grunt');
2 +
3 +module.exports = function(){
4 + var onReadyCallback = this.async();
5 +
6 + var phantomjs = require("phantomjs").path;
7 + var child_process = require('child_process');
8 + var config = this.data || {};
9 +
10 + var args = ["--webdriver=" + (config.port || 9515)];
11 + grunt.verbose.writeln('phantomjs START path:%s args:%s', phantomjs, args);
12 +
13 + var child = child_process.spawn(phantomjs, args);
14 + process.on('exit', function() {
15 + child.kill();
16 + });
17 +
18 + child.on('error', function(error) {
19 + grunt.verbose.writeln('phantomjs ERROR');
20 + grunt.fatal(error);
21 + });
22 + child.on('exit', function(code) {
23 + grunt.verbose.writeln('phantomjs END');
24 + if (code) grunt.fatal('phantomjs FAIL');
25 + });
26 +
27 + function verboseWrite(chunk) {
28 + if (onReadyCallback && chunk.toString().indexOf('running on port') != -1) {
29 + grunt.verbose.writeln('phantomjs STARTED');
30 + onReadyCallback();
31 + onReadyCallback = null;
32 + }
33 + grunt.verbose.write(chunk);
34 + }
35 + child.stdout.on('data', verboseWrite);
36 + child.stderr.on('data', verboseWrite);
37 +}