diff --git a/README.md b/README.md index 047a8c6..4c0e9c0 100644 --- a/README.md +++ b/README.md @@ -124,8 +124,8 @@ if (window.callPhantom) { if (window.callPhantom) { window.callPhantom({ viewportSize : { - x : 100, - y : 100 + width : 100, + height : 100 } }); } diff --git a/mocha-phantomjs-core.js b/mocha-phantomjs-core.js index 0743a93..4718cd3 100644 --- a/mocha-phantomjs-core.js +++ b/mocha-phantomjs-core.js @@ -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 diff --git a/test/lib/viewport-size.js b/test/lib/viewport-size.js new file mode 100644 index 0000000..b7ac21c --- /dev/null +++ b/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}}) + } + }) +}); + diff --git a/test/viewport-size.html b/test/viewport-size.html new file mode 100644 index 0000000..25c0951 --- /dev/null +++ b/test/viewport-size.html @@ -0,0 +1,20 @@ + + + Viewport size test + + + + +
+ + + + + + +