Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable debugging of AVA based test in TypeScript application using VS Code #2579

Closed
MarekLani opened this issue Sep 8, 2020 · 9 comments
Closed
Labels

Comments

@MarekLani
Copy link

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.

@MarekLani MarekLani changed the title Enable usage of ava modules while debugging TypeScript application using VS Code Enable debugging of ava based test in Typescript application using VS Code Sep 8, 2020
@novemberborn
Copy link
Member

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 😄

@sindresorhus sindresorhus changed the title Enable debugging of ava based test in Typescript application using VS Code Enable debugging of AVA based test in TypeScript application using VS Code Sep 8, 2020
@MarekLani
Copy link
Author

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.

@novemberborn
Copy link
Member

Could you share your AVA version and configuration?

@MarekLani
Copy link
Author

MarekLani commented Sep 8, 2020

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.

@novemberborn
Copy link
Member

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.)

@MarekLani
Copy link
Author

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?

@novemberborn
Copy link
Member

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"].

@MarekLani
Copy link
Author

MarekLani commented Sep 9, 2020

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

@novemberborn
Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants