Exclude file from compilation during karma test runs

Discussão em 'Angular' iniciado por mindparse, Novembro 7, 2024.

  1. mindparse

    mindparse Guest

    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.

    [​IMG]

    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

    Continue reading...

Compartilhe esta Página