Security News
ESLint is Now Language-Agnostic: Linting JSON, Markdown, and Beyond
ESLint has added JSON and Markdown linting support with new officially-supported plugins, expanding its versatility beyond JavaScript.
grunt-lib-phantomjs
Advanced tools
Grunt and PhantomJS, sitting in a tree.
The best way to understand how this lib should be used is by looking at the grunt-contrib-qunit plugin. Mainly, look at how the lib is required, how event handlers are bound and how PhantomJS is actually spawned.
Also, in the case of the grunt-contrib-qunit plugin, it's important to know that the page being loaded into PhantomJS doesn't know it will be loaded into PhantomJS, and as such doesn't have any PhantomJS->Grunt code in it. That communication code, aka. the "bridge", is dynamically injected into the html page.
If a Grunt task looked something like this:
grunt.registerTask('mytask', 'Integrate with phantomjs.', function() {
var phantomjs = require('./lib/phantomjs').init(grunt);
var errorCount = 0;
// Handle any number of namespaced events like so.
phantomjs.on('mytask.ok', function(msg) {
grunt.log.writeln(msg);
});
phantomjs.on('mytask.error', function(msg) {
errorCount++;
grunt.log.error(msg);
});
// Create some kind of "all done" event.
phantomjs.on('mytask.done', function() {
phantomjs.halt();
});
// This task is async.
var done = this.async();
// Spawn phantomjs
phantomjs.spawn('test.html', {
// Additional PhantomJS options.
options: {},
// Complete the task when done.
done: function(err) {
done(err || errorCount === 0);
}
});
});
And test.html
looked something like this (note the "bridge" is hard-coded into this page and not injected):
<!doctype html>
<html>
<head>
<script>
// Send messages to the parent PhantomJS process via alert! Good times!!
function sendMessage() {
var args = [].slice.call(arguments);
alert(JSON.stringify(args));
}
sendMessage('mytask.ok', 'Something worked.');
sendMessage('mytask.error', 'Something failed.');
sendMessage('mytask.done');
</script>
</head>
<body>
</body>
</html>
Then running Grunt would behave something like this:
$ grunt mytask
Running "mytask" task
Something worked.
>> Something failed.
Warning: Task "mytask" failed. Use --force to continue.
Aborted due to warnings.
FAQs
Grunt and PhantomJS, sitting in a tree
The npm package grunt-lib-phantomjs receives a total of 16,227 weekly downloads. As such, grunt-lib-phantomjs popularity was classified as popular.
We found that grunt-lib-phantomjs demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 8 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
ESLint has added JSON and Markdown linting support with new officially-supported plugins, expanding its versatility beyond JavaScript.
Security News
Members Hub is conducting large-scale campaigns to artificially boost Discord server metrics, undermining community trust and platform integrity.
Security News
NIST has failed to meet its self-imposed deadline of clearing the NVD's backlog by the end of the fiscal year. Meanwhile, CVE's awaiting analysis have increased by 33% since June.