DevExpress / testcafe-hammerhead

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

Accessing private class members got rewritten by Hammerhead causing getting undefined on a defined member #2882

Closed pokai-chang-appier closed 1 year ago

pokai-chang-appier commented 1 year ago

What is your Scenario?

(Similar to https://github.com/DevExpress/testcafe-hammerhead/issues/2858, but with a different JS feature)

We are using private class members in our JavaScript code, such as the following:

class SomeClass {
  #somePrivateAttr = 'hi';

  getPrivateAttr() {
    return this.#somePrivateAttr;
  }
}

const someClass = new SomeClass();
alert('This should be "hi": ' + someClass.getPrivateAttr());

It should show alert This should be “hi”: hi when executed.

However, when proxied via testcafe-hammerhead, the line:

this.#somePrivateAttr

got re-written as:

__get$(this,”somePrivateAttr”)

which will get undefined instead of 'hi'.

What is the Current behavior?

this.#somePrivateAttr got re-written as __get$(this,”somePrivateAttr”) which become undefined.

What is the Expected behavior?

Proxied code should get this.#somePrivateAttr as 'hi' correctly.

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

https://moonlit-kangaroo-fd48ff.netlify.app/index.html

What is your TestCafe test code?

N/A

Your complete configuration file

No response

Your complete test report

No response

Screenshots

No response

Steps to Reproduce

To reproduce, I prepared a simple web page, https://moonlit-kangaroo-fd48ff.netlify.app.

The HTML:

<!-- https://moonlit-kangaroo-fd48ff.netlify.app/index.html -->

<script src="script.js"></script>

JS:

// https://moonlit-kangaroo-fd48ff.netlify.app/script.js

class SomeClass {
  #somePrivateAttr = 'hi';

  getPrivateAttr() {
    return this.#somePrivateAttr;
  }
}

const someClass = new SomeClass();
alert('This should be "hi": ' + someClass.getPrivateAttr());

When opening this page, an alert will pop-up with This should be "hi": hi:

But while opening the page in the Hammerhead playground, as instructed in the README, the message becomes This should be "hi": undefined

TestCafe version

testcafe-hammerhead 44388ee2d226d83c1a67f4bdbed93bd55f97a6b4

Node.js version

v18.15.0

Command-line arguments

N/A

Browser name(s) and version(s)

No response

Platform(s) and version(s)

No response

Other

No response

pokai-chang-appier commented 1 year ago

I was able to workaround this by using --experimental-proxyless.

AlexKamaev commented 1 year ago

We plan to add the fix to testcafe version 2.5.1. While we are preparing it you can try the release candidate version 2.5.1-rc.1 with the fix.

AlexKamaev commented 1 year ago

duplicate of https://github.com/DevExpress/testcafe/issues/7632