Skip to content

Commit

Permalink
Modernise code changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrew Finlay committed Feb 20, 2019
1 parent ed4ccd8 commit d5d9b64
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 22 deletions.
20 changes: 8 additions & 12 deletions index.js
Expand Up @@ -243,24 +243,20 @@ NYC.prototype.instrumentAllFiles = function (input, output, cb) {
}

NYC.prototype.walkAllFiles = function (dir, visitor) {
var pattern = null
if (this.extensions.length === 1) {
pattern = '**/*' + this.extensions[0]
} else {
pattern = '**/*{' + this.extensions.join() + '}'
}
const pattern = (this.extensions.length === 1)
? `**/*${this.extensions[0]}`
: `**/*{${this.extensions.join()}}`

var filesToWalk = glob.sync(pattern, { cwd: dir, nodir: true, ignore: this.exclude.exclude })
let filesToWalk = glob.sync(pattern, { cwd: dir, nodir: true, ignore: this.exclude.exclude })

var excludeNegatedPatterns = this.exclude.excludeNegated
excludeNegatedPatterns.forEach(function (pattern) {
// package node-glob no longer observes negated excludes, so we need to restore these files ourselves
const excludeNegatedPaths = this.exclude.excludeNegated
excludeNegatedPaths.forEach(pattern => {
filesToWalk = filesToWalk.concat(glob.sync(pattern, { cwd: dir, nodir: true }))
})
filesToWalk = arrayUniq(filesToWalk)

filesToWalk.forEach(function (filename) {
visitor(filename)
})
filesToWalk.forEach(visitor)
}

NYC.prototype._maybeInstrumentSource = function (code, filename, relFile) {
Expand Down
20 changes: 10 additions & 10 deletions test/nyc-bin.js
Expand Up @@ -103,19 +103,19 @@ describe('the nyc cli', function () {
})

it('should allow negated exclude patterns', function (done) {
var args = [bin, '--all', '--exclude', '**/include-exclude/**', '--exclude', '!**/exclude-negated.js', process.execPath, './half-covered.js']
const args = [bin, '--all', '--exclude', '**/include-exclude/**', '--exclude', '!**/exclude-negated.js', process.execPath, './half-covered.js']

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

var stdout = ''
proc.stdout.on('data', function (chunk) {
let stdout = ''
proc.stdout.on('data', chunk => {
stdout += chunk
})

proc.on('close', function (code) {
proc.on('close', code => {
code.should.equal(0)
stdout.should.not.match(/excluded\.js/)
stdout.should.match(/exclude-negated\.js/)
Expand All @@ -124,19 +124,19 @@ describe('the nyc cli', function () {
})

it('should include \'node_modules\' using exclude patterns', function (done) {
var args = [bin, '--all', '--exclude', '!**/node_modules/**', process.execPath, './half-covered.js']
const args = [bin, '--all', '--exclude', '!**/node_modules/**', process.execPath, './half-covered.js']

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

var stdout = ''
proc.stdout.on('data', function (chunk) {
let stdout = ''
proc.stdout.on('data', chunk => {
stdout += chunk
})

proc.on('close', function (code) {
proc.on('close', code => {
code.should.equal(0)
stdout.should.match(/include-exclude\/node_modules/)
stdout.should.match(/cover-me\.js/)
Expand Down

0 comments on commit d5d9b64

Please sign in to comment.