Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proxy is not able to parse code which contains spread fn(...args) #1336

Closed
damianbaar opened this issue Oct 5, 2017 · 8 comments
Closed
Assignees
Milestone

Comments

@damianbaar
Copy link

Hey!

I've encountered the issue when testcafe is not able to proxy page which contain scrips with not resolved spread operator, this is, if file will contain any expression like fn(...sth) then file is not being downloaded and browser hangs.

Output from console is a bit cryptic and saying.

(node:65577) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): TypeError: First argument must be a string or Buffer
(node:65577) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

actually this error is handled but real reason it is caused by, (where $param.type = RestExpression)

TypeError: ExprGen[$param.type] is not a function
    at generateFunctionParams (/Users/.../node_modules/testcafe-hammerhead/lib/processing/script/tools/esotope.js:610:105)
    at generateFunctionBody (/Users/.../node_modules/testcafe-hammerhead/lib/processing/script/tools/esotope.js:629:5)
    at Object.generateArrowFunctionExpression [as ArrowFunctionExpression] (/Users/.../node_modules/testcafe-hammerhead/lib/processing/script/tools/esotope.js:1014:9)
    at Object.generateAssignmentExpression [as AssignmentExpression] (/Users/.../node_modules/testcafe-hammerhead/lib/processing/script/tools/esotope.js:1004:29)
    at exprToJs (/Users/.../node_modules/testcafe-hammerhead/lib/processing/script/tools/esotope.js:2005:24)
    at Object.generateExpressionStatement [as ExpressionStatement] (/Users/.../node_modules/testcafe-hammerhead/lib/processing/script/tools/esotope.js:1657:22)
    at Object.generateBlockStatement [as BlockStatement] (/Users/.../node_modules/testcafe-hammerhead/lib/processing/script/tools/esotope.js:1490:32)
    at Object.generateIfStatement [as IfStatement] (/Users/.../node_modules/testcafe-hammerhead/lib/processing/script/tools/esotope.js:1861:37)
    at Object.generateBlockStatement [as BlockStatement] (/Users/.../node_modules/testcafe-hammerhead/lib/processing/script/tools/esotope.js:1490:32)
    at generateFunctionBody (/Users/.../node_modules/testcafe-hammerhead/lib/processing/script/tools/esotope.js:643:28)
    at Object.generateArrowFunctionExpression [as ArrowFunctionExpression] (/Users/.../node_modules/testcafe-hammerhead/lib/processing/script/tools/esotope.js:1014:9)
    at Object.generateCallExpression [as CallExpression] (/Users/.../node_modules/testcafe-hammerhead/lib/processing/script/tools/esotope.js:1058:31)
    at exprToJs (/Users/.../node_modules/testcafe-hammerhead/lib/processing/script/tools/esotope.js:2005:24)
    at generateFunctionBody (/Users/.../node_modules/testcafe-hammerhead/lib/processing/script/tools/esotope.js:636:22)
    at Object.generateArrowFunctionExpression [as ArrowFunctionExpression] (/Users/.../node_modules/testcafe-hammerhead/lib/processing/script/tools/esotope.js:1014:9)
    at Object.generateNewExpression [as NewExpression] (/Users/.../node_modules/testcafe-hammerhead/lib/processing/script/tools/esotope.js:1086:35)
    at run (/Users/.../node_modules/testcafe-hammerhead/lib/processing/script/tools/esotope.js:2028:92)
    at generate (/Users/.../node_modules/testcafe-hammerhead/lib/processing/script/tools/esotope.js:2114:12)
    at getCode (/Users/.../node_modules/testcafe-hammerhead/lib/processing/script/index.js:100:38)
    at applyChanges (/Users/.../node_modules/testcafe-hammerhead/lib/processing/script/index.js:159:21)
    at processScript (/Users/.../node_modules/testcafe-hammerhead/lib/processing/script/index.js:188:38)
    at ScriptResourceProcessor.processResource (/Users/.../node_modules/testcafe-hammerhead/lib/processing/resources/script.js:55:57)
    at _callee$ (/Users/.../node_modules/testcafe-hammerhead/lib/processing/resources/index.js:45:51)
    at tryCatch (/Users/.../node_modules/testcafe-hammerhead/node_modules/regenerator-runtime/runtime.js:65:40)
    at Generator.invoke [as _invoke] (/Users/.../node_modules/testcafe-hammerhead/node_modules/regenerator-runtime/runtime.js:299:22)
    at Generator.prototype.(anonymous function) [as next] (/Users/.../node_modules/testcafe-hammerhead/node_modules/regenerator-runtime/runtime.js:117:21)
    at step (/Users/.../node_modules/testcafe-hammerhead/node_modules/babel-runtime/helpers/asyncToGenerator.js:17:30)
    at /Users/.../node_modules/testcafe-hammerhead/node_modules/babel-runtime/helpers/asyncToGenerator.js:28:13

I got two questions here:

  • is there any chance to enable logging to get such issues without step by step debugging?
  • is it hard to enable support for spread? I believe it should be handled by proxy as if someone is running stuff only on chrome and there is no need to resolve spread in chrome since it is handled natively there would be an extra effort around testcafe to make that working - like babel transpiling.
@damianbaar damianbaar changed the title Proxy is not able to parse code which contain spreads fn(...args) Proxy is not able to parse code which contains spread fn(...args) Oct 5, 2017
miherlosev pushed a commit to miherlosev/issue-pages that referenced this issue Oct 5, 2017
@miherlosev
Copy link
Contributor

Unfortunately, I cannot reproduce your issue.
I've created a sample page containing examples from MDN.
Then I ran a simple test :

fixture `Test`
 .page('https://miherlosev.github.io/issue-pages/hammerhead/1336/index.html');
 
test('spread', async t => {
 await t.click('body');
}); 

with TestCafe 0.17.2 and it works fine

image

Could you provide a JavaScript code snippet that leads to the issue?

@damianbaar
Copy link
Author

damianbaar commented Oct 6, 2017

thanks for quick check. yep, it seems that it works, but not sure whether script within html is parsed by your internal AST transpiler which wraps everything by hammerhead, so not sure whether you are running code which is failing.

to be more specific, my page has couple of chunks, like

<script src="a"/>
<script src="b"/>
<script src="c"/>

if any of these scripts contain ... spread, then it does not work - script basically is not being loaded and error above is thrown.
To reproduce this issue correctly try to add script tag with src to pass it through proxy.

EDIT: if you won't be still able to reproduce this issue, will try to provide example over the weekend.

@miherlosev
Copy link
Contributor

I've changed a sample page as you described.
But it still works fine.
So, please provide an example.

P.S. If you can provide a public page on which this issue is reproduced it would be enough.

@joflashstudios
Copy link

We've encountered and consistently reproduced this issue in the particular case where we assign a member to a function:

  • The member lookup must be dynamic by key
  • The function assigned to the member must be a function with a ...rest parameter

Something like this:

let object = {};
let propertyName = "arbitrary";
object[propertyName] = function (...restParameter) {
    //Doesn't matter
}

We've reproduced this issue in this repo, which references the GitHub.io page in this repo, and includes instructions for reproducing the issue.

@miherlosev
Copy link
Contributor

The problem related to esotope library.

var code        = 'obj[prop] = function (...restParameter) {}';
var ast           = acorn.parse(code);
var newCode = esotope.generate(ast);  //throws an error


TypeError: ExprGen[$param.type] is not a function
      at generateFunctionParams (lib\processing\script\tools\esotope.js:610:105)
      at generateFunctionBody (lib\processing\script\tools\esotope.js:629:5)
      at Object.generateFunctionExpression [as FunctionExpression] (lib\processing\script\tools\esotope.js:1205:9)
      at Object.generateCallExpression [as CallExpression] (lib\processing\script\tools\esotope.js:1058:31)

@AlexanderMoskovkin
Copy link
Contributor

The fix is published in [email protected]

@damianbaar
Copy link
Author

great, thanks guys for quick turnaround.

AndreyBelym pushed a commit to AndreyBelym/testcafe-hammerhead that referenced this issue Feb 28, 2019
@lock
Copy link

lock bot commented Mar 28, 2019

This thread has been automatically locked since it is closed and there has not been any recent activity. Please open a new issue for related bugs or feature requests. We recommend you ask TestCafe API, usage and configuration inquiries on StackOverflow.

@lock lock bot added the STATE: Auto-locked Issues that were automatically locked by the Lock bot label Mar 28, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Mar 28, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants