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

allow the directory that coverage reports are outputted to to be configured #145

Merged
merged 1 commit into from
Jan 21, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion bin/nyc.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ var yargs = require('yargs')
describe: 'coverage reporter(s) to use',
default: 'text'
})
.option('report-dir', {
describe: 'default directory to output coverage reports in',
default: 'coverage'
})
.help('h')
.alias('h', 'help')
.example('$0 report --reporter=lcov', 'output an HTML lcov report to ./coverage')
Expand Down Expand Up @@ -57,6 +61,10 @@ var yargs = require('yargs')
describe: 'coverage reporter(s) to use',
default: 'text'
})
.option('report-dir', {
describe: 'default directory to output coverage reports in',
default: 'coverage'
})
.option('s', {
alias: 'silent',
default: false,
Expand Down Expand Up @@ -154,7 +162,8 @@ function report (argv) {
process.env.NYC_CWD = process.cwd()

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

Expand Down
3 changes: 2 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ function NYC (opts) {
this._istanbul = opts.istanbul
this.subprocessBin = opts.subprocessBin || path.resolve(__dirname, './bin/nyc.js')
this._tempDirectory = opts.tempDirectory || './.nyc_output'
this._reportDir = opts.reportDir

var config = this._loadConfig(opts)
this.cwd = config.cwd
Expand Down Expand Up @@ -298,7 +299,7 @@ NYC.prototype.report = function (cb, _collector, _reporter) {

var istanbul = this.istanbul()
var collector = _collector || new istanbul.Collector()
var reporter = _reporter || new istanbul.Reporter()
var reporter = _reporter || new istanbul.Reporter(null, this._reportDir)

this._loadReports().forEach(function (report) {
collector.add(report)
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@
"any-path": "^1.3.0",
"chai": "^3.0.0",
"coveralls": "^2.11.4",
"exists-sync": "0.0.3",
"forking-tap": "^0.1.1",
"is-windows": "^0.1.0",
"lodash": "^3.10.0",
Expand Down
24 changes: 24 additions & 0 deletions test/src/nyc-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ function NYC (opts) {
}

var path = require('path')
var existsSync = require('exists-sync')
var rimraf = require('rimraf')
var sinon = require('sinon')
var isWindows = require('is-windows')()
Expand Down Expand Up @@ -350,6 +351,29 @@ describe('nyc', function () {
)
})
})

it('allows coverage report to be output in an alternative directory', function (done) {
var reporters = ['lcov']
var nyc = new NYC({
cwd: process.cwd(),
reporter: reporters,
reportDir: './alternative-report'
})
nyc.reset()

var proc = spawn(process.execPath, ['./test/fixtures/child-1.js'], {
cwd: process.cwd(),
env: process.env,
stdio: 'inherit'
})

proc.on('close', function () {
nyc.report()
existsSync('./alternative-report/lcov.info').should.equal(true)
rimraf.sync('./alternative-report')
return done()
})
})
})

describe('.istanbul.yml configuration', function () {
Expand Down