I have a folder called "__ tests __".
I want it to be validated as typescript, but I don't want to build that folder. ( I don't want it to go to dist folder )
How would I do that?
It's like I have to include it, but not really...
My ts.config.json:
{
"compilerOptions": {
"module": "CommonJS",
"target": "ES2017",
"noImplicitAny": true,
"preserveConstEnums": true,
"outDir": "./dist",
"sourceMap": true,
"esModuleInterop": true,
"resolveJsonModule": true
},
"include": ["src/**/*", "src/**/*.json", "__tests__/**/*"],
"exclude": ["node_modules", "**/*.spec.ts"]
}
I have a folder called "__ tests __".
I want it to be validated as typescript, but I don't want to build that folder. ( I don't want it to go to dist folder )
How would I do that?
It's like I have to include it, but not really...
My ts.config.json:
{
"compilerOptions": {
"module": "CommonJS",
"target": "ES2017",
"noImplicitAny": true,
"preserveConstEnums": true,
"outDir": "./dist",
"sourceMap": true,
"esModuleInterop": true,
"resolveJsonModule": true
},
"include": ["src/**/*", "src/**/*.json", "__tests__/**/*"],
"exclude": ["node_modules", "**/*.spec.ts"]
}
Share
Improve this question
asked Dec 14, 2020 at 2:32
Djordje NikolicDjordje Nikolic
4331 gold badge7 silver badges14 bronze badges
1 Answer
Reset to default 22You can simply use the option noEmit
in your use case to not emit the output.
{
"compilerOptions": {
// ...
"noEmit": true,
}
}
Update for only emitting in test case
I think you can also go for creating the new configuration for testing files to include
only your test code extending from the current one.
tsconfig.test.json
{
"extends": "./tsconfig.json",
{
"compilerOptions": {
"noEmit": true,
},
"include": [
"__tests__", // your test file
],
}
}
package.json
{
"scripts": {
"build": "tsc",
"test:typeCheck": "tsc --project tsconfig.test.json"
}
}
- Type check your test folder without emitting:
npm run test:typeCheck
- Run build to emit files normally:
npm build