For my Angular application using angular-cli with Karma, I am facing an issue where a specific file needs to be excluded from compilation during unit tests.
The file causing the problem is mentioned in the error message, indicating that it cannot be compiled due to a missing module dependency.
https://i.sstatic.net/oEzyw.png
Although this file compiles successfully in other projects where the required module is present, in this particular project, it does not require compilation but still needs to be exportable.
My project directory is structured as follows:
index.ts
- /src
- /testing
In my index.ts file, I have a single export statement:
export * from './src/core';
The TypeScript source files within the testing
folder are being compiled, even though I am not importing any files from this folder in the files under my src
folder or anywhere else.
I want to completely exclude the testing folder from the compiler's scope, but my attempts to ignore it have been unsuccessful.
Within my .angular-cli.json file, I have specified the following:
"tsconfig": "tsconfig.json",
"testTsconfig": "tsconfig.spec.json"
Both of these configuration files are located in my src
folder. I tried defining exclude patterns in my tsconfig.spec.json like this:
"exclude": [
"../testing",
"testing"
]
However, this did not solve the issue.
Concerned that Karma might not be utilizing my tsconfig.spec.json file, I added the following:
karmaTypescriptConfig : {
tsconfig: '.src/tsconfig.spec.json',
}
Still, the testing folder continues to be included during test preparation.
I am running the latest versions of TypeScript(3.1.6) and Karma(3.1.1) but am still unable to resolve this issue.
If anyone has any suggestions or insights on what might be causing this problem, I would greatly appreciate it.
Thank you