-
Notifications
You must be signed in to change notification settings - Fork 106
Screenshotting support #109
base: master
Are you sure you want to change the base?
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"name": "grunt-mocha", | ||
"description": "Grunt task for running client-side Mocha specs in PhantomJS", | ||
"name": "grunt-mocha-screenshot", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please don't modify the package name or description. :) |
||
"description": "grunt-mocha with screenshot added pending pull request", | ||
"version": "0.4.10", | ||
"homepage": "https://github.com/kmiyashiro/grunt-mocha", | ||
"author": { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -80,6 +80,21 @@ page.onAlert = function(str) { | |
|
||
// Relay console logging messages. | ||
page.onConsoleMessage = function(message) { | ||
try { | ||
var json = JSON.parse(message); | ||
if (json.action === 'viewportSize') { | ||
sendMessage('console', 'Changing viewport to width: ' + json.width + ' and height: ' + json.height); | ||
page.viewportSize = { width: json.width, height: json.height }; | ||
} else if (json.action === 'render') { | ||
sendMessage('console', 'Taking a screenshot to file: ' + json.filename); | ||
if (page.clipRect) { | ||
page.clipRect = json.clipRect; | ||
} | ||
page.render(json.filename); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we lift There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @robcolburn we've done both using what's in this PR. What we've done is to create a global function To take a screenshot: var container = $('article')[0]; // or any DOM node
console.log(JSON.stringify({
action: 'render', // mandatory
filename: 'screenshots/article.png', // mandatory
clipRect: container.getBoundingClientRect() // optional
})); The user can of course replace the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I still feel like I'd want to define the pattern along with other grunt configuration, rather than application-level code. But, that's just splitting hairs when there's a working solution here. |
||
} | ||
} catch(err) { | ||
sendMessage('console', 'Console message could not be parsed.'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This catch statement seems like it could get rather chatty with application code also using the console. Maybe scrap it or put the output behind a specific flag? |
||
} | ||
sendMessage('console', message); | ||
}; | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can may now configure a viewport size in available in newer versions of the grunt-lib-phantomjs dependency. So, maybe bump the dependency version?
https://github.com/gruntjs/grunt-lib-phantomjs/blob/master/Gruntfile.js#L74-78
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@robcolburn we needed to be able to keep changing the viewport during testing - especially with our responsive Sky.com websites that cater for mobile, tablet and desktop viewports.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 Makes sense. Having both (grunt) declarative and programmatic control of viewport is ideal.