Ava: Enable debugging of AVA based test in TypeScript application using VS Code

Created on 8 Sep 2020  路  9Comments  路  Source: avajs/ava

I was trying to debug typescript tests from Visual Studio Code, but I received error saying "Test files must be run with the AVA CLI". It would be nice to have possibility to set breakpoints directly in the typescript test files, what seems not possible at this point. I managed to configure ava to transpile typescript files and run the tests from command line, nevertheless I am interested in having debugging experience provided by VS Code.

I also tried the AVA Test Explorer extensions for VS Code, but it seem not to support Typescript.

I would like to ask, if there is some way how to enable debugging of tests when using ava in combination with Typescript.

question

All 9 comments

I use https://github.com/avajs/typescript. It works great with debug terminals.

Beyond that you need to create a launch configuration.

I also tried the AVA Test Explorer extensions for VS Code, but it seem not to support Typescript.

That's a third-party plugin so I can't help you with that 馃槃

Thank you for quick response. Unfortunately I am seeing this error when trying to run tests:

PathToProject\node_modules\.bin\ava.CMD PathToProject\tests\my.test.ts --inspect-brk=18225 

  脳 Couldn't find any files to test

  脳 Internal error
  Error: Cannot apply enhancement-only precompilation, possible bad usage: PathToProject\tests\my.test.ts
  Error: Cannot apply enhancement-only precompilation, possible bad usage: PathToProject\tests\my.test.ts
      at Object.precompileEnhancementsOnly.options.extensions.enhancementsOnly.length.filename [as precompileEnhancementsOnly] (PathToProject\node_modules\ava\lib\api.js:298:12)
      at precompilation.map.reduce (PathToProject\node_modules\ava\lib\api.js:204:21)
      at Array.reduce (<anonymous>)
      at Api.run (PathToProject\node_modules\ava\lib\api.js:198:34)
      at process._tickCallback (internal/process/next_tick.js:68:7)

Nevertheless if I run command from terminal: PathToProject\node_modules.bin\ava.CMD PathToProject\tests\my.test.ts --inspect-brk=18225 It works and test is executed.

Could you share your AVA version and configuration?

Ava configuration in package.json

"ava":{
   "typescript":{
      "extensions":[
         "ts",
         "tsx"
      ],
      "rewritePaths":{
         "tests/":"out/"
      }
   },
   "compileEnhancements":false,
   "extensions":[
      "ts"
   ],
   "require":[
      "ts-node/register"
   ]
}

version:
"ava": "^2.4.0",
"@ava/typescript": "^1.1.1",

Thanks.

You're not using the latest version. Try with AVA 3 instead, and remove the top-level compileEnhancements & extensions configuration. Ideally you should try to avoid ts-node/register as well since it adds a lot of overhead, but right now you're only rewriting imports of tests/ so you may need to change that configuration.

(I'm closing this issue for housekeeping purposes, but let's keep the conversation going.)

thank you. With changes you proposed error got limited to
脳 Couldn't find any files to test

I suppose I don't have full understanding of rewrite paths

Project directory structure:

tests
-- package.json
-- testfile.test.ts
.vscode
-- launch.json
out
tsconfig.json

Please can you give me bit more guidance on rewrite paths?

How are you invoking AVA?

I'm not immediately sure if the default patterns select your test file. You could try adding "files": ["tests/**/*.test.ts"].

This is my Launch.json file:

    "version": "0.2.0",
    "configurations": [
    {
        "type": "node",
        "request": "launch",
        "name": "Debug AVA test file",
        "runtimeExecutable": "${workspaceFolder}\\tests\\node_modules\\.bin\\ava",
        "runtimeArgs": [
          "${file}"
        ],
        "outputCapture": "std"
    }]

as said it seem to produce correct command, nevertheless it does not work when invoked thru VS Code debug, but works from terminal

I think that ought to work, but I must admit I haven't tried the launch configuration since VSCode made it easier to create a debug terminal.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

carpasse picture carpasse  路  3Comments

OmgImAlexis picture OmgImAlexis  路  3Comments

fleg picture fleg  路  3Comments

leegee picture leegee  路  4Comments

ivogabe picture ivogabe  路  5Comments