From d5d9b64fced4075e111ab060d7c2ad1815220b6c Mon Sep 17 00:00:00 2001 From: Andrew Finlay Date: Wed, 20 Feb 2019 15:35:06 +1100 Subject: [PATCH] Modernise code changes --- index.js | 20 ++++++++------------ test/nyc-bin.js | 20 ++++++++++---------- 2 files changed, 18 insertions(+), 22 deletions(-) diff --git a/index.js b/index.js index 94ae28669..122ed8a12 100755 --- a/index.js +++ b/index.js @@ -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) { diff --git a/test/nyc-bin.js b/test/nyc-bin.js index 03e73a892..3529ee9ba 100644 --- a/test/nyc-bin.js +++ b/test/nyc-bin.js @@ -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/) @@ -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/)