Is it possible to exclude all test files only for the build but use them with nodemon to run tests locally? When I exclude test files within the tsconfig.json
file I get a typescript error that it can't find the types of the testing library like jest in my case.
Cannot find name 'describe'. Do you need to install type definitions for a test runner? Try `npm i @types/jest` or `npm i @types/mocha`.ts(2582)
{
"compilerOptions": {},
"exclude": [
"**/*.test.ts"
]
}
I am wondering since I guess the temporary transpiling is put into another folder than the build folder.
Use // @ts-ignore to ignore the type checking errors on the next line in a TypeScript file. If you use a linter, you might have to add a comment to also suppress linting errors when using ts-ignore - // eslint-disable-next-line @typescript-eslint/ban-ts-comment .
Use the exclude option in your tsconfig. json file to exclude a folder from compilation in TypeScript. The exclude option changes what the include setting finds and defaults to node_modules and bower_components .
The tsconfig.json file specifies the root files and the compiler options required to compile the project. JavaScript projects can use a jsconfig.json file instead, which acts almost the same but has some JavaScript-related compiler flags enabled by default.
The include and exclude properties take a list of glob-like file patterns. The supported glob wildcards are: * matches zero or more characters (excluding directory separators) ? matches any one character (excluding directory separators)
One possible solution would be to use two different tsconfig files, one for the tests and one for the production build.
tsconfig.json
{
"compilerOptions": {
"module": "commonjs",
"target": "es6",
"outDir": "./build",
"baseUrl": ".",
"paths": {
"*": ["types/*"]
},
"strict": true,
}
}
tsconfig.prod.json
{
"extends": "./tsconfig",
"exclude": ["**/*.test.ts", "**/*.mock.ts"]
}
Then point tsc to the new config when running tsc -p tsconfig.prod.json
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With