Skip to content

Commit

Permalink
Address review issues
Browse files Browse the repository at this point in the history
All changed, so all this does now is propagate `cwd` so that it can influence `testExclude` and `require` path settings.
  • Loading branch information
Andrew Finlay committed Mar 19, 2019
1 parent 9822a8b commit c454b56
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 47 deletions.
11 changes: 5 additions & 6 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,15 +179,15 @@ NYC.prototype.addAllFiles = function () {
NYC.prototype.instrumentAllFiles = function (input, output, cb) {
let inputDir = '.' + path.sep
const visitor = filename => {
const inFile = path.resolve(this.cwd, inputDir, filename)
const inFile = path.resolve(inputDir, filename)
const inCode = fs.readFileSync(inFile, 'utf-8')

const extname = path.extname(filename).toLowerCase()
const transform = this.transforms[extname] || (code => code)
const outCode = transform(inCode, { filename: inFile })

if (output) {
const outFile = path.resolve(this.cwd, output, filename)
const outFile = path.resolve(output, filename)
mkdirp.sync(path.dirname(outFile))
fs.writeFileSync(outFile, outCode, 'utf-8')
} else {
Expand All @@ -198,11 +198,10 @@ NYC.prototype.instrumentAllFiles = function (input, output, cb) {
this._loadAdditionalModules()

try {
const inputPath = path.resolve(this.cwd, input)
const stats = fs.lstatSync(inputPath)
const stats = fs.lstatSync(input)
if (stats.isDirectory()) {
inputDir = inputPath
this.walkAllFiles(inputPath, visitor)
inputDir = input
this.walkAllFiles(input, visitor)
} else {
visitor(input)
}
Expand Down
5 changes: 0 additions & 5 deletions lib/commands/instrument.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ exports.command = 'instrument <input> [output]'
exports.describe = 'instruments a file or a directory tree and writes the instrumented code to the desired output location'

exports.builder = function (yargs) {
const cwd = process.cwd()
return yargs
.option('require', {
alias: 'i',
Expand All @@ -29,10 +28,6 @@ exports.builder = function (yargs) {
type: 'boolean',
description: "should nyc's instrumenter produce source maps?"
})
.option('cwd', {
describe: 'working directory used when resolving paths',
default: cwd
})
.option('compact', {
default: true,
type: 'boolean',
Expand Down
36 changes: 0 additions & 36 deletions test/nyc-integration.js
Original file line number Diff line number Diff line change
Expand Up @@ -606,42 +606,6 @@ describe('the nyc cli', function () {
})
})

it('works with a different working directory', function (done) {
const subdir = path.resolve(fixturesCLI, 'subdir')
const args = [bin, 'instrument', '--cwd', subdir, './input-dir', './output-dir']

const proc = spawn(process.execPath, args, {
cwd: fixturesCLI,
env: env
})

proc.on('exit', code => {
code.should.equal(0)
const target = path.resolve(subdir, 'output-dir', 'index.js')
fs.readFileSync(target, 'utf8')
.should.match(/console.log\('Hello, World!'\)/)
done()
})
})

it('works with a deep folder structure working directory', function (done) {
const subdir = path.resolve(fixturesCLI, 'subdir')
const args = [bin, 'instrument', '--cwd', subdir, '.', './output-dir']

const proc = spawn(process.execPath, args, {
cwd: fixturesCLI,
env: env
})

proc.on('exit', code => {
code.should.equal(0)
const target = path.resolve(subdir, 'output-dir', 'input-dir', 'index.js')
fs.readFileSync(target, 'utf8')
.should.match(/console.log\('Hello, World!'\)/)
done()
})
})

it('can be configured to exit on error', function (done) {
var args = [
bin,
Expand Down

0 comments on commit c454b56

Please sign in to comment.