Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Exclude file from compilation during karma test runs

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.

enter image description here

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

like image 835
mindparse Avatar asked Nov 26 '18 15:11

mindparse


1 Answers

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"
    ]
like image 135
rguerin Avatar answered Oct 18 '22 21:10

rguerin