Skip to content

Commit

Permalink
drop lodash from index.js
Browse files Browse the repository at this point in the history
Dropped AVA test suite coverage penalty from 5 seconds to 4 seconds
  • Loading branch information
jamestalmage committed Dec 18, 2015
1 parent 9b014bb commit 1343d4a
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 11 deletions.
24 changes: 16 additions & 8 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/* global __coverage__ */
var _ = require('lodash')
var fs = require('fs')
var glob = require('glob')
var micromatch = require('micromatch')
Expand All @@ -13,6 +12,7 @@ var resolveFrom = require('resolve-from')
var md5 = require('md5-hex')
var arrify = require('arrify')
var convertSourceMap = require('convert-source-map')
var endsWith = require('ends-with')

/* istanbul ignore next */
if (/index\.covered\.js$/.test(__filename)) {
Expand Down Expand Up @@ -83,16 +83,24 @@ NYC.prototype._createInstrumenter = function () {
NYC.prototype._prepGlobPatterns = function (patterns) {
if (!patterns) return patterns

var directories = []
patterns = _.map(patterns, function (pattern) {
var result = []

function add (pattern) {
if (result.indexOf(pattern) === -1) {
result.push(pattern)
}
}

patterns.forEach(function (pattern) {
// Allow gitignore style of directory exclusion
if (!_.endsWith(pattern, '/**')) {
directories.push(pattern.replace(/\/$/, '').concat('/**'))
if (!endsWith(pattern, '/**')) {
add(pattern.replace(/\/$/, '').concat('/**'))
}

return pattern
add(pattern)
})
return _.union(patterns, directories)

return result
}

NYC.prototype.addFile = function (filename) {
Expand Down Expand Up @@ -242,7 +250,7 @@ NYC.prototype._loadReports = function () {

var cacheDir = _this.cacheDirectory()

return _.map(files, function (f) {
return files.map(function (f) {
var report
try {
report = JSON.parse(fs.readFileSync(
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
"append-transform": "^0.2.0",
"arrify": "^1.0.1",
"convert-source-map": "^1.1.2",
"ends-with": "^0.2.0",
"foreground-child": "^1.3.0",
"glob": "^5.0.14",
"istanbul": "^0.4.1",
Expand Down
6 changes: 3 additions & 3 deletions test/src/nyc-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,11 @@ describe('nyc', function () {
var result = _prepGlobPatterns(['./foo', 'bar/**', 'baz/'])

result.should.deep.equal([
'./foo/**', // Appended `/**`
'./foo',
'bar/**',
'baz/',
'./foo/**', // Appended `/**`
'baz/**' // Removed trailing slash before appending `/**`
'baz/**', // Removed trailing slash before appending `/**`
'baz/'
])
})
})
Expand Down

0 comments on commit 1343d4a

Please sign in to comment.