Skip to content

Tests fail on absolute import/TS path alias #699

@ildar-icoosoft

Description

@ildar-icoosoft

Current Behavior

npm run test failed because of absolute import path aliases in tested code.

Steps to reproduce the error:

  1. npx tsdx create mylib (select "react" option)
  2. create some file in /src folder. For example: /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:

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>;
};

  1. run npm run test in mylib folder
  2. You will see failed test:
    tsdx

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions