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 assumes it is an immediate dependency of the project being tested #852

Closed
octogonz opened this issue Nov 6, 2018 · 1 comment
Closed

Comments

@octogonz
Copy link

octogonz commented Nov 6, 2018

Issue:

I noticed this warning while running ts-jest:

ts-jest[config] (WARN) Unable to find the root of the project where ts-jest has been installed.

It seems to be coming from this code:

  get projectPackageJson(): Record<string, any> {
    const tsJestRoot = resolve(__dirname, '..', '..')
    let pkgPath = resolve(tsJestRoot, '..', '..', 'package.json')
    let exists = existsSync(pkgPath)
    if (!exists) {
      if (realpathSync(this.rootDir) === realpathSync(tsJestRoot)) {
        pkgPath = resolve(tsJestRoot, 'package.json')
        exists = true
      } else {
        this.logger.warn(Errors.UnableToFindProjectRoot)
      }
    }
    return exists ? require(pkgPath) : {}
  }

Expected behavior:

This logic seems to assume that ts-jest was installed in the node_modules/ts-jest folder as a direct dependency of the project that is being tested. This is not a reliable assumption in general.

For example, we use Jest in a monorepo with hundreds of projects. It would be very cumbersome to add ts-jest and all the other tooling dependencies as a direct dependency of every single project. Instead, we publish a toolchain package that brings along the compiler, test presets, Webpack configuration, etc. Our projects depend on this toolchain package, instead of depending on the tools themselves.

I can simply ignore this warning, however I'm a little concerned that in some cases the check may succeed and load configuration information from the wrong project. (For example, during upgrades we sometimes have multiple versions of our toolchain coexisting side-by-side in the node_modules folder.)

What is ts-jest looking for in the root of the project? Is there a better way to discover this information?

@iclanton

@huafu huafu added the duplicate label Nov 6, 2018
@huafu
Copy link
Collaborator

huafu commented Nov 6, 2018

Thanks @pgonzal, tho I'll close this as it's a duplicate of #823. But your detailed description will be useful when fixing.

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

2 participants