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

ts-jest inconsistently ignores "include" in tsconfig.json #618

Closed
qwertie opened this issue Jul 16, 2018 · 1 comment
Closed

ts-jest inconsistently ignores "include" in tsconfig.json #618

qwertie opened this issue Jul 16, 2018 · 1 comment

Comments

@qwertie
Copy link

qwertie commented Jul 16, 2018

Normally ts-jest is unaffected by the "include" option in tsconfig.json. In my case I use "include": ["src/*.ts", "src/*.tsx"] so that when I run tsc it does not produce .js files in my tests folder (if I allow tsc to produce .js files of my tests then I would have to reconfigure Jest to ignore them.)

Expected behavior

ts-jest should always ignore "include", but it breaks if "include" doesn't include any files.

Why does this matter? There is a tool (by me) called testpack-cli to check whether your npm package is valid before you publish it. This tool generates a test folder based on your existing tests and your existing tsconfig.json. It installs the packaged version of your package and runs your tests against that. Consequently the src folder no longer exists, so "include": ["src/*.ts", "src/*.tsx"] refers to an empty set.

Minimal repo that reproduces this issue

Create the "repo" with the following commands:

mkdir temp
cd temp
echo test('',function(){}); >my.test.ts
echo {"include":["nonexist.ts"]} > tsconfig.json
echo {"name":"x","version":"1.0.0","jest":{"transform":{"^.+\\.tsx?$":"ts-jest"},"testRegex":"test\\.(jsx?|tsx?)$","moduleFileExtensions":["ts","js"]}} > package.json
npm install jest ts-jest typescript
"./node_modules/.bin/jest"

Result:

  Error: Some errors occurred while attempting to read from C:\Dev\temp\tsconfig.json: error TS18003: No inputs were found in config file 'tsconfig.json'. Specified 'include' paths were '["nonexist.ts"]' and 'exclude' paths were '[]'.
  at readCompilerOptions (node_modules/ts-jest/src/utils.ts:42:11)
  at Object.getTSConfig_local (node_modules/ts-jest/src/utils.ts:128:18)
  at Object.memoized [as getTSConfig] (node_modules/lodash/lodash.js:10551:27)
  at getCacheKey (node_modules/ts-jest/src/preprocessor.ts:91:20)
  at Object.getCacheKey (node_modules/ts-jest/index.js:8:51)

Output from your debug log

No <your_project_dir>/node_modules/ts-jest/debug.txt file was created.

@huafu
Copy link
Collaborator

huafu commented Jul 24, 2018

this is typescript config loader bailing, so you'll need to use a different tsconfig file extending yours. You can define a specific tsconfig within the jest config like that:

{
  ...
  "globals": {
    "ts-jest": {"tsConfigFile": "tsconfig.test.json"}
  }
}

wataruoguchi added a commit to wataruoguchi/zubora that referenced this issue Jan 28, 2020
- [ts-jest inconsistently ignores "include" in tsconfig.json](kulshekhar/ts-jest#618)
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

3 participants