How to exclude files for compilation but include for testing in Typescript?

Viewed 999

File structure

functions/lib/src/...src .ts files
functions/lib/test/...test files
functions/tsconfig.json

When I include test files directory in the tsconfig.json.include property linting works fine in my test files. However when I run tsc the test files are compliled into js.

When I remove the test directory from the tsconfig.json include property i get errors in my test files for all Jest methods like the following:

Cannot find name 'test'. Do you need to install type definitions for a test runner? Try npm i @types/jest or npm i @types/mocha.

tsconfig.json looks as follows

{
  "compilerOptions": {
    "module": "commonjs",
    "noImplicitReturns": true,
    "noUnusedLocals": true,
    "outDir": "lib",
    "sourceMap": true,
    "strict": true,
    "target": "es2017"
  },
  "compileOnSave": true,
  "include": [
    "src",
  ],

}

jest.config.js looks as follows

module.exports = {
  preset: 'ts-jest',
  testEnvironment: 'node',
};

How can I get Jest method recognition and not be stuck with compiling the test files?

0 Answers
Related