grafana / k6

A modern load testing tool, using Go and JavaScript - https://k6.io
GNU Affero General Public License v3.0
26.1k stars 1.27k forks source link

Interop from ClojureScript doesn't seem to work since v0.53 #4050

Open trueneu opened 1 week ago

trueneu commented 1 week ago

Brief summary

Starting from k6 v0.53, it is not possible to call any http methods from ClojureScript for no obvious reason. It seems that imports stopped working correctly.

k6 version

v0.53, v0.54

OS

Ubuntu 22.04

Docker version and image (if applicable)

No response

Steps to reproduce the problem

I am using shadow-cljs to compile ClojureScript with the following relevant configuration:

            :target           :esm
            :js-options       {:keep-as-import #{"k6" "k6/http" "k6/crypto" "k6/encoding"}}
            :modules          {:main {:exports {default k6-test.core/default
                                                options k6-test.core/options
                                                setup   k6-test.core/setup}}}
            :compiler-options {:optimizations      :advanced
                               :output-feature-set :es5}}

Then, I import k6/http (the results are the same):

(:require ["k6/http" :as http])
_or_
(:require ["k6/http$default" :as http])

k6 v0.52 will make an http call if I do

(http/get url)

However, starting from v0.53, it complains there's no such method.

If I do (js/Object.keys http), with v0.52 everything's fine:

["TLS_1_0","TLS_1_1","TLS_1_2","TLS_1_3","OCSP_STATUS_GOOD","OCSP_STATUS_REVOKED","OCSP_STATUS_SERVER_FAILED","OCSP_STATUS_UNKNOWN","OCSP_REASON_UNSPECIFIED","OCSP_REASON_KEY_COMPROMISE","OCSP_REASON_CA_COMPROMISE","OCSP_REASON_AFFILIATION_CHANGED","OCSP_REASON_SUPERSEDED","OCSP_REASON_CESSATION_OF_OPERATION","OCSP_REASON_CERTIFICATE_HOLD","OCSP_REASON_REMOVE_FROM_CRL","OCSP_REASON_PRIVILEGE_WITHDRAWN","OCSP_REASON_AA_COMPROMISE","url","CookieJar","cookieJar","file","get","head","post","put","patch","del","options","request","asyncRequest","batch","setResponseCallback","expectedStatuses","default"]

With v0.53 onwards, it's either an empty array (regular require), or this ($default require):

TypeError: Cannot convert undefined or null to object
        at keys (native)

If I perform the same from TypeScript code, everything's fine with the new version.

Basically, imports from ClojureScript don't work anymore. All things given, I assume this is a regression from v0.52 behaviour.

Could something change in the runtime ESM support that breaks this between the v0.52 and v0.53? I see CJS/ESM related breaking changes listed for v0.53, but I don't quite understand from the description how they are related.

Thomas Heller, the author of shadow-cljs, was kind to provide his expertise and has debugged it with me, but he also has no idea why this doesn't work as the code emitted by shadow-cljs should work if ESM is implemented correctly by the runtime.

Expected behaviour

k6/http is imported correctly and all the methods are callable.

Actual behaviour

TypeError: Object has no member 'get'
- [ ] https://github.com/grafana/k6/pull/4058
- [ ] added to release notes (with credits)
ankur22 commented 1 week ago

Hi @trueneu,

Thanks for opening an issue. To help us replicate the issue, could you provide us with a working script that works in v0.52 and doesn't work in v0.53 of k6?

trueneu commented 1 week ago

@ankur22 Sure thing, I'll have to spend some time to put together a minimal example with an instruction. If I upload it to a separate GitHub repo would that work for you?

Or do you want a compiled JS without the source?

trueneu commented 1 week ago

@ankur22 , anyways, here's a repo with an example and a README to reproduce: https://github.com/trueneu/k6-bug

trueneu commented 6 days ago

@ankur22 FWIW, I tried running against k6 built from your branch and it works, thank you very much! :)

We can close this now and reopen if it resurfaces for any reason, or close it after a new k6 version is released, whatever works.

ankur22 commented 4 days ago

Great news, @trueneu! Thanks for being proactive and checking against your own scripts 😄 🎉 The fix will make it into the next release, so you should be able to work with that instead of a custom build once that has been released.