Skip to content

Commit

Permalink
Pull request feedback :
Browse files Browse the repository at this point in the history
1) Changed x, y to width, height
2) Removed setTimeout, and simplified viewport changing
3) Wrote tests - tested on both phantomjs and slimerjs
  • Loading branch information
maqqju committed Apr 27, 2016
1 parent 118eb8f commit dbb310a
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 11 deletions.
4 changes: 2 additions & 2 deletions README.md
Expand Up @@ -124,8 +124,8 @@ if (window.callPhantom) {
if (window.callPhantom) {
window.callPhantom({
viewportSize : {
x : 100,
y : 100
width : 100,
height : 100
}
});
}
Expand Down
14 changes: 5 additions & 9 deletions mocha-phantomjs-core.js
Expand Up @@ -114,15 +114,11 @@ page.onCallback = function(data) {
output.write(data.stdout)
} else if (typeof data.screenshot === 'string') {
page.render(data.screenshot + '.png')
} else if (data.viewportSize && (data.viewportSize.x || data.viewportSize.y)) {
setTimeout(function() {
page.viewportSize = (function(_page, _current, _x, _y) {
return _page.viewportSize = {
width : _x || _current.width,
height : _y || _current.height
};
})(page, page.viewportSize, data.viewportSize.x, data.viewportSize.y);
}, 0);
} else if (data.viewportSize && (data.viewportSize.width || data.viewportSize.height)) {
page.viewportSize = {
width: data.viewportSize.width || page.viewportSize.width,
height: data.viewportSize.height || page.viewportSize.height,
}
} else if (data.configureColWidth) {
page.evaluate(function(columns) {
Mocha.reporters.Base.window.width = columns
Expand Down
23 changes: 23 additions & 0 deletions test/lib/viewport-size.js
@@ -0,0 +1,23 @@
describe('Viewport Size Change', function() {
it('changes viewport size', function() {
if (window.callPhantom) {
console.log("Changing viewport size to : width 500, height 500")
callPhantom({'viewportSize': { width : 500, height : 500}})
}
});

it('changes viewport size - only on width', function() {
if (window.callPhantom) {
console.log("Changing viewport size to : width 1000")
callPhantom({'viewportSize': { width : 1000}})
}
})

it('chanves viewport size - only on height', function() {
if (window.callPhantom) {
console.log("Changing viewport size to : height 1000")
callPhantom({'viewportSize': { height : 1000}})
}
})
});

20 changes: 20 additions & 0 deletions test/viewport-size.html
@@ -0,0 +1,20 @@
<html>
<head>
<title>Viewport size test</title>
<meta charset="utf-8">
<link rel="stylesheet" href="../node_modules/mocha/mocha.css" />
</head>
<body>
<div id="mocha"></div>
<script src="../node_modules/mocha/mocha.js"></script>
<script>
mocha.ui('bdd');
mocha.reporter('html');
</script>
<script src="lib/viewport-size.js"></script>
<script>
mocha.run();
</script>
</body>
</html>

0 comments on commit dbb310a

Please sign in to comment.