Closed bdshadow closed 1 month ago
Hi @bdshadow, I recently found this out and discuss it in https://github.com/grafana/k6/issues/3864 also related to https://github.com/grafana/k6/issues/3860
Can you tell version of k6 you are using and compatibility-mode
?
As mentioned in the first issue this is coming from chaijs and has been fixed for years but a new version hasn't been released so that it works in other places apart from NodeJS.
A workaround will be for you (or here in chaijs) for us to do the globalThis.global = globalThis
so that it can be used.
if you put in global.js
globalThis.global = globalThis;
and then in your file you have
import "./global.js"
import { expect } from "https://jslib.k6.io/k6chaijs/4.3.4.3/index.js"
// rest of your code
That should make it work
@mstoykov thank you for your reply.
First of all, I want to confirm that the described workaround works
Can you tell version of k6 you are using and compatibility-mode ?
We use k6 operator of version v0.0.13, which uses alpine image with the following k6:
/ # k6 version
k6 v0.51.0 (go1.22.4, linux/amd64)
Extensions:
github.com/grafana/xk6-browser v1.6.0, k6/x/browser [js]
github.com/grafana/xk6-browser v1.6.0, k6/x/browser/async [js]
github.com/grafana/xk6-loki v0.0.0-20240621131830-5248b47b4efd, k6/x/loki [js]
github.com/grafana/xk6-output-timescaledb v0.2.1, timescaledb [output]
github.com/szkiba/xk6-chai v0.1.1, k6/x/chai [js]
About compatibility mode:
env:
- name: K6_COMPATIBILITY_MODE
value: "base"
Hi @bdshadow I would expect that given that you use base
you are also transpiling the source code from ECMAScript Modules to CommonJS with babel/webpack/esbuild as v0.51.0 doesn't support ECMAScript Modules in base compatibility mode.
This has finally been implemented but isn't realeased and is under heavy testing in order to be part of v0.53.0 to be released in August.
But base
again will not actually include global
being alias to globalThis
as it is meant to be a pure ECMAScript implementation as possible.
I will try to push the fix through the upstream and see how it goes. But I would expect it will be a while, and I doubt there will be a backport for v4.X of chai given that v5 exists.
I' getting the following error
while running the following test:
The test is run in k8 by using https://github.com/grafana/k6-operator. When version is changed to 4.3.4.1, everything works fine, the problem starts from version 4.3.4.2. Also, everything works fine locally. I also tried to use https://github.com/szkiba/xk6-chai and update the dependency to "k6/x/chai", but it was the same ReferenceError only complaining about k6chaijs.min.js.
I'm a little lost in what theoretically can be the problem and what else can I check.