Organizing Files
In my project, I have structured my files as follows:
functions/lib/src/...src .ts files
functions/lib/test/...test files
functions/tsconfig.json
Initially, including the test files directory in the tsconfig.json.include property allowed linting to work successfully in the test files. However, when running tsc, the test files were also compiled into js.
Upon removing the test directory from the tsconfig.json include property, errors started appearing in the test files related to Jest methods, with messages like:
Cannot find name 'test'. Do you need to install type definitions for a test runner? Try
npm i @types/jest
ornpm i @types/mocha
.
This is how the tsconfig.json appears:
{
"compilerOptions": {
"module": "commonjs",
"noImplicitReturns": true,
"noUnusedLocals": true,
"outDir": "lib",
"sourceMap": true,
"strict": true,
"target": "es2017"
},
"compileOnSave": true,
"include": [
"src",
],
}
And here is the jest.config.js file:
module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
};
How can I ensure that Jest methods are recognized without having the test files compiled?