0

My Setup

I have a mono repo with jest tests in each package.

My code

Github repo here.

I have distilled my issue in an example package lambda-a which has the following tsconfig.json

{
  "extends": "../../tsconfig.build.json",
  "compilerOptions": {
    "rootDir": "./src",
    "outDir": "./dist",
    "baseUrl": "./",
    "composite": true,
    "paths": {
      "@example/*": ["src/example/*"]
    }
  },
  "include": ["src/**/*"]
}

and the following jest.config.js

/* eslint-disable u/typescript-eslint/no-var-requires */
const base = require('../../jest.config.base.js');
const package = require('./package.json');

module.exports = {
  ...base,
  name: package.name,
  displayName: package.name,
  roots: ['<rootDir>/src'],
  moduleDirectories: ['node_modules', '<rootDir>'],
  moduleNameMapper: {
    '^@example/(.*)$': '<rootDir>/src/example/$1',
    '^scr/(.*)$': '<rootDir>/src/$1',
  },
};

My Problem

For my src *.ts files I can use relative, absolute and alias imports as shown here

For tests I am using *.test.ts files. My problem is that in my tests absolute and alias imports do not work as shown here

Actually the tests run fine. My only issue is the linting errors and the fact that vs code doesn't give me any intelisense for the modules imported absolutely.

How can I get absolute and alias imports to work correctly in my tests?

Thanks :)

Simon Verhoeven
  • 347
  • 4
  • 16
  • I think I found my issue. I was excluding `*.test.ts` in my base tsconfig. I fixed it in my repo. While I'm here if anyone has any feedback on my test setup as a whole. Any constructive criticism I would appreciate it a lot :) – Simon Verhoeven Jan 15 '21 at 10:03
  • Can you share your solution here? The repo seems dead – Alex Ironside Dec 08 '21 at 09:28

0 Answers0