lukeed / uvu

uvu is an extremely fast and lightweight test runner for Node.js and the browser
MIT License
2.96k stars 102 forks source link

How to debug? #88

Open gionapaolini opened 3 years ago

gionapaolini commented 3 years ago

Maybe it's a stupid question but how can you debug the tests? Is there a test-adapter available?

lukeed commented 3 years ago

Hi, sorry, not entirely sure what you're asking. You should be using .only modifier to isolate tests, and you can always console.log values from within your tests.

gionapaolini commented 3 years ago

I was wondering if there is a test adapter to easily run the tests in debug mode and put breakpoints, something similar to https://marketplace.visualstudio.com/items?itemName=firsttris.vscode-jest-runner

benmccann commented 3 years ago

Here's the documentation for .only: https://github.com/lukeed/uvu/blob/master/docs/api.uvu.md#suiteonlyname-callback

It took me a very long time to find. I was trying to figure out how to run a single test suite and did not think it was possible because I was looking in the cli docs for something like mocha's grep option (https://github.com/lukeed/uvu/issues/74) and the CLI docs suggested you could comment out all the tests you don't want to run and don't mention .only at all: https://github.com/lukeed/uvu/blob/master/docs/cli.md#isolation

maxmilton commented 3 years ago

It is possible to debug with breakpoints and var inspection etc. using VS Code's debugger.

In your project create a .vscode/launch.json file with something like:

// https://code.visualstudio.com/docs/editor/debugging#_launch-configurations
{
  "version": "0.2.0",
  "configurations": [
    // based on https://github.com/Microsoft/vscode-recipes/tree/master/debugging-jest-tests
    {
      "name": "uvu All",
      "type": "pwa-node",
      "request": "launch",
      "skipFiles": ["<node_internals>/**"],
      "program": "${workspaceFolder}/node_modules/.bin/uvu",
      "args": ["-r", "esbuild-register", "./test", "\\.test\\.ts$"],
      "console": "integratedTerminal",
      "windows": {
        "program": "${workspaceFolder}/node_modules/uvu/bin.js"
      }
    },
    {
      "name": "uvu Current File",
      "type": "pwa-node",
      "request": "launch",
      "skipFiles": ["<node_internals>/**"],
      "args": ["-r", "esbuild-register", "${relativeFile}"],
      "console": "integratedTerminal"
    }
  ]
}

I also have esbuild-register as a dependency so I can write my tests in TypeScript. The above assumes your tests are in test/*.test.ts.

bentaber commented 2 years ago

@gionapaolini maybe many months too late, but this seems to work, assuming you are running within vscode integrated terminal... or are using chrome debug tools.

node --inspect ./node_modules/.bin/uvu ./tests/

Kamrulhasan12345 commented 2 years ago

I use this way: image