werpu / jsfs_js_ts

Apache License 2.0
2 stars 1 forks source link

html unit error reported #27

Closed werpu closed 1 year ago

werpu commented 1 year ago

This is mostly an investigation issue. We have a reported HTMLUnit error. This most likely stems from the fact that we have a "modern" browser baseline now, and HTMLUnit might be lacking in some areas or the library which was producing that error was using an outdatet HTMLUnit version. This issue is for now only for documentation whether the problem persists in current html unit versions, it wont produce very likely any fixes (the verdict is still open on that)

werpu commented 1 year ago

HTMLUninit indeed breaks on the compiled es2015 code delivered by the typescript compiler. It is not a dom inconsitency but a bug in the embedded rhino engine as it seems (does it embed the engine? or does it come from the jdk?) Exception class=[net.sourceforge.htmlunit.corejs.javascript.EvaluatorException] com.gargoylesoftware.htmlunit.ScriptException: missing ) after formal parameters (http://localhost:8080/IntegrationJSTest/jakarta.faces.resource/jsf.js_next_gen/dist/window/faces-development.js.jsf;jsessionid=CE3E00AD8F78A0440CC74251A94FB7AB?ln=node_modules#72)

I will try a recompile towards a lower ecmascript version maybe this fixes it! The Javascript File coming out of the typescript compiler definitely is fine and does not have any errors.

werpu commented 1 year ago

Ok the ecmascript level is indeed the issue. I now have moved down to es5, and now I am getting an error com.gargoylesoftware.htmlunit.ScriptException: identifier is a reserved word: class

in the code class _LangUtils {

So the Rhino used definitely is not on es2015 level but on es5 level.

Found references: https://mozilla.github.io/rhino/compat/engines.html

So es2015 is not supported for whatever reasons in rhino properly for now.

werpu commented 1 year ago

Apparently Rhino does not support ES2015, which is the base javascript engine for HTMLUnit. https://mozilla.github.io/rhino/compat/engines.html

I got a more meaningful error by moving down to ES5 and then HTMLUnit broke on my external testing framework telling me that the keyword class is not allowed (explicit class declarations were introduced in ES2015 as alternative to prototype based classes)

So one fix could be that we move our code down to es5, the other one would be to check whether the testing framework can use something differently then Rhino (Nashorn was introduced as alternative in the JDK afair because it was further advanced than Rhino in its ecmascript support).

werpu commented 1 year ago

Found the issue, apparently html unit bundles Mozilla Rhino and the bundled version or any version (still not fully done with my research on that yet) does not support Ecmascript 2015 syntax. After compiling the files down to es5 I get a more meaningful error in my internal testing framework that the keyword class (explicit classes were introduced in es2015) is not allowed. I checked on Mozillas side and found this: https://mozilla.github.io/rhino/compat/engines.html

There are two possible fixes to move forward a) We can return to an ES5 compile target, which is rather pointless given the apis we use, and might run into compatibility issues with html unit anyway (we use FormData elements XhrObject, querySelectorAll etc... which are APIs which might not exist on ES5 level browser implementations) But nevertheless it is worth a shot, but my hopes are somewhat limited.

b) You guys can have a look to get the unit tests out of this ES5 level maybe move the tests to selenium where you can use different drivers or move to a client side testing framework. I know this is a little but much to ask. But as it seems HTMLUnit for now as testrunner seems to be a dead end as long as it uses Rhino and/or Rhino does not move forward.

A viable option for a testing with a more recent engine would be to use Selenium Webdrivers with headless chrome (you need to have a chrome instance preinstalled in the testing environment though)

https://gist.github.com/werpu/5f212b8c6ee8864cbfdceec8bbff226b

Gives you the idea how to pull this off.

And the configuration for it would be: https://gist.github.com/werpu/94f4a74007ac6efae9561e111e216b42

So you get the idea...

Basically the same as html unit but with chrome as engine (headless) or firefox etc... in non headless mode.

This then can be combined by the usual means into tests. Just to sum it up outside of having a browser engine in pure java and maybe having the need to check for explicity es5 compatibility for legacy reasons, there is no advantage in using HTMLUnit, you still can use it as a webdriver in such a setup, but then you will get all downsides the same way we did by calling it directly.

For now need to fix anything on the code side, it probably really is a matter of changing the test engine slightly to get things rolling again. I do not see any reason to move the code back to ES5 for stated reasons.