Tests fail on absolute import/TS path alias #699
Labels
solution: duplicate
This issue or pull request already exists
solution: workaround available
There is a workaround available for this issue
topic: TS Paths Aliases
Related to using aliases with TypeScript paths
Milestone
Current Behavior
npm run test failed because of absolute import path aliases in tested code.
Steps to reproduce the error:
npx tsdx create mylib
(select "react" option)/src/config.ts
with following content:export const a = 1;
3. Import constant "a" in
/src/index.tsx
file. Here is my/src/index.tsx
file content:npm run test
in mylib folderExpected behavior
test shouldn't fail because of absolute paths in scripts in /src folder.
Suggested solution(s)
I know If I replace
import {a} from "config";
withimport {a} from "./config";
then this error will be fixed. But tsconfig.json allows me to use absolute paths. From tsconfig.json:And my IDE automatically adds absolute paths. And absolute paths works if I run
npm run build
ornpm start
. But it doesn't work in testing.Give the opportunity to use absolute paths in tests. Or take away the opportunity to use absolute paths in
/src
folderAdditional context
Your environment
The text was updated successfully, but these errors were encountered: