Search code examples
node.jstypescriptwebpackvisual-studio-codek6

How to debug k6 testing script in Visual Studio Code?


When trying to launch Visual Studio Code in debugging mode, to inspect a k6 testing script, I get the following message:

Uncaught Error: Cannot find module 'k6'.

I'm writing the test scripts in TypeScript and I'm using NodeJS + Webpack + Babel. The .js file I pass to k6 is the bundle file created by Webpack.

My launch.json file looks like this:

"version": "0.2.0",
"configurations": [
    {
        "name": "Launch Program",
        "type": "node",
        "request": "launch",
        "cwd": "${workspaceFolder}",
        "protocol": "inspector",
        "preLaunchTask": "npm: build",
        "program": "${workspaceFolder}/src/Main.ts",
        "outFiles": [
            "${workspaceFolder}/dist/Main.js"
          ],
        "sourceMaps": true
    }
]

I've also added this to the tsconfig.json:

"sourceMap": true

There is this import in my script:

import { Options } from 'k6/options';

Please, can anyone help? How can I configure it so that I can debug k6 testing scripts in Visual Studio Code?


Solution

  • Turns out it is not possible, unfortunately. k6 is not nodejs based and also has no debugger of its own. So there is no way for visual studio code to debug k6 scripts. The error I see is because it tries to run it in nodejs and 'k6' is not a module nodejs recognizes. Console.log is currently the only 'debugger'. I've confirmed it with the k6 community.