K6 jest http mocking

Hi there,

As import http from 'k6/http'; doesn’t actually resolve to a true node_modules module, I’m having issues mocking this and http.asyncRequest.

I’m open to suggestions, I found GitHub - szkiba/xk6-mock: A k6 extension for mocking HTTP(S) servers during test development. but I just want to define an NPM dep.

Why not publish to NPM the k6 libs, yes there’s a downside in scripts potentially bundling and increasing filesize when it’s already part of a runtime but it’d simplify a lot of aspects in writing tests.

Hi @beyaga6767 :wave:

Why not publish to NPM the k6 libs

I’m not entirely sure this will answer your question: the main reason is that most k6 modules are written in Go. k6 does not execute JavaScript using node, but rather its own lightweight JavaScript runtime “Goja”. While some libraries are written in JavaScript, the vast majority is not, and wouldn’t be compatible with node or installable via npm as a result.

Does that answer your question? :bowing_man:


Hi there, thanks for the reply!

It does answer as to why, but I’m wondering if there’s a way to publish something useable so that I can effectively write or mock out unit tests.

Hey @beyaga6767

I’m not very familiar with the whole Node ecosystem myself, and I’m not unfortunately aware of a direct solution to what you’re looking for myself :bowing_man: