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

Replacement of <rootDir> happens too late #153

Closed
arabull opened this issue Dec 10, 2020 · 4 comments
Closed

Replacement of <rootDir> happens too late #153

arabull opened this issue Dec 10, 2020 · 4 comments

Comments

@arabull
Copy link

arabull commented Dec 10, 2020

The final output location is determined using the following logic:

  const outputName = (options.uniqueOutputName === 'true') ? getOptions.getUniqueOutputName() : options.outputName
  const output = path.join(options.outputDirectory, outputName);
  const finalOutput = getOptions.replaceRootDirInOutput(jestRootDir, output);

Unfortunately, the call to path.join() scrubs <rootDir> from the outputDirectory, so any path that uses that syntax ends up incorrect.

Tweaking the order to replace <rootDir> first solves the problem:

  const outputName = (options.uniqueOutputName === 'true') ? getOptions.getUniqueOutputName() : options.outputName
  const output = getOptions.replaceRootDirInOutput(jestRootDir, options.outputDirectory);
  const finalOutput = path.join(output, outputName);
@palmerj3
Copy link
Collaborator

Nice catch!

Could you submit a PR to fix this and include a test case that makes sure rootDir isn't stripped out?

@arabull
Copy link
Author

arabull commented Dec 10, 2020

Yep, working on it now. Will hopefully have something later today.

@arabull
Copy link
Author

arabull commented Dec 10, 2020

There is more nuance here than what I originally reported. The problem is actually when the outputDirectory looks like <rootDir>/../some/dir. In that case, path.join() assumes the .. cancels out the <rootDir>, which seems entirely reasonable. Unfortunately, it means the final value is some/dir, and that ends up rooted at process.cwd(), which doesn't always match <rootDir>.

In our case, our Jest root directory isn't at the root of the project, but we want the final report to end up in the root. That's why we're using that pattern.

The fix suggested above works and is the correct fix, but I wanted to provide a little more detail for what's going on. It was a bit unfair to blame path.join(). It's just doing what it thinks is right.

@taitruong
Copy link

I just found this bug after spending too much time why outputDirectory: "<rootDir>/../../packages" is not working :(. The workaround is not using rootDir: outputDirectory: "../../packages".

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