Skip to content

Commit

Permalink
update hammerhead version (close DevExpress#930, DevExpress#1473) (De…
Browse files Browse the repository at this point in the history
  • Loading branch information
miherlosev committed Aug 15, 2017
1 parent 22b6f87 commit 7428dd0
Show file tree
Hide file tree
Showing 14 changed files with 58 additions and 15 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@
"stack-chain": "^1.3.6",
"strip-bom": "^2.0.0",
"testcafe-browser-tools": "1.2.4",
"testcafe-hammerhead": "11.0.3",
"testcafe-hammerhead": "11.1.1",
"testcafe-legacy-api": "3.1.1",
"testcafe-reporter-json": "^2.1.0",
"testcafe-reporter-list": "^2.1.0",
Expand Down
3 changes: 2 additions & 1 deletion src/client/.eslintrc
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
"rules": {
"hammerhead/use-hh-promise": 2,
"hammerhead/use-native-methods": [2, ["setTimeout", "setInterval", "clearTimeout", "clearInterval"]]
"hammerhead/use-native-methods": [2, ["setTimeout", "setInterval", "clearTimeout", "clearInterval"]],
"no-restricted-globals": [2, "Object", "JSON"]
},
"env": {
"browser": true,
Expand Down
2 changes: 1 addition & 1 deletion src/client/automation/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ exports.cursor = cursor;

exports.get = require;

Object.defineProperty(window, '%testCafeAutomation%', {
hammerhead.nativeMethods.objectDefineProperty.call(window, window, '%testCafeAutomation%', {
enumerable: false,
configurable: false,
writable: false,
Expand Down
6 changes: 4 additions & 2 deletions src/client/browser/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ function sendXHR (url, createXHR, method = 'GET', data = null) {
xhr.onreadystatechange = () => {
if (xhr.readyState === 4) {
if (xhr.status === 200)
/*eslint-disable no-restricted-globals*/
resolve(xhr.responseText ? JSON.parse(xhr.responseText) : '');
/*eslint-enable no-restricted-globals*/
else
reject('disconnected');
}
Expand Down Expand Up @@ -48,9 +50,9 @@ function executeInitScript (initScriptUrl, createXHR) {
if (!res.code)
return null;

/* eslint-disable no-eval */
/* eslint-disable no-eval, no-restricted-globals*/
return sendXHR(initScriptUrl, createXHR, 'POST', JSON.stringify(eval(res.code)));
/* eslint-enable no-eval */
/* eslint-enable no-eval, no-restricted-globals */
})
.then(() => {
window.setTimeout(() => executeInitScript(initScriptUrl, createXHR), 1000);
Expand Down
2 changes: 1 addition & 1 deletion src/client/core/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ exports.selectorAttributeFilter = selectorAttributeFilter;

exports.get = require;

Object.defineProperty(window, '%testCafeCore%', {
hammerhead.nativeMethods.objectDefineProperty.call(window, window, '%testCafeCore%', {
enumerable: false,
configurable: false,
writable: false,
Expand Down
4 changes: 3 additions & 1 deletion src/client/core/utils/array.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import hammerhead from '../deps/hammerhead';

var nativeIndexOf = Array.prototype.indexOf;
var nativeForEach = Array.prototype.forEach;
var nativeSome = Array.prototype.some;
Expand All @@ -22,7 +24,7 @@ export function reverse (arr) {
}

export function isArray (arg) {
return Object.prototype.toString.call(arg) === '[object Array]';
return hammerhead.nativeMethods.objectToString.call(arg) === '[object Array]';
}

export function find (arr, callback) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import Replicator from 'replicator';
import evalFunction from './eval-function';
import { NodeSnapshot, ElementSnapshot } from './selector-executor/node-snapshots';
import { DomNodeClientFunctionResultError, UncaughtErrorInCustomDOMPropertyCode } from '../../../../errors/test-run';
import hammerhead from '../../deps/hammerhead';

// NOTE: save original ctors because they may be overwritten by page code
var Node = window.Node;
Expand Down Expand Up @@ -45,7 +46,7 @@ export class SelectorNodeTransform {
}

_extend (snapshot, node) {
Object.keys(this.customDOMProperties).forEach(prop => {
hammerhead.nativeMethods.objectKeys.call(window.Object, this.customDOMProperties).forEach(prop => {
try {
snapshot[prop] = this.customDOMProperties[prop](node);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { InvalidSelectorResultError } from '../../../../../errors/test-run';
import hammerhead from '../../../deps/hammerhead';

// NOTE: save original ctors and methods because they may be overwritten by page code
var isArray = Array.isArray;
Expand All @@ -24,7 +25,7 @@ function getNodeByIndex (collection, index) {


// Selector filter
Object.defineProperty(window, '%testCafeSelectorFilter%', {
hammerhead.nativeMethods.objectDefineProperty.call(window, window, '%testCafeSelectorFilter%', {
value: (node, options) => {
var filtered = [];

Expand Down
1 change: 1 addition & 0 deletions src/client/driver/driver.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ export default class Driver {
preventRealEvents();

hammerhead.on(hammerhead.EVENTS.uncaughtJsError, err => this._onJsError(err));
hammerhead.on(hammerhead.EVENTS.unhandledRejection, err => this._onJsError(err));
}

set speed (val) {
Expand Down
6 changes: 3 additions & 3 deletions src/client/driver/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,21 @@ import IframeDriver from './iframe-driver';
import ScriptExecutionBarrier from './script-execution-barrier';


Object.defineProperty(window, '%testCafeDriver%', {
hammerhead.nativeMethods.objectDefineProperty.call(window, window, '%testCafeDriver%', {
enumerable: false,
configurable: false,
writable: false,
value: Driver
});

Object.defineProperty(window, '%testCafeIframeDriver%', {
hammerhead.nativeMethods.objectDefineProperty.call(window, window, '%testCafeIframeDriver%', {
enumerable: false,
configurable: false,
writable: false,
value: IframeDriver
});

Object.defineProperty(window, '%ScriptExecutionBarrier%', {
hammerhead.nativeMethods.objectDefineProperty.call(window, window, '%ScriptExecutionBarrier%', {
enumerable: false,
configurable: false,
writable: false,
Expand Down
2 changes: 1 addition & 1 deletion src/client/ui/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ exports.show = function (showTopRoot) {
return Promise.resolve();
};

Object.defineProperty(window, '%testCafeUI%', {
hammerhead.nativeMethods.objectDefineProperty.call(window, window, '%testCafeUI%', {
enumerable: false,
configurable: false,
writable: false,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Unhandled Promise rejection</title>
</head>
<body>
<button id="button" onclick="Promise.reject('Rejection reason')">Reject</button>
</body>
</html>
23 changes: 21 additions & 2 deletions test/functional/fixtures/page-js-errors/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,29 @@ describe('Test should fail after js-error on the page', function () {
errorInEachBrowserContains(errs, 'Error before reload', 0);
});
});

it('if unhandled promise rejection is raised', function () {
return runTests('./testcafe-fixtures/unhandled-promise-rejection-test.js', 'Click button',
{
shouldFail: true,
only: 'chrome'
})
.catch(function (errs) {
errorInEachBrowserContains(errs, 'Rejection reason', 0);
});
});
});

describe('Should ignore an js-error on the page', function () {
it('if the skipJsErrors option is set to true', function () {
describe('Should ignore an js-error on the page if the skipJsErrors option is set to true', function () {
it('uncaught JavaScript error', function () {
return runTests('./testcafe-fixtures/error-after-click-test.js', 'Click button', { skipJsErrors: true });
});

it ('unhandled Promise rejection', function () {
return runTests('./testcafe-fixtures/unhandled-promise-rejection-test.js', 'Click button',
{
skipJsErrors: true,
only: 'chrome'
});
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
fixture `Unhandled Promise rejection`
.page `http://localhost:3000/fixtures/page-js-errors/pages/unhandled-promise-rejection-test.html`;

test('Click button', async t => {
await t.click('#button');
});

0 comments on commit 7428dd0

Please sign in to comment.