DevExpress / testcafe-hammerhead

A powerful web-proxy used as a core for the TestCafe testing framework. :hammer: :smiley:
https://testcafe.io
MIT License
171 stars 161 forks source link

Optional chaining rewriting by Hammerhead causes unhandled exception #2891

Closed bbutel closed 1 year ago

bbutel commented 1 year ago

What is your Scenario?

Following https://github.com/DevExpress/testcafe-hammerhead/issues/2858, I've got a similar issue.

What is the Current behavior?

# e is undefined
e?.myObject[X] ?? 0 # return undeifned with optional chaining
# but hammerhead change that into 
__get$(e?.myObject, X) ?? 0 # here, an exception is raised. 

What is the Expected behavior?

No exception raised.

Here the patch to ugly solve my issue:

diff --git a/node_modules/testcafe-hammerhead/lib/client/hammerhead.js b/node_modules/testcafe-hammerhead/lib/client/hammerhead.js
index 2b7fea5..5e52241 100644
--- a/node_modules/testcafe-hammerhead/lib/client/hammerhead.js
+++ b/node_modules/testcafe-hammerhead/lib/client/hammerhead.js
@@ -4130,6 +4130,7 @@
        directive,
        extra;

+
    var Syntax = {
        AssignmentExpression:     'AssignmentExpression',
        AssignmentPattern:        'AssignmentPattern',
@@ -21486,7 +21487,9 @@
        PropertyAccessorsInstrumentation._propertyGetter = function (owner, propName, optional) {
            if (optional === void 0) { optional = false; }
            if (isNullOrUndefined(owner) && !optional)
-               PropertyAccessorsInstrumentation._error("Cannot read property '".concat(propName, "' of ").concat(inaccessibleTypeToStr(owner)));
+                       // ugly fix for https://github.com/DevExpress/testcafe-hammerhead/issues/2858
+                       return undefined
+             //PropertyAccessorsInstrumentation._error("Cannot read property '".concat(propName, "' of ").concat(inaccessibleTypeToStr(owner)));
            if (typeof propName === 'string' && shouldInstrumentProperty(propName)) {
                if (optional && isNullOrUndefined(owner))
                    return void 0;

What is your public website URL? (or attach your complete example)

see above

What is your TestCafe test code?

see above

Your complete configuration file

No response

Your complete test report

No response

Screenshots

No response

Steps to Reproduce

see above

TestCafe version

2.5

Node.js version

No response

Command-line arguments

not relevant here

Browser name(s) and version(s)

No response

Platform(s) and version(s)

No response

Other

No response

github-actions[bot] commented 1 year ago

Release v31.4.2 addresses this.

github-actions[bot] commented 1 year ago

Release v31.4.3 addresses this.