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

Add the ability to specify a custom tempDirectory #171

Closed
kentcdodds opened this issue Feb 25, 2016 · 5 comments
Closed

Add the ability to specify a custom tempDirectory #171

kentcdodds opened this issue Feb 25, 2016 · 5 comments

Comments

@kentcdodds
Copy link
Member

The NYC constructor already accepts the option. But this needs to be exposed and utilized in the CLI. I almost had things working, but then had to get back to work.

My use case is I have frontend and backend code that's tested separately and I want to be able to track coverage on them separately. So I already specify the --report-dir for them, but to be able to utilize check-coverage, I need to be able to specify a custom tempDirectory.

I had to slightly alter both the bin/nyc.js and bin/wrap.js. Basically this got me most of the way there:

In nyc.js

if (argv._[0] === 'report') {
  // run a report.
  process.env.NYC_CWD = process.cwd()

  report(argv)
} else if (argv._[0] === 'check-coverage') {
  checkCoverage(argv)
} else if (argv._.length) {
  // wrap subprocesses and execute argv[1]
  if (!Array.isArray(argv.require)) argv.require = [argv.require]

  var nyc = (new NYC({
    require: argv.require,
+    tempDirectory: argv.tempDirectory,
  }))
  nyc.reset()

  if (argv.all) nyc.addAllFiles()

  var env = {
    NYC_CWD: process.cwd(),
    NYC_CACHE: argv.cache ? 'enable' : 'disable',
+    NYC_TEMP_DIRECTORY: argv.tempDirectory,
  }
  if (!argv.tempDirectory) {
      throw new Error('no temp directory in nyc')
  }
  if (argv.require.length) {
    env.NYC_REQUIRE = argv.require.join(',')
  }
  sw([wrapper], env)

  foreground(nyc.mungeArgs(argv), function (done) {
    if (argv.checkCoverage) {
      checkCoverage(argv, function (done) {
        if (!argv.silent) report(argv)
        return done()
      })
    } else {
      if (!argv.silent) report(argv)
      return done()
    }
  })
} else {
  // I don't have a clue what you're doing.
  yargs.showHelp()
}

function report (argv) {
  process.env.NYC_CWD = process.cwd()

  ;(new NYC({
    reporter: argv.reporter,
    reportDir: argv.reportDir,
+    tempDirectory: argv.tempDirectory,
  })).report()
}


function checkCoverage (argv, cb) {
+  var tempDirectory = argv.tempDirectory || './.nyc_output'
  foreground(
    process.execPath,
    [
      require.resolve('istanbul/lib/cli'),
      'check-coverage',
      '--lines=' + argv.lines,
      '--functions=' + argv.functions,
      '--branches=' + argv.branches,
      '--statements=' + argv.statements,
-     path.resolve(process.cwd(), './.nyc_output/*.json')
+     path.resolve(process.cwd(), tempDirectory + '/*.json')
    ],
    cb
  )
}

In wrap.js:

;(new NYC({
  require: process.env.NYC_REQUIRE ? process.env.NYC_REQUIRE.split(',') : [],
  enableCache: process.env.NYC_CACHE === 'enable',
+  tempDirectory: process.env.NYC_TEMP_DIRECTORY,
})).wrap()

I think I'm missing something somewhere, but like I said, I've run out of time to work on this. Also want to make sure this is something you want to do :-)

Thanks!

@bcoe
Copy link
Member

bcoe commented Apr 11, 2016

@kentcdodds hey :) where does this stand. Do you want to take a stab at this feature, should we try to encourage someone else to implement this feature

@kentcdodds
Copy link
Member Author

Would be awesome to set it up as a first-timers-only issue 👍 though, I'm not certain I know all that needs to happen for it to be implemented...

@gitgrimbo
Copy link

gitgrimbo commented Sep 22, 2016

This feature would also help me - is it planned to be added?

Hmm, was it already added by

.option('temp-directory', {
on Sep 17, 2016?

@JaKXz
Copy link
Member

JaKXz commented Sep 22, 2016

@gitgrimbo good point - perhaps a PR to document it would close this issue? :)

@bcoe
Copy link
Member

bcoe commented May 14, 2017

@gitgrimbo @kentcdodds doing a bit of cleanup of old issues; passing an alternate --temp-directory should now be supported in all scenarios, feel free to open a new issue if you bump into any bugs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants