grunt-lib-phantomjs
Advanced tools
Comparing version 0.5.0 to 0.6.0
@@ -47,7 +47,23 @@ /* | ||
halted = null; | ||
// Handle for spawned process. | ||
var phantomJSHandle; | ||
// Default options. | ||
if (typeof options.killTimeout !== 'number') { options.timeout = 5000; } | ||
options.options = options.options || {}; | ||
// All done? Clean up! | ||
var cleanup = function() { | ||
var cleanup = function(done, immediate) { | ||
clearTimeout(id); | ||
tempfile.unlink(); | ||
var kill = function(){ | ||
// Only kill process if it's connected, otherwise an error would be thrown. | ||
if (phantomJSHandle.connected){ | ||
phantomJSHandle.kill(); | ||
} | ||
if (typeof done === 'function') { done(null); } | ||
}; | ||
// Allow immediate killing in an error condition. | ||
if (immediate) { return kill(); } | ||
// Wait until the timeout expires to kill the process, so it can clean up. | ||
setTimeout(kill, options.killTimeout); | ||
}; | ||
@@ -108,4 +124,3 @@ | ||
// All done. | ||
cleanup(); | ||
options.done(null); | ||
cleanup(options.done); | ||
} else { | ||
@@ -151,3 +166,3 @@ // Update n so previously processed lines are ignored. | ||
// Actually spawn PhantomJS. | ||
return grunt.util.spawn({ | ||
return phantomJSHandle = grunt.util.spawn({ | ||
cmd: binPath, | ||
@@ -157,6 +172,10 @@ args: args | ||
if (!err) { return; } | ||
// Something went horribly wrong. | ||
cleanup(); | ||
// Ignore intentional cleanup. | ||
if (code === 15 /* SIGTERM */){ return; } | ||
// If we're here, something went horribly wrong. | ||
cleanup(null, true /* immediate */); | ||
grunt.verbose.or.writeln(); | ||
grunt.log.write('Running PhantomJS...').error(); | ||
grunt.log.write('PhantomJS threw an error:').error(); | ||
// Print result to stderr because sometimes the 127 code means that a shared library is missing | ||
@@ -163,0 +182,0 @@ String(result).split('\n').forEach(grunt.log.error, grunt.log); |
{ | ||
"name": "grunt-lib-phantomjs", | ||
"description": "Grunt and PhantomJS, sitting in a tree.", | ||
"version": "0.5.0", | ||
"version": "0.6.0", | ||
"homepage": "http://github.com/gruntjs/grunt-lib-phantomjs", | ||
@@ -24,6 +24,6 @@ "author": { | ||
"engines": { | ||
"node": ">= 0.6.0" | ||
"node": ">= 0.8.0" | ||
}, | ||
"scripts": { | ||
"test": "grunt test" | ||
"test": "grunt jshint test" | ||
}, | ||
@@ -40,3 +40,4 @@ "dependencies": { | ||
"difflet": "~0.2.3", | ||
"express": "~3.1.1" | ||
"express": "~3.1.1", | ||
"grunt-cli": "~0.1.13" | ||
}, | ||
@@ -43,0 +44,0 @@ "main": "lib/phantomjs", |
@@ -38,2 +38,5 @@ /* | ||
// Create a new page. | ||
var page = require('webpage').create(options.page); | ||
// Abort if the page doesn't send any messages for a while. | ||
@@ -43,2 +46,5 @@ setInterval(function() { | ||
sendMessage('fail.timeout'); | ||
if (options.screenshot) { | ||
page.render(['page-at-timeout-', Date.now(), '.jpg'].join('')); | ||
} | ||
phantom.exit(); | ||
@@ -48,4 +54,2 @@ } | ||
// Create a new page. | ||
var page = require('webpage').create(options.page); | ||
@@ -132,2 +136,5 @@ // Inject bridge script into client page. | ||
sendMessage('fail.load', url); | ||
if (options.screenshot) { | ||
page.render(['page-at-timeout-', Date.now(), '.jpg'].join('')); | ||
} | ||
phantom.exit(); | ||
@@ -134,0 +141,0 @@ } |
# grunt-lib-phantomjs | ||
[![Build Status](https://travis-ci.org/gruntjs/grunt-lib-phantomjs.png?branch=master)](https://travis-ci.org/gruntjs/grunt-lib-phantomjs) | ||
> Grunt and PhantomJS, sitting in a tree. | ||
@@ -16,2 +18,3 @@ | ||
* `page`: an object of options for the PhantomJS [`page` object](https://github.com/ariya/phantomjs/wiki/API-Reference-WebPage). | ||
* `screenshot`: saves a screenshot on failure | ||
@@ -110,8 +113,1 @@ ## An inline example | ||
apt-get install libfontconfig1 fontconfig libfontconfig1-dev libfreetype6-dev | ||
## Release History | ||
* 2013-08-02 - v0.4.0 - /34 /18 /24 merged | ||
* 2013-02-28 - v0.3.0 - Use PhantomJS 1.9.0-1. | ||
* 2013-02-28 - v0.2.0 - Use PhantomJS 1.8.1. | ||
* 2012-12-21 - v0.1.0 - Use PhantomJS 1.7.0. |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
15398
292
5
112