5

The error message I am getting is:

File 'd:/Project/server/jest.config.ts' is not under 'rootDir' 
'd:/Project/server/src'. 'rootDir' is expected to contain all source files.
The file is in the program because:
Matched by include pattern '**/*' in 'd:/Project/server/tsconfig.json'

My tsconfig.json file is:

{
 "compilerOptions": {
    "target": "es2020",
    "module": "commonjs",

    "rootDir": "./src",
    "outDir": "./dist",
    "esModuleInterop": true,
    "forceConsistentCasingInFileNames": true,
    "strict": true,
    "skipLibCheck": true
  }
}

My jest.config.ts file is:

export default {
    clearMocks: true,
    collectCoverage: true,
    coverageDirectory: "coverage",
    coverageProvider: "v8",
    transform: {
        "^.+\\.(t|j)sx?$": ["@swc/jest"],
    },
};

I am trying to exactly follow the directives of each documentation.

What am I doing wrong here?

2 Answers 2

2

For future reference, another possible solution would be to simply change

"rootDir": "./src",

to

"rootDir": "./",

in the tsconfig.json file.

Especially if you don't want to move all your configuration files into the src/ directory.

Sign up to request clarification or add additional context in comments.

Comments

1

You have to move your jest.config.ts file inside your src/ directory in order to work. The error is self explanatory I would say.

2 Comments

Yes, you are right. I tried to do that, but the problem persisted because I did not Reload Window in VSCode. After the window reloaded, this solution worked.
Nice. Angular has hot reload anyways, so i dont know why you had to reaload the page manually

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.