const path = require('path');
const getOptions = require('./getOptions');

module.exports = (options, jestRootDir)  => {
  // Override outputName and outputDirectory with outputFile if outputFile is defined
  let output = options.outputFile;
  if (!output) {
    // Set output to use new outputDirectory and fallback on original output
    const outputName = (options.uniqueOutputName === 'true') ? getOptions.getUniqueOutputName() : options.outputName
    output = path.join(options.outputDirectory, outputName);  
  }
  
  const finalOutput = getOptions.replaceRootDirInOutput(jestRootDir, output);
  return finalOutput;
};

const path = require('path');
const getOptions = require('./getOptions');

module.exports = (options, jestRootDir)  => {
  // Override outputName and outputDirectory with outputFile if outputFile is defined
  let output = options.outputFile;
  if (!output) {
    // Set output to use new outputDirectory and fallback on original output
    const outputName = (options.uniqueOutputName === 'true') ? getOptions.getUniqueOutputName() : options.outputName
    output = getOptions.replaceRootDirInOutput(jestRootDir, options.outputDirectory);
    const finalOutput = path.join(output, outputName);
    return finalOutput;
  }
  
  const finalOutput = getOptions.replaceRootDirInOutput(jestRootDir, output);
  return finalOutput;
};

Replace <rootDir> prior to path.join().
Replace <rootDir> prior to path.join().

This allows outputDirectory to be formatted 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>.

Handling the <rootDir> replacement first allevaites this problem.
