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

V23: relative path in extends field of tsconfig.json does not work as expected. #636

Closed
Ailrun opened this issue Jul 26, 2018 · 9 comments
Closed
Assignees

Comments

@Ailrun
Copy link

Ailrun commented Jul 26, 2018

  • Issue
    Suppose that we have following directory structure.
project
|- config
   |- jest.config.js
   |- tsconfig.base.json
   |- tsconfig.dev.json
   |- tsconfig.test.json
|- test
   |- test1.ts
   |- tsconfig.json
| - tsconfig.json

And also suppose that tsconfig.dev.json and tsconfig.test.json extend ./tsconfig.base.json, jest.config.js have following content.

module.exports = {
  errorOnDeprecated: true,
  globals: {
    'ts-jest': {
      tsConfigFile: './config/tsconfig.test.json',
    },
  },
  moduleFileExtensions: [
    'js', 'jsx', 'json', 'ts', 'tsx',
  ],
  rootDir: '../',
  testMatch: [
    '<rootDir>/test/**/*.ts',
  ],
  transform: {
    '^.+\\.tsx?$': 'ts-jest',
  },
};

For this case, running tsc -p config/tsconfig.dev.json in project directory works well, but jest --config=./config/jest.config.js does not work with error

Some errors occurred while attempting to read from <project directory>/config/tsconfig.test.json: error TS5058: The specified path does not exist: '<project directory>/tsconfig.base.json'.

IMO, this problem probably came from following line,

path.resolve(rootDir),

which is changed in e5ad58e

  • Expected behavior

tsconfig.test.json reads <project directory>/config/tsconfig.base.json

  • Output from your debug log
    I tried test with TS_JEST_DEBUG="true", but debug.txt file does not generated.

  • Link to a minimal repo that reproduces this issue

  • Optional (but highly recommended) - Configure Travis (or your favorite system) with the minimal repo

This allows potential solutions to be tested against the minimal repo. This saves everyone time and avoids a lot of back and forth.

@huafu
Copy link
Collaborator

huafu commented Jul 26, 2018

Thanks @Ailrun for reporting this. Can you please provide a minimal repo where the issue can be reproduced. It'd save us a lot of time addressing the issue.

@Ailrun
Copy link
Author

Ailrun commented Jul 26, 2018

@Ailrun
Copy link
Author

Ailrun commented Jul 26, 2018

The repo works with ts-jest@^22, and does not work with ts-jest@^23.

  1. npm run build works.
  2. npm test does not work with original package.json(which includes ts-jest@^23)
  3. Modify package.json by npm i -D ts-jest@^22 makes npm test work.

@huafu huafu self-assigned this Jul 26, 2018
@huafu
Copy link
Collaborator

huafu commented Jul 26, 2018

@Ailrun in your repo the path in tsConfigFile should be ./tsconfig.test.json and not ./config/tsconfig.test.json. The . means the path of this file so in jest config file it means config path. But yeah, even with that change, the issue then is that it's trying to resolve the extends in that file from the base of the project instead of from config as it should.

Found the issue and fixing it right now, thanks again!

@huafu
Copy link
Collaborator

huafu commented Jul 26, 2018

Hmmm actually I was wrong. I meant, I'd love to do it so that a . means relatively to where 'tsConfigFile' key is, but jest doesn't provide this information in multi-projects configuration. So the . will remain relatively to rootDir and if it can't find it, there will be a specific message. Anyway, the use of <rootDir> in tsConfigFile key will be possible and then it'll make no doubts about where to find that file.

@donaldpipowitch
Copy link

Hi there! I think I have this problem as well and I don't know if it was fixed?

in tsConfigFile key will be possible

Is this already possible?


Use case: We have a project structure like that. https://github.com/Mercateo/ws
This is a monorepo with multiple packages and each package could potentially have multiple test configs using Jest. Each test directory can have its own Jest config (because they are often configured in different ways).

Example:
Structure: packages/{packageName}/{testDirectory}/jest.config.js
Becomes: packages/cool-component/tests/jest.config.js

Then we call it with $ jest --config tests/jest.config.js. Next to the jest.config.js can be a tsconfig.json.

In v22 I've written ./tsconfig.json and it worked - I got the tsconfig.json next to the jest.config.js. (I think the default value is/ws tsconfig.json which was resolved to packages/{packageName}/tsconfig.json and not packages/{packageName}/{testDirectory}/tsconfig.json.) <rootDir> wasn't respected as far as I can tell.

In v23 my old config breaks and I get the error File not found: ./tsconfig.json (resolved as: /Users/my-name/workspace/ws/packages/example-browser-ts-react-i18n/tsconfig.json) (the tests/ directory before tsconfig.json is missing - props to this nice and readable error message 👍).
When I remove my custom ./tsconfig.json setting a different (or default?) config is used.
What I really need (as far as I can tell) is <rootDir>/tsconfig.json, but this throws as well: File not found: <rootDir>/tsconfig.json (resolved as: /tsconfig.json).

@huafu
Copy link
Collaborator

huafu commented Sep 6, 2018

@donaldpipowitch I'll advise you to come chat on slack about this. I'll be available in a few. Until then, you can try ts-jest beta: #697 if you feel like it.

@donaldpipowitch
Copy link

Thanks, I'll do that. (Also tried the beta already. 👍)

@donaldpipowitch
Copy link

I just made a quick test with 23.10.0-beta.3 and it seems to work. Thank you so much for the quick fix.

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