Skip to content

Can not run and debug tests with AVA in VSCode. Typescript, ESM modules, with aliases (absolute paths) working. #55

Closed
@korulis

Description

@korulis
  • What you're trying to do:

I am trying to create a Typescript project with Ava testing where I could debug the code while tests are running. My setup used to just work (as described here) when I was using commonjs modules, but after switching to esm I can not get it to work. I have spent hours and days looking for the right configuration and/or workaround for that.
This is my current setup (master branch on repo) after switching to esm modules.

  • What happened

Adding breakpoints and running the app yarn start correctly stops at breakpoints, but when running yarn test it does not stop at breakpoints.

  • What you expected to happen

I was expecting the execution to stop at breakpoints in app.ts and test.test.ts files

What Iv'e tried so far:

  • Using esm-module-alias to create custom loader. This fixes the issue of alias paths in generated .js files, and allows debugging in vscode both with "start": "rm -rf dist && NODE_ENV=development tsx watch ./src/app/index.ts", and "build_and_start_ema": "tsc && node --loader=./dist/app/alias.js ./dist/app/index.js", commands. It also allows running ava tests with "test": "NODE_OPTIONS='--import=tsx' ava --config unittest.js", ,but does not allow debuging. (on master branch)
  • Using tsconfig-paths to fix aliased import paths in generated javascript - this does not even allow running the app after build phase. (on master branch)
  • Using ts-patch to fix aliased import paths in generated javascript - this does not allow running tests at all. See repo branch.
  • Using '' this allows running the tests but not debugging them, and only after running command "build_tsca": "tsc --project tsconfig.json && tsc-alias -p tsconfig.json", , which means I can not run tests continuously using yarn test --watch . See repo branch.

Overall my best attempts were attempt 1 and 4, but attempt 1 is better because it allows running tests continuously.

How can I achieve being able to continously run and debug ava tests in vscode on a typescript project with ESM modules that uses aliased import paths, like it used to when I was using commonjs modules?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions