-
Notifications
You must be signed in to change notification settings - Fork 504
Tests fail on absolute import/TS path alias #699
Copy link
Copy link
Closed
Labels
solution: duplicateThis issue or pull request already existsThis issue or pull request already existssolution: workaround availableThere is a workaround available for this issueThere is a workaround available for this issuetopic: TS Paths AliasesRelated to using aliases with TypeScript pathsRelated to using aliases with TypeScript paths
Description
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)- create some file in /src folder. For example:
/src/config.tswith following content:
export const a = 1;
3. Import constant "a" in /src/index.tsx file. Here is my /src/index.tsx file content:
import * as React from 'react';
import {a} from "config";
// Delete me
export const Thing = () => {
console.log(a);
return <div>the snozzberries taste like snozzberries</div>;
};
Expected 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"; with import {a} from "./config"; then this error will be fixed. But tsconfig.json allows me to use absolute paths. From tsconfig.json:
"paths": {
"*": ["src/*", "node_modules/*"]
},
And my IDE automatically adds absolute paths. And absolute paths works if I run npm run build or npm 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 folder
Additional context
Your environment
| Software | Version(s) |
|---|---|
| TSDX | "^0.13.2" |
| TypeScript | "^3.8.3" |
| Browser | Last Chrome |
| npm/Yarn | npm 6.12.0 |
| Node | v12.13.0 |
| Operating System | Win 10 |
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
solution: duplicateThis issue or pull request already existsThis issue or pull request already existssolution: workaround availableThere is a workaround available for this issueThere is a workaround available for this issuetopic: TS Paths AliasesRelated to using aliases with TypeScript pathsRelated to using aliases with TypeScript paths
