ChaiJS import into k6 locally


Saw great opportunity to use describe blocks within K6.

As I am trying to use k6 on a server, I cant be importing it from https:// as in example, I would rather have it locally in codebase.

However If I try to add chaijs directory from github (GitHub - grafana/k6-jslib-k6chaijs: Chai Assertion Library for to mine I get errors which I cant really resolve.

Steps I did:
I tried downloading codebase for chaijs as zip and adding to my workspace and then importing describe block from directory.

Perhaps anyone already has solution for that ?

When I run k6 after importing describe block I get error like this:

   5 |  * Handle assertion grouping the K6 way
   6 |  */
>  7 | export function describe(name: string, fn: (...xs: unknown[]) => unknown) {
     |                              ^
   8 |   let success = true;
   9 | 
  10 |   group(name, () => {
        at <internal/k6/compiler/lib/babel.min.js>:2:28536(105)
        at <internal/k6/compiler/lib/babel.min.js>:14:24413(12)
        at bound  (native)
        at s (<internal/k6/compiler/lib/babel.min.js>:1:1331(8))
        at native  hint="script exception"

Hopefully someone will find this useful.

To use describe from codebase without importing it from the servers.

I had to create 2 files:

index.js content:

ajv.js content:

Imported Ajv from ajv.js into index.js

imported describe from index.js to k6 script :slight_smile:

And Voila! it works :slight_smile:

1 Like