I am using angular-cli with Karma, and I need to exclude a particular file from being compiled when running unit tests.
The file in question is referenced in the error below, where it cannot be compiled due to a module not being present it relies on.
This file is used by other projects where the module will be present and so compiles fine, its just in this particular project it does not need compilation but still needs to be exported.
My directory structure is as follows:
index.ts
- /src
- /testing
In my index.ts file I have a single export:
export * from './src/core';
TS source files under my testing
folder are getting picked up by the compiler, and I am unsure why as I am not importing any files under this folder in files under my src
folder or anywhere else from what I can tell.
I want to prevent the compiler from picking up my testing folder altogether, but I cannot get it to ignore it.
I am using angular-cli, and in my .angular-cli.json file I have these lines:
"tsconfig": "tsconfig.json",
"testTsconfig": "tsconfig.spec.json"
Both of these files are located under my src
folder, I tried adding some exclude patterns to my tsconfig.spec.json like so:
"exclude": [
"../testing",
"testing"
]
But this made no difference.
I then wondered if karma was definitely using my tsconfig.spec.json file and so I added the following:
karmaTypescriptConfig : {
tsconfig: '.src/tsconfig.spec.json',
}
But again, still no difference is made, my testing folder gets picked up by the compiler when preparing to run my tests.
I am unsure what else to try, I have updated my versions of TypeScript(3.1.6) and Karma(3.1.1) to the latest.
Has anyone got any ideas on what may be going on here?
Thanks
Maybe your path is not enough precise. Could we have your project pseudo tree view ? And especially the path of the file you want to exclude ?
The config file may expect something like this :
"exclude": [
"someFolder/**/o3-test-harness.class.ts"
]
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