You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This is a port of a question from @ava/typescript forum as suggested by the author of that package - novemberborn.
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.
(new) Using simply tsc to compile/transpile my typescript into javascript into dist/ folder and then runing with ava without the typescript config (yarn build + yarn test). See commit for this attempt. This does run the tests, but it still does not stop at vscode breakpoints. Why I expected the breakpoints to work in this case? After all, my breakpoints are in .ts files and I am executing strictly only .js files in dist/ folder... - because when I do analogous thing for running the app "build_and_start_ema": "tsc && node --loader=./dist/app/alias.js ./dist/app/index.js", it DOES hit the breakpoints in .ts files even though I am executing only the .js files.
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?
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?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
This is a port of a question from @ava/typescript forum as suggested by the author of that package - novemberborn.
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 toesm
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.Adding breakpoints and running the app
yarn start
correctly stops at breakpoints, but when runningyarn test
it does not stop at breakpoints.I was expecting the execution to stop at breakpoints in
app.ts
andtest.test.ts
filesWhat Iv'e tried so far:
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)tsconfig-paths
to fix aliased import paths in generated javascript - this does not even allow running the app after build phase. (on master branch)ts-patch
to fix aliased import paths in generated javascript - this does not allow running tests at all. See repo branch."build_tsca": "tsc --project tsconfig.json && tsc-alias -p tsconfig.json",
, which means I can not run tests continuously usingyarn test --watch
. See repo branch.tsc
to compile/transpile my typescript into javascript intodist/
folder and then runing with ava without the typescript config (yarn build
+yarn test
). See commit for this attempt. This does run the tests, but it still does not stop at vscode breakpoints. Why I expected the breakpoints to work in this case? After all, my breakpoints are in.ts
files and I am executing strictly only.js
files indist/
folder... - because when I do analogous thing for running the app"build_and_start_ema": "tsc && node --loader=./dist/app/alias.js ./dist/app/index.js",
it DOES hit the breakpoints in.ts
files even though I am executing only the.js
files.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?my "flattened" tsconfig in master branch:
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?
Beta Was this translation helpful? Give feedback.
All reactions