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 162 forks source link

Hammerhead Transformation changes function name to something that is undefined #3030

Open Tonsil opened 2 weeks ago

Tonsil commented 2 weeks ago

What is your Scenario?

I'm working on a module for Prebid.js, and their library code contains the following function (see here)

  static all(promises) {
    return new this((resolve, reject) => {
      let res = [];
      this.#collect(promises, (success, val, i) => success ? res[i] = val : reject(val), () => resolve(res));
    })
  }

What is the Current behavior?

I'm using TestCafe to run a suite of tests using npm run. I am seeing the error: TypeError: this.collect is not a function. The code is transformed from this:

  static all(promises) {
    return new this((resolve, reject) => {
      let res = [];
      this.#collect(promises, (success, val, i) => success ? res[i] = val : reject(val), () => resolve(res));
    })
  }

into this:

  static all(promises) {
    return  new this((resolve,reject)=>{let res=[];this.collect(promises,(success,val,i)=>success?__set$(res,i,val):reject(val),()=>resolve(res));}) ;
  }

The problem is that it's trying to call this.collect instead of this.#collect.

What is the Expected behavior?

The static all function should be calling this.#collect after transformation. Any other references in that file that start with # should be unchanged.

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

N/A

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

N/A

TestCafe version

3.6.2

Node.js version

21.7.3

Command-line arguments

N/A

Browser name(s) and version(s)

No response

Platform(s) and version(s)

No response

Other

This is very similar to https://github.com/DevExpress/testcafe-hammerhead/issues/3012 , but I don't know if it's the same issue. Please consolidate if they do have the same root cause.

github-actions[bot] commented 1 week ago

Thank you for submitting a bug report. We would love to help you investigate the issue. Please share a simple code example that reliably reproduces the bug. For more information, read the following article: How To Create a Minimal Working Example When You Submit an Issue. We look forward to your response.

Tonsil commented 2 days ago

Here's as simple as I can make this. There are 2 files you need to witness the bug.

  1. runner file
    
    var shell = require("shelljs");

const shellCommand = npx testcafe "chrome --auto-open-devtools-for-tabs" ./src/test/javascript/example/ --fixture 'Example' --debug-on-fail -c 1 example --disable-native-automation --page-load-timeout 10 --disable-page-caching --color; console.debug("Command: ", shellCommand); shell.exec(shellCommand); process.exit(0);


2. test file

fixture('Example') .page('http://pupation.com/test_hammerhead.html'); test('My first test', async t => { // Test code goes here await t.debug(); });`

as written, the test file should be in an `example/` directory.

I'm hosting the html and javascript files to make things easier, but I will attach all 4 in case that helps.
[hammerhead_issue_3030.zip](https://github.com/user-attachments/files/17708123/hammerhead_issue_3030.zip)

To see the bug, when you run an `npx` command directly:

npx testcafe "chrome --auto-open-devtools-for-tabs" ./src/test/javascript/example/ --fixture 'Example' --debug-on-fail -c 1 example --disable-native-automation --page-load-timeout 10 --disable-page-caching --color

the test will show in the developer tools console "SUCCESS, #collect is a function". 

When you use an npm runner script:

npm test --prefix=src/test/javascript -- --browser "chrome:headless" --debugOnFail=false --clientConfigEnv=dev --tagEnv=dev --txEnv=dev --concurrency=5 --retriesPerBrowser 1


the test will show in the developer tools console "FAIL, #collect is undefined".