Hello guys,
I’m encountering an issue while trying to use the “eventsource” module in Node.js to perform a test using Server-Sent Events (SSE). I’m following the step-by-step guide from k6 modules to create a bundle. The bundle is being created successfully, but when I run the code, I receive the following
error: [0025] TypeError: Cannot read property 'protocol' of undefined
I’m not sure if the error lies in my code or if I’m doing something wrong in the process.
My code:
import EventSource from 'eventsource';
import { check, sleep } from 'k6';
export let options = {
stages: [
{ duration: '30s', target: 1 },
{ duration: '30s', target: 1 },
{ duration: '30s', target: 0 },
],
};
export default function () {
const url = "x";
const es = new EventSource(url);
let event;
const processEvent = e => {
event = e;
es.close();
};
es.addEventListener("open", processEvent);
es.addEventListener("error", processEvent);
sleep(1);
console.log(event);
check(event, { 'is a valid event': (e) => e.type == "open" });
}
the output:
TypeError: Cannot read property 'protocol' of undefined
running at file:///Users/rafael.nascimentoo/Documents/clones/testebundle/example-project/dist/login.bundle.js:2:113336(22)
at call (native)
at file:///Users/rafael.nascimentoo/Documents/clones/testebundle/example-project/dist/login.bundle.js:2:50978(12)
at O (file:///Users/rafael.nascimentoo/Documents/clones/testebundle/example-project/dist/login.bundle.js:2:36222(195))
at h (file:///Users/rafael.nascimentoo/Documents/clones/testebundle/example-project/dist/login.bundle.js:2:38211(88))
at u (file:///Users/rafael.nascimentoo/Documents/clones/testebundle/example-project/dist/login.bundle.js:2:150251(14))
at native executor=ramping-vus scenario=default source=stacktrace
^C
running (0m01.6s), 0/1 VUs, 1778 complete and 1 interrupted iterations
default ✗ [--------------------------------------] 0/1 VUs 0m01.6s/1m30.0s
data_received........: 0 B 0 B/s
data_sent............: 0 B 0 B/s
iteration_duration...: avg=527.51µs min=160.55µs med=317.13µs max=28.16ms p(90)=722.15µs p(95)=1.17ms
iterations...........: 1779 1084.441345/s
vus..................: 1 min=1 max=1
vus_max..............: 1 min=1 max=1
I would appreciate any insights or suggestions to help resolve this issue. Thank you in advance for your assistance!