Setting up a typescript compile scope to exclude `__tests__` folder from being compiled doesn't work.

All of my tests are written in typescript. They are stored in the __tests__ folder. I use jest and ts-jest to run the tests so I don't need Webstorm to compile those test scripts into js/jsx for me.

My aims:

1. Exclude  __tests__ and __tests__util from being compiled 

2. Make sure the type_src folder that stores all the main project ts codes are compiled. 

I've found that the only way to get it work is making two settings:

1. Set up a compile scope pattern in `Language > Frameworks > Typescript` to exclude __tests__ and __tests__util recursively and include type_src recursively:

file[web]:type_src//*&&!file[web]:__tests__//*&&!file[web]:__tests__util//*

2. adding__tests__ and __tests__util to the `exclude property` in tsconfig.json

My question is, is it the correct way of excluding those folders from compiling? I thought just setting up the compile scope in Webstorm would work, but I don't understand why  I have to update the tsconfig.json as well.

Folder structure:

-- project
-- __tests__
-- __tests__util
-- node_modules
-- src <<-- js output
-- type_src
-- tsconfig.json
-- package.json

tsconfig.json: 

{

"compilerOptions": {
"module": "commonjs",
"target": "es6",
"moduleResolution": "node",
"allowSyntheticDefaultImports": true,
"noImplicitAny": false,
"experimentalDecorators": true,
"noLib": false,
"declaration": false,
"emitDecoratorMetadata": true,
"lib": ["es6", "dom"],
"types": ["reflect-metadata"],
"inlineSources":true,
"skipLibCheck": true,
"rootDir":"./type_src",
"outDir": "./src",
"jsx": "preserve"
},
"exclude": [
"node_modules",
"__tests__",
"__tests__util"
]

}
4 comments
Comment actions Permalink

No need to specify test patterns... I'd suggest excluding "__tests__" from the root tsconfig.json, adding a separate tsconfig.json to __tests__ folder, with

"compileOnSave": false
0
Comment actions Permalink

Hi Elena,

I have created a ticket https://youtrack.jetbrains.com/issue/WEB-34462 with a demo repository. I can't get it to work. It looks like the WebStorm compiler is stubborn at compiling all of my ts files in __tests__ even though there's a tsconfig that specifies "compileOnSave":false in __tests__

0
Comment actions Permalink

thanks, reproduced

0
Comment actions Permalink

please see the developer's comment in the ticket - you should have excluded __tests__ from the root config per my suggestion in https://intellij-support.jetbrains.com/hc/en-us/community/posts/360000432259/comments/360000100400

0

Please sign in to leave a comment.