Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

testcafe

Package Overview
Dependencies
Maintainers
1
Versions
464
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

testcafe - npm Package Compare versions

Comparing version 0.16.0-alpha4 to 0.16.0-alpha5

313

lib/browser/provider/built-in/chrome/cdp.js
'use strict';
exports.__esModule = true;
exports.resizeWindow = exports.takeScreenshot = exports.closeTab = exports.getClientInfo = undefined;
exports.resizeWindow = exports.takeScreenshot = exports.closeTab = exports.createClient = undefined;

@@ -44,6 +44,7 @@ var _regenerator = require('babel-runtime/regenerator');

var getWindowId = function () {
var _ref2 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee2(client, tab) {
var _ref3, windowId;
var setEmulationBounds = function () {
var _ref2 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee2(_ref3) {
var client = _ref3.client,
config = _ref3.config,
viewportSize = _ref3.viewportSize;
return _regenerator2.default.wrap(function _callee2$(_context2) {

@@ -53,17 +54,16 @@ while (1) {

case 0:
_context2.prev = 0;
_context2.next = 3;
return client.Browser.getWindowForTarget({ targetId: tab.id });
_context2.next = 2;
return client.Emulation.setDeviceMetricsOverride({
width: viewportSize.width,
height: viewportSize.height,
deviceScaleFactor: config.scaleFactor,
mobile: config.mobile,
fitWindow: false
});
case 3:
_ref3 = _context2.sent;
windowId = _ref3.windowId;
return _context2.abrupt('return', windowId);
case 2:
_context2.next = 4;
return client.Emulation.setVisibleSize({ width: viewportSize.width, height: viewportSize.height });
case 8:
_context2.prev = 8;
_context2.t0 = _context2['catch'](0);
return _context2.abrupt('return', null);
case 11:
case 4:
case 'end':

@@ -73,6 +73,6 @@ return _context2.stop();

}
}, _callee2, this, [[0, 8]]);
}, _callee2, this);
}));
return function getWindowId(_x3, _x4) {
return function setEmulationBounds(_x3) {
return _ref2.apply(this, arguments);

@@ -82,5 +82,5 @@ };

var setEmulationBounds = function () {
var _ref4 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee3(client, device, newDimensions) {
var width, height;
var setEmulation = function () {
var _ref4 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee3(runtimeInfo) {
var client, config;
return _regenerator2.default.wrap(function _callee3$(_context3) {

@@ -90,141 +90,108 @@ while (1) {

case 0:
width = newDimensions ? newDimensions.width : device.width;
height = newDimensions ? newDimensions.height : device.height;
_context3.next = 4;
return client.Emulation.setDeviceMetricsOverride({
width: width,
height: height,
deviceScaleFactor: device.scaleFactor,
mobile: device.mobile,
fitWindow: true
});
client = runtimeInfo.client, config = runtimeInfo.config;
case 4:
_context3.next = 6;
return client.Emulation.setVisibleSize({ width: width, height: height });
case 6:
case 'end':
return _context3.stop();
}
}
}, _callee3, this);
}));
return function setEmulationBounds(_x5, _x6, _x7) {
return _ref4.apply(this, arguments);
};
}();
var setEmulation = function () {
var _ref5 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee4(client, device) {
return _regenerator2.default.wrap(function _callee4$(_context4) {
while (1) {
switch (_context4.prev = _context4.next) {
case 0:
if (!(device.userAgent !== void 0)) {
_context4.next = 3;
if (!(config.userAgent !== void 0)) {
_context3.next = 4;
break;
}
_context4.next = 3;
return client.Network.setUserAgentOverride({ userAgent: device.userAgent });
_context3.next = 4;
return client.Network.setUserAgentOverride({ userAgent: config.userAgent });
case 3:
if (!(device.touch !== void 0)) {
_context4.next = 6;
case 4:
if (!(config.touch !== void 0)) {
_context3.next = 7;
break;
}
_context4.next = 6;
_context3.next = 7;
return client.Emulation.setTouchEmulationEnabled({
enabled: device.touch,
configuration: device.mobile ? 'mobile' : 'desktop'
enabled: config.touch,
configuration: config.mobile ? 'mobile' : 'desktop'
});
case 6:
_context4.next = 8;
return setEmulationBounds(client, device);
case 7:
_context3.next = 9;
return resizeWindow({ width: config.width, height: config.height }, runtimeInfo);
case 8:
case 9:
case 'end':
return _context4.stop();
return _context3.stop();
}
}
}, _callee4, this);
}, _callee3, this);
}));
return function setEmulation(_x8, _x9) {
return _ref5.apply(this, arguments);
return function setEmulation(_x4) {
return _ref4.apply(this, arguments);
};
}();
var getClientInfo = exports.getClientInfo = function () {
var _ref6 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee5(browserId, _ref7) {
var config = _ref7.config,
cdpPort = _ref7.cdpPort;
var tab, client, windowId;
return _regenerator2.default.wrap(function _callee5$(_context5) {
var createClient = exports.createClient = function () {
var _ref5 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee4(runtimeInfo) {
var browserId, config, cdpPort, tab, client;
return _regenerator2.default.wrap(function _callee4$(_context4) {
while (1) {
switch (_context5.prev = _context5.next) {
switch (_context4.prev = _context4.next) {
case 0:
_context5.prev = 0;
_context5.next = 3;
browserId = runtimeInfo.browserId, config = runtimeInfo.config, cdpPort = runtimeInfo.cdpPort;
_context4.next = 3;
return getActiveTab(cdpPort, browserId);
case 3:
tab = _context5.sent;
tab = _context4.sent;
if (tab) {
_context5.next = 6;
_context4.next = 6;
break;
}
return _context5.abrupt('return', {});
return _context4.abrupt('return');
case 6:
_context5.next = 8;
_context4.prev = 6;
_context4.next = 9;
return (0, _chromeRemoteInterface2.default)({ target: tab, port: cdpPort });
case 8:
client = _context5.sent;
_context5.next = 11;
return getWindowId(client, tab);
case 9:
client = _context4.sent;
_context4.next = 15;
break;
case 11:
windowId = _context5.sent;
_context5.next = 14;
case 12:
_context4.prev = 12;
_context4.t0 = _context4['catch'](6);
return _context4.abrupt('return');
case 15:
runtimeInfo.tab = tab;
runtimeInfo.client = client;
_context4.next = 19;
return client.Page.enable();
case 14:
_context5.next = 16;
case 19:
_context4.next = 21;
return client.Network.enable();
case 16:
case 21:
if (!config.emulation) {
_context5.next = 19;
_context4.next = 24;
break;
}
_context5.next = 19;
return setEmulation(client, config);
_context4.next = 24;
return setEmulation(runtimeInfo);
case 19:
return _context5.abrupt('return', { tab: tab, client: client, windowId: windowId });
case 22:
_context5.prev = 22;
_context5.t0 = _context5['catch'](0);
return _context5.abrupt('return', {});
case 25:
case 24:
case 'end':
return _context5.stop();
return _context4.stop();
}
}
}, _callee5, this, [[0, 22]]);
}, _callee4, this, [[6, 12]]);
}));
return function getClientInfo(_x10, _x11) {
return _ref6.apply(this, arguments);
return function createClient(_x5) {
return _ref5.apply(this, arguments);
};

@@ -234,10 +201,10 @@ }();

var closeTab = exports.closeTab = function () {
var _ref9 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee6(_ref10) {
var tab = _ref10.tab,
cdpPort = _ref10.cdpPort;
return _regenerator2.default.wrap(function _callee6$(_context6) {
var _ref7 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee5(_ref8) {
var tab = _ref8.tab,
cdpPort = _ref8.cdpPort;
return _regenerator2.default.wrap(function _callee5$(_context5) {
while (1) {
switch (_context6.prev = _context6.next) {
switch (_context5.prev = _context5.next) {
case 0:
_context6.next = 2;
_context5.next = 2;
return _chromeRemoteInterface2.default.closeTab({ id: tab.id, port: cdpPort });

@@ -247,10 +214,10 @@

case 'end':
return _context6.stop();
return _context5.stop();
}
}
}, _callee6, this);
}, _callee5, this);
}));
return function closeTab(_x12) {
return _ref9.apply(this, arguments);
return function closeTab(_x6) {
return _ref7.apply(this, arguments);
};

@@ -260,16 +227,16 @@ }();

var takeScreenshot = exports.takeScreenshot = function () {
var _ref11 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee7(path, _ref12) {
var client = _ref12.client,
config = _ref12.config;
var _ref9 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee6(path, _ref10) {
var client = _ref10.client,
config = _ref10.config;
var screenshot;
return _regenerator2.default.wrap(function _callee7$(_context7) {
return _regenerator2.default.wrap(function _callee6$(_context6) {
while (1) {
switch (_context7.prev = _context7.next) {
switch (_context6.prev = _context6.next) {
case 0:
_context7.next = 2;
_context6.next = 2;
return client.Page.captureScreenshot({ fromSurface: config.headless });
case 2:
screenshot = _context7.sent;
_context7.next = 5;
screenshot = _context6.sent;
_context6.next = 5;
return (0, _promisifiedFunctions.writeFile)(path, screenshot.data, { encoding: 'base64' });

@@ -279,10 +246,10 @@

case 'end':
return _context7.stop();
return _context6.stop();
}
}
}, _callee7, this);
}, _callee6, this);
}));
return function takeScreenshot(_x13, _x14) {
return _ref11.apply(this, arguments);
return function takeScreenshot(_x7, _x8) {
return _ref9.apply(this, arguments);
};

@@ -292,59 +259,45 @@ }();

var resizeWindow = exports.resizeWindow = function () {
var _ref13 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee8(newDimensions, currentDimensions, _ref14) {
var config = _ref14.config,
client = _ref14.client,
windowId = _ref14.windowId;
var newWidth, newHeight, currentWidth, currentHeight, bounds;
return _regenerator2.default.wrap(function _callee8$(_context8) {
var _ref11 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee7(newDimensions, runtimeInfo) {
var browserId, config, viewportSize, currentWidth, currentHeight, newWidth, newHeight;
return _regenerator2.default.wrap(function _callee7$(_context7) {
while (1) {
switch (_context8.prev = _context8.next) {
switch (_context7.prev = _context7.next) {
case 0:
newWidth = newDimensions.width;
newHeight = newDimensions.height;
currentWidth = currentDimensions.width;
currentHeight = currentDimensions.height;
browserId = runtimeInfo.browserId, config = runtimeInfo.config, viewportSize = runtimeInfo.viewportSize;
currentWidth = viewportSize.width;
currentHeight = viewportSize.height;
newWidth = newDimensions.width || currentWidth;
newHeight = newDimensions.height || currentHeight;
if (!(config.emulation || !windowId && config.headless)) {
_context8.next = 8;
if (config.headless) {
_context7.next = 8;
break;
}
_context8.next = 7;
return setEmulationBounds(client, config.device, { width: newWidth, height: newHeight });
_context7.next = 8;
return _testcafeBrowserTools2.default.resize(browserId, currentWidth, currentHeight, newWidth, newHeight);
case 7:
return _context8.abrupt('return');
case 8:
case 8:
if (windowId) {
_context8.next = 10;
viewportSize.width = newWidth;
viewportSize.height = newHeight;
if (!config.emulation) {
_context7.next = 13;
break;
}
return _context8.abrupt('return');
_context7.next = 13;
return setEmulationBounds(runtimeInfo);
case 10:
_context8.next = 12;
return client.Browser.getWindowBounds({ windowId: windowId });
case 12:
bounds = _context8.sent;
bounds.width += newWidth - currentWidth;
bounds.height += newHeight - currentHeight;
_context8.next = 17;
return client.Browser.setWindowBounds({ windowId: windowId, bounds: bounds });
case 17:
case 13:
case 'end':
return _context8.stop();
return _context7.stop();
}
}
}, _callee8, this);
}, _callee7, this);
}));
return function resizeWindow(_x15, _x16, _x17) {
return _ref13.apply(this, arguments);
return function resizeWindow(_x9, _x10) {
return _ref11.apply(this, arguments);
};

@@ -359,2 +312,6 @@ }();

var _testcafeBrowserTools = require('testcafe-browser-tools');
var _testcafeBrowserTools2 = _interopRequireDefault(_testcafeBrowserTools);
var _promisifiedFunctions = require('../../../../utils/promisified-functions');

@@ -364,7 +321,7 @@

function isHeadlessTab(_ref8) {
var tab = _ref8.tab,
config = _ref8.config;
function isHeadlessTab(_ref6) {
var tab = _ref6.tab,
config = _ref6.config;
return tab && config.headless;
}

@@ -13,6 +13,2 @@ 'use strict';

var _keys = require('babel-runtime/core-js/object/keys');
var _keys2 = _interopRequireDefault(_keys);
exports.default = function (configString) {

@@ -36,7 +32,7 @@ if (!configCache[configString]) configCache[configString] = getNewConfig(configString);

var CONFIG_TERMINATOR_RE = /(\s+|^)-/;
var HEADLESS_DEFAULT_WIDTH = 1280;
var HEADLESS_DEFAULT_HEIGHT = 800;
var CONFIG_TERMINATOR_RE = /(\s+|^)-/;
var configCache = {};

@@ -93,10 +89,10 @@

function getPathFromParsedModes(modesList) {
var pathRegExp = /^path=(.*)/;
var pathIndex = (0, _lodash.findIndex)(modesList, function (el) {
return el.match(pathRegExp);
});
var path = findMatch(modesList, pathRegExp);
if (!modesList.length) return '';
if (_osFamily2.default.win && pathIndex > -1 && pathIndex < modesList.length - 1 && path.match(/^[A-Za-z]$/)) path += ':' + modesList[pathIndex + 1];
if (modesList[0] === 'headless' || modesList[0] === 'emulation') return '';
var path = modesList.shift();
if (_osFamily2.default.win && modesList.length && path.match(/^[A-Za-z]$/)) path += ':' + modesList.shift();
return path;

@@ -108,16 +104,20 @@ }

var path = getPathFromParsedModes(parsed);
var headless = hasMatch(parsed, /^headless$/);
var nextMode = parsed.shift();
var hasHeadless = nextMode === 'headless';
var modes = {
if (hasHeadless) nextMode = parsed.shift();
var hasEmulation = nextMode === 'emulation';
if (hasEmulation) nextMode = parsed.shift();
while (parsed.length) {
nextMode += ':' + parsed.shift();
}var modes = {
path: path,
headless: headless,
emulation: hasMatch(parsed, /^emulation$/) || headless
headless: hasHeadless,
emulation: hasEmulation || hasHeadless
};
var countOfModes = (0, _keys2.default)(modes).reduce(function (count, key) {
return modes[key] ? count + 1 : count;
}, 0);
var optionsString = countOfModes < parsed.length ? parsed[parsed.length - 1] : '';
return { modes: modes, optionsString: optionsString };
return { modes: modes, optionsString: nextMode || '' };
}

@@ -124,0 +124,0 @@

@@ -9,6 +9,2 @@ 'use strict';

var _assign = require('babel-runtime/core-js/object/assign');
var _assign2 = _interopRequireDefault(_assign);
var _asyncToGenerator2 = require('babel-runtime/helpers/asyncToGenerator');

@@ -44,2 +40,13 @@

/*eslint-disable no-undef*/
function getWindowDimensionsInfo() {
return {
width: window.innerWidth,
height: window.innerHeight
};
}
/*eslint-enable no-undef*/
var GET_WINDOW_DIMENSIONS_INFO_SCRIPT = getWindowDimensionsInfo.toString();
exports.default = {

@@ -54,3 +61,3 @@ openedBrowsers: {},

return (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee() {
var runtimeInfo, browserName, cdpClientInfo;
var runtimeInfo, browserName;
return _regenerator2.default.wrap(function _callee$(_context) {

@@ -66,22 +73,28 @@ while (1) {

browserName = _this.providerName.replace(':', '');
_context.next = 6;
return (0, _localChrome.start)(browserName, pageUrl, runtimeInfo);
case 6:
runtimeInfo.browserId = browserId;
runtimeInfo.browserName = browserName;
_context.next = 8;
return _this.waitForConnectionReady(browserId);
return (0, _localChrome.start)(pageUrl, runtimeInfo);
case 8:
_context.next = 10;
return cdp.getClientInfo(browserId, runtimeInfo);
return _this.waitForConnectionReady(browserId);
case 10:
cdpClientInfo = _context.sent;
_context.next = 12;
return _this.runInitScript(browserId, GET_WINDOW_DIMENSIONS_INFO_SCRIPT);
case 12:
runtimeInfo.viewportSize = _context.sent;
_context.next = 15;
return cdp.createClient(runtimeInfo);
(0, _assign2.default)(runtimeInfo, cdpClientInfo);
case 15:
_this.openedBrowsers[browserId] = runtimeInfo;
case 13:
case 16:
case 'end':

@@ -193,6 +206,11 @@ return _context.stop();

runtimeInfo = _this5.openedBrowsers[browserId];
_context5.next = 3;
return cdp.resizeWindow({ width: width, height: height }, { width: currentWidth, height: currentHeight }, runtimeInfo);
case 3:
runtimeInfo.viewportSize.width = currentWidth;
runtimeInfo.viewportSize.height = currentHeight;
_context5.next = 5;
return cdp.resizeWindow({ width: width, height: height }, runtimeInfo);
case 5:
case 'end':

@@ -209,3 +227,3 @@ return _context5.stop();

return (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee6() {
var _openedBrowsers$brows, config, windowId, client;
var _openedBrowsers$brows, config, client;

@@ -216,5 +234,5 @@ return _regenerator2.default.wrap(function _callee6$(_context6) {

case 0:
_openedBrowsers$brows = _this6.openedBrowsers[browserId], config = _openedBrowsers$brows.config, windowId = _openedBrowsers$brows.windowId, client = _openedBrowsers$brows.client;
_openedBrowsers$brows = _this6.openedBrowsers[browserId], config = _openedBrowsers$brows.config, client = _openedBrowsers$brows.client;
return _context6.abrupt('return', {
hasResizeWindow: !!client && (config.emulation || windowId || config.headless),
hasResizeWindow: !!client && (config.emulation || config.headless),
hasTakeScreenshot: !!client,

@@ -221,0 +239,0 @@ hasCanResizeWindowToDimensions: false,

@@ -66,4 +66,5 @@ 'use strict';

var start = exports.start = function () {
var _ref2 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee2(browserName, pageUrl, _ref3) {
var config = _ref3.config,
var _ref2 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee2(pageUrl, _ref3) {
var browserName = _ref3.browserName,
config = _ref3.config,
cdpPort = _ref3.cdpPort,

@@ -115,3 +116,3 @@ tempUserDataDir = _ref3.tempUserDataDir;

return function start(_x2, _x3, _x4) {
return function start(_x2, _x3) {
return _ref2.apply(this, arguments);

@@ -148,3 +149,3 @@ };

return function stop(_x5) {
return function stop(_x4) {
return _ref4.apply(this, arguments);

@@ -151,0 +152,0 @@ };

@@ -5,3 +5,3 @@ {

"license": "MIT",
"version": "0.16.0-alpha4",
"version": "0.16.0-alpha5",
"author": {

@@ -104,4 +104,4 @@ "name": "Developer Express Inc.",

"strip-bom": "^2.0.0",
"testcafe-browser-tools": "1.2.1",
"testcafe-hammerhead": "10.8.1",
"testcafe-browser-tools": "1.2.2",
"testcafe-hammerhead": "10.9.0",
"testcafe-legacy-api": "3.0.0",

@@ -108,0 +108,0 @@ "testcafe-reporter-json": "^2.1.0",

@@ -1340,3 +1340,3 @@ // ClientFunction

*/
(name: string): this;
(name: string | TemplateStringsArray): this;
/**

@@ -1348,3 +1348,3 @@ * Specifies a webpage at which all tests in a fixture start.

*/
page(url: string): this;
page(url: string | TemplateStringsArray): this;
/**

@@ -1351,0 +1351,0 @@ * Specifies HTTP Basic or Windows (NTLM) authentication credentials for all tests in the fixture.

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc