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

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

Closed
korulis opened this issue Nov 22, 2024 · 3 comments

Comments

@korulis
Copy link

korulis commented Nov 22, 2024

  • 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?

@korulis
Copy link
Author

korulis commented Nov 22, 2024

BTW my "flattened" tsconfig in master branch:

> npx tsc --showConfig
{
    "compilerOptions": {
        "lib": [
            "es2022"
        ],
        "module": "nodenext",
        "target": "es2022",
        "strict": true,
        "esModuleInterop": true,
        "skipLibCheck": true,
        "moduleResolution": "nodenext",
        "rootDir": "./src",
        "resolveJsonModule": true,
        "moduleDetection": "force",
        "isolatedModules": true,
        "verbatimModuleSyntax": true,
        "noUncheckedIndexedAccess": true,
        "noImplicitOverride": true,
        "noImplicitReturns": true,
        "noImplicitThis": true,
        "noImplicitAny": true,
        "noUnusedLocals": true,
        "noFallthroughCasesInSwitch": true,
        "strictNullChecks": true,
        "useUnknownInCatchVariables": true,
        "outDir": "./dist",
        "sourceMap": true,
        "baseUrl": "./",
        "paths": {
            "*": [
                "./src/*"
            ]
        },
        "allowSyntheticDefaultImports": true,
        "resolvePackageJsonExports": true,
        "resolvePackageJsonImports": true,
        "preserveConstEnums": true,
        "useDefineForClassFields": true,
        "strictFunctionTypes": true,
        "strictBindCallApply": true,
        "strictPropertyInitialization": true,
        "strictBuiltinIteratorReturn": true,
        "alwaysStrict": true
    },
    "files": [
        "./src/app/alias.ts",
        "./src/app/app.ts",
        "./src/app/app2.ts",
        "./src/app/index.ts",
        "./src/test/unit/test.test.ts",
        "./src/test/unit/test2.test.ts"
    ],
    "include": [
        "src/**/*"
    ],
    "exclude": [
        "node_modules/**/*"
    ]
}

@novemberborn
Copy link
Member

You may have more luck asking in the main Discussions area: https://github.com/avajs/ava/discussions

Personally I try and avoid the complications, and use @ava/typescript with a build process I run separately. But then I also don't use module aliases.

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

@korulis
Copy link
Author

korulis commented Nov 25, 2024

use @ava/typescript with a build process I run separately - yes that would be acceptable to me in the end.. just so I can have that debugging option, however, it seems ,as you have correctly identified, I would need to drop the aliased paths in my code base in order to get that.. at least as it stands right now.

Thanks you for at least reading the post ;) I will try my luck in the main forum.

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

No branches or pull requests

2 participants