Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exclude test files from compilation but include for plugin processing #605

Closed
ernieturner opened this issue May 4, 2017 · 3 comments
Closed

Comments

@ernieturner
Copy link

My tsconfig file currently looks like this

{
    "compilerOptions": {
        "alwaysStrict": true,
        "noImplicitAny": true,
        "noImplicitThis": true,
        "strictNullChecks": true,
        "noUnusedParameters": true,
        "noEmitOnError": true,
        "noUnusedLocals": true,
        "declaration": false,
        "target": "es2015",
        "baseUrl": ".",
        "paths": {
            "*": [
                "src/*"
            ]
        },
        "moduleResolution": "node",
        "lib": ["es6", "dom"]
    },
    "exclude": [
        "node_modules",
        "dist",
        "**/tests/*.test.ts",
        "src/tests"
    ]
}

And my code is setup where my unit test files are located in a tests directory as a sibling of the source file, e.g.

/lib
   /tests
      Utils.test.ts
  Utils.ts

When I compile my code the current setup works find and ignores all unit test files during compilation. However, when I open the unit test files in Sublime with this configuration it can't find any of the global types that it should find from jasmine/karma/etc.

screen shot 2017-05-04 at 3 31 09 pm

If I remove the unit test file from the exclude list in tsconfig, then it all starts working again.

Is there a way to exclude files from TS compilation but still have the plugin process them correctly?

@billti
Copy link
Member

billti commented May 5, 2017

You will need a separate tsconfig.json that includes your test files along with the necessary compiler options and files to build the appropriate context. They are excluded in the above project, so TypeScript will effectively treat them as standalone files when opened.

@fossecode
Copy link

It the problem only applies for jest, you can add this to your jest config:

"jest": {
    "testPathIgnorePatterns": [
      "<rootDir>/build/",
      "<rootDir>/node_modules/"
    ]
}

@AverageHelper
Copy link

For more info on working with multiple tsconfig.json files, see this StackOverflow answer. Basically you'd make use of the "extends" field so as to not duplicate your compiler options overmuch.

You may need to change how you run tsc just a tad:

tsc --project tsconfig.production.json # or whatever you call your other tsconfig

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants