Separate src and test folders in TypeScript projects

If I have my code in separate src and test folders then WebStorm (and IDEA) don't seem to pick up the compiler options from my tsconfig file.

I need to have "include": [ "src/**/*"] in tsconfig to stop tsc from copying my test files to the outputDir, but if I run the tests from a shell using "mocha -r ts-node/register --colors --recursive 'test/**/*.test.ts'" then it all works fine, but in WebStorm I get errors complaining about TS2705 (async functions and the lib compiler options, which in my case is set to es6).

 

Any idea how I can configure my project to get rid of the spurious error highlights?

0
2 comments

Don't you think that "WebStorm (and IDEA) don't seem to pick up the compiler options from my tsconfig file." contradicts "I need to have "include": [ "src/**/*"] in tsconfig to stop tsc from copying my test files to the outputDir"? If changing the config changes the behavior, options are definitely picked up, no?

Not sure what configuration is used by ts-node + mocha - it might have its own custom logic/configuration. But built-in compiler service works just in the same way as tsc - it uses the nearest tsconfig.json current file is included in, and follows the rules defined in this config to process it. You can have separate configs to src and test roots if you like...

 

0
Avatar
Permanently deleted user

Hmm, not ideal but I can work with that. The nice thing about the way `ts-node` works is that it doesn't leave any build artefacts on disk as the test files are compiled as they are loaded, but I can work with a separate `tsconfig.json` file in the root of my test folder.

 

Thanks for the speedy response though! 😀

0

Please sign in to leave a comment.