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

Issues with using a websocket k6 typescript enum type #4540

Open
joffotron opened this issue Feb 12, 2025 · 1 comment
Open

Issues with using a websocket k6 typescript enum type #4540

joffotron opened this issue Feb 12, 2025 · 1 comment
Assignees

Comments

@joffotron
Copy link

Brief summary

Using e.g. the EventName.Open type from the k6/experimental/websockets compiles but can't be run

k6 version

k6 v0.56.0 (go1.23.4, darwin/arm64)

OS

MacOS 15.3

Docker version and image (if applicable)

No response

Steps to reproduce the problem

I have some code that can be summarised thus:

import { EventName, Params, WebSocket } from 'k6/experimental/websockets';
...

const ws = new WebSocket(`${websocketHost}/ocpp/1.6/`, null, params);
ws.addEventListener(EventName.Open, () => {
    console.log('Connected');
}

I can try running it in several ways:

  • k6 run --compatibility-mode=experimental_enhanced src/idle-station.ts
  • k6pack src/idle-station.ts| k6 run -
  • find ./src -type f -name '*.ts' -exec esbuild '{}' --bundle --outbase=src --outdir=dist --external:k6 --format=esm \; then k6 run dist/idle-station.js

Expected behaviour

I expect the code to compile and run the test

Actual behaviour

For all of the above methods, I get this runtime error:

ERRO[0000] TypeError: Cannot read property 'Open' of undefined
        at idle_station_default (file:///Users/joff/src/chargefox/load-testing/dist/idle-station.js:16:33(19))  executor=shared-iterations scenario=default source=stacktrace

To work around this in the meantime -

I can either use the "open" literal in place of the enum:

ws.addEventListener('open', () => {

Although then my IDE complains of TS2345: Argument of type "open" is not assignable to parameter of type EventName

Or I can use a type assertion:

ws.addEventListener(<EventName>'open', () => {

Which isn't ideal either

@Fernando-hub527
Copy link

Hi, I'm starting to contribute to K6 and would like to help with this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants