Skip to content

Commit

Permalink
Chain fix (#3040)
Browse files Browse the repository at this point in the history
* testing: esotope-hammerhead build testing

* testing: esotope-hammerhead build testing

* add: tests and refactor

* header updated

* tests updated

* tests updated

* tests updated

* bump: update esotope-hammerhead

* release: v31.7.5

* update: client test

* update: client test

---------

Co-authored-by: Bayheck <[email protected]>
  • Loading branch information
Bayheck and Bayheck authored Feb 12, 2025
1 parent 1b93e18 commit 0ffecaa
Show file tree
Hide file tree
Showing 12 changed files with 103 additions and 97 deletions.
12 changes: 6 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "testcafe-hammerhead",
"description": "A powerful web-proxy used as a core for the TestCafe testing framework (https://github.com/DevExpress/testcafe).",
"version": "31.7.4",
"version": "31.7.5",
"homepage": "https://github.com/DevExpress/testcafe-hammerhead",
"bugs": {
"url": "https://github.com/DevExpress/testcafe-hammerhead/issues"
Expand All @@ -21,7 +21,7 @@
"bowser": "1.6.0",
"crypto-md5": "^1.0.0",
"debug": "4.3.1",
"esotope-hammerhead": "0.6.8",
"esotope-hammerhead": "0.6.9",
"http-cache-semantics": "^4.1.0",
"httpntlm": "^1.8.10",
"iconv-lite": "0.5.1",
Expand Down
2 changes: 1 addition & 1 deletion src/processing/script/header.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ const HEADER = trim(`
var ${INSTRUCTION.getLocation} = function(l){return l},
${INSTRUCTION.setLocation} = function(l,v){return l = v},
${INSTRUCTION.setProperty} = function(o,p,v){return o[p] = v},
${INSTRUCTION.getProperty} = function(o,p){return o[p]},
${INSTRUCTION.getProperty} = function(o,p,opt=false){return opt&&(o===undefined||o===null)?undefined:o[p]},
${INSTRUCTION.callMethod} = function(o,p,a){return o[p].apply(o,a)},
${INSTRUCTION.getEval} = function(e){return e},
${INSTRUCTION.processScript} = function(s){return s},
Expand Down
57 changes: 30 additions & 27 deletions test/client/fixtures/sandbox/node/document-write-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ var nativeMethods = hammerhead.nativeMethods;
var iframeSandbox = hammerhead.sandbox.iframe;
var nodeSandbox = hammerhead.sandbox.node;
var domUtils = hammerhead.utils.dom;
var browserUtils = hammerhead.utils.browser;

iframeSandbox.on(iframeSandbox.RUN_TASK_SCRIPT_EVENT, initIframeTestHandler);
iframeSandbox.off(iframeSandbox.RUN_TASK_SCRIPT_EVENT, iframeSandbox.iframeReadyToInitHandler);
Expand Down Expand Up @@ -114,33 +115,35 @@ test('write incomplete tags', function () {
});
});

test('write script', function () {
return createWriteTestIframes()
.then(function () {
open();
testWrite('<script>var a, b, c;<' + '/script>');
testWrite('<script id="scr1">');
testContent('#scr1');
testWrite('var a = 5;');
testContent('#scr1');
testVariable('a');
testWrite('var b = 6;');
testContent('#scr1');
testVariable('b');
testWrite('<' + '/script>');
testContent('#scr1');
testVariable('a');
testVariable('b');
testWrite('var c = x + y;');
testWrite('<script id="scr2">var c=a<b;');
testContent('#scr2');
testVariable('c');
testWrite('<' + '/script>');
testContent('#scr2');
testVariable('c');
close();
});
});
if (!browserUtils.isFirefox) {
test('write script', function () {
return createWriteTestIframes()
.then(function () {
open();
testWrite('<script>var a, b, c;<' + '/script>');
testWrite('<script id="scr1">');
testContent('#scr1');
testWrite('var a = 5;');
testContent('#scr1');
testVariable('a');
testWrite('var b = 6;');
testContent('#scr1');
testVariable('b');
testWrite('<' + '/script>');
testContent('#scr1');
testVariable('a');
testVariable('b');
testWrite('var c = x + y;');
testWrite('<script id="scr2">var c=a<b;');
testContent('#scr2');
testVariable('c');
testWrite('<' + '/script>');
testContent('#scr2');
testVariable('c');
close();
});
});
}

test('write style', function () {
return createWriteTestIframes()
Expand Down
97 changes: 50 additions & 47 deletions test/client/fixtures/sandbox/node/text-properties-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ var styleProcessor = hammerhead.processors.styleProcessor;
var scriptProcessor = hammerhead.utils.processing.script;
var urlUtils = hammerhead.utils.url;
var DomProcessor = hammerhead.processors.DomProcessor;
var browserUtils = hammerhead.utils.browser;

var nativeMethods = hammerhead.nativeMethods;

Expand Down Expand Up @@ -49,71 +50,73 @@ test('stylesheet after innerHTML', function () {
check(nativeMethods.elementInnerHTMLGetter.call(style));
});

test('script.<innerHTML/innerText/text/textContent>', function () {
var script = document.createElement('script');
var scriptText = 'var test = window.href';
var processedScriptText = scriptProcessor.processScript(scriptText, true).replace(/\s/g, '');
var scriptWithImport = 'import foo from "foo.js"; import("bar.js").then(() => {});';
var processedScriptWithImport = scriptProcessor.processScript(scriptWithImport, true, false, urlUtils.convertToProxyUrl).replace(/\s/g, '');
var testProperties = {
'innerHTML': {
getter: nativeMethods.elementInnerHTMLGetter,
setter: nativeMethods.elementInnerHTMLSetter,
},

'innerText': {
getter: nativeMethods.htmlElementInnerTextGetter,
setter: nativeMethods.htmlElementInnerTextSetter,
},

'text': {
getter: nativeMethods.scriptTextGetter,
setter: nativeMethods.scriptTextSetter,
},

'textContent': {
getter: nativeMethods.nodeTextContentGetter,
setter: nativeMethods.nodeTextContentSetter,
},
};
if (!browserUtils.isFirefox) {
test('script.<innerHTML/innerText/text/textContent>', function () {
var script = document.createElement('script');
var scriptText = 'var test = window.href';
var processedScriptText = scriptProcessor.processScript(scriptText, true).replace(/\s/g, '');
var scriptWithImport = 'import foo from "foo.js"; import("bar.js").then(() => {});';
var processedScriptWithImport = scriptProcessor.processScript(scriptWithImport, true, false, urlUtils.convertToProxyUrl).replace(/\s/g, '');
var testProperties = {
'innerHTML': {
getter: nativeMethods.elementInnerHTMLGetter,
setter: nativeMethods.elementInnerHTMLSetter,
},

Object.keys(testProperties).forEach(function (property) {
var nativeGetter = testProperties[property].getter;
var nativeSetter = testProperties[property].setter;
'innerText': {
getter: nativeMethods.htmlElementInnerTextGetter,
setter: nativeMethods.htmlElementInnerTextSetter,
},

'text': {
getter: nativeMethods.scriptTextGetter,
setter: nativeMethods.scriptTextSetter,
},

'textContent': {
getter: nativeMethods.nodeTextContentGetter,
setter: nativeMethods.nodeTextContentSetter,
},
};

script[property] = scriptText;
Object.keys(testProperties).forEach(function (property) {
var nativeGetter = testProperties[property].getter;
var nativeSetter = testProperties[property].setter;

strictEqual(nativeGetter.call(script).replace(/\s/g, ''), processedScriptText);
script[property] = scriptText;

script[property] = '';
strictEqual(nativeGetter.call(script).replace(/\s/g, ''), processedScriptText);

strictEqual(nativeGetter.call(script).replace(/\s/g, ''), '');
script[property] = '';

script[property] = { a: 1 };
strictEqual(nativeGetter.call(script).replace(/\s/g, ''), '');

strictEqual(nativeGetter.call(script), '[object Object]');
script[property] = { a: 1 };

nativeSetter.call(script, null);
strictEqual(nativeGetter.call(script), '[object Object]');

var expectedValueForNull = nativeGetter.call(script);
nativeSetter.call(script, null);

script[property] = null;
var expectedValueForNull = nativeGetter.call(script);

strictEqual(nativeGetter.call(script), expectedValueForNull);
script[property] = null;

nativeSetter.call(script, void 0);
strictEqual(nativeGetter.call(script), expectedValueForNull);

var expectedValueForUndefined = nativeGetter.call(script);
nativeSetter.call(script, void 0);

script[property] = void 0;
var expectedValueForUndefined = nativeGetter.call(script);

strictEqual(nativeGetter.call(script), expectedValueForUndefined);
script[property] = void 0;

script[property] = scriptWithImport;
strictEqual(nativeGetter.call(script), expectedValueForUndefined);

strictEqual(nativeGetter.call(script).replace(/\s/g, ''), processedScriptWithImport);
script[property] = scriptWithImport;

strictEqual(nativeGetter.call(script).replace(/\s/g, ''), processedScriptWithImport);
});
});
});
}

test('style.<innerHTML/innerText/textContent>', function () {
var style = document.createElement('style');
Expand Down
2 changes: 1 addition & 1 deletion test/server/data/cache/expected-script.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 0ffecaa

Please sign in to comment.