Skip to content

Commit

Permalink
Merge pull request #194 from bcoe/fix-189
Browse files Browse the repository at this point in the history
hot-fix for --all
  • Loading branch information
bcoe committed Mar 14, 2016
2 parents 9ce65e7 + e5e9139 commit 4a15488
Show file tree
Hide file tree
Showing 10 changed files with 52 additions and 20 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
## Change Log

### v6.1.1 (2016/03/13 14:23 +7:00)

- [#194](https://github.com/bcoe/nyc/pull/194) hot-fix for --all with multiple extensions (@bcoe)

### v6.1.0 (2016/03/12 15:00 +7:00)

- [#191](https://github.com/bcoe/nyc/pull/191) upgrade to non-singleton verison of yargs (@bcoe)
Expand Down
8 changes: 7 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,13 @@ NYC.prototype.addAllFiles = function () {

this._loadAdditionalModules()

var pattern = '**/*{' + this.extensions.join() + '}'
var pattern = null
if (this.extensions.length === 1) {
pattern = '**/*' + this.extensions[0]
} else {
pattern = '**/*{' + this.extensions.join() + '}'
}

glob.sync(pattern, {cwd: this.cwd, nodir: true, ignore: this.exclude}).forEach(function (filename) {
var obj = _this.addFile(path.join(_this.cwd, filename))
if (obj.instrument) {
Expand Down
File renamed without changes.
File renamed without changes.
7 changes: 7 additions & 0 deletions test/fixtures/conf-multiple-extensions/check-instrumented.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
function probe () {}

// When instrumented there will be references to variables like
// __cov_pwkoI2PYHp3LJXkn_erl1Q in the probe() source.
module.exports = function () {
return /\b__cov_\B/.test(probe + '')
}
File renamed without changes.
2 changes: 2 additions & 0 deletions test/fixtures/conf-multiple-extensions/not-loaded.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
var i = 3 + 5
i++
17 changes: 17 additions & 0 deletions test/fixtures/conf-multiple-extensions/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"name": "nyc",
"version": "1.1.1",
"description": "forking code-coverage using istanbul.",
"main": "index.js",
"bin": {
"nyc": "./bin/nyc.js",
"nyc-report": "./bin/nyc-report.js"
},
"nyc": {
"exclude": [
"**/blarg",
"**/blerg"
],
"extension": [".es6", ".foo.BAR"]
}
}
3 changes: 1 addition & 2 deletions test/fixtures/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
"exclude": [
"**/blarg",
"**/blerg"
],
"extension": [".es6", ".foo.BAR"]
]
}
}
31 changes: 14 additions & 17 deletions test/src/nyc-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,19 @@ function NYC (opts) {

var path = require('path')
var existsSync = require('exists-sync')
var glob = require('glob')
var rimraf = require('rimraf')
var sinon = require('sinon')
var isWindows = require('is-windows')()
var spawn = require('child_process').spawn
var fixtures = path.resolve(__dirname, '../fixtures')
var projectDir = path.resolve(__dirname, '../..')
var projectTempDir = path.join(projectDir, '.nyc_output')
var projectCacheDir = path.join(projectDir, 'node_modules', '.cache', 'nyc')
var fixtureTempDir = path.join(fixtures, '.nyc_output')
var fixtureCacheDir = path.join(fixtures, 'node_modules', '.cache', 'nyc')
var bin = path.resolve(__dirname, '../../bin/nyc')

// beforeEach
rimraf.sync(projectTempDir)
rimraf.sync(fixtureTempDir)
rimraf.sync(projectCacheDir)
rimraf.sync(fixtureCacheDir)
glob.sync('**/*/{.nyc_output,.cache}').forEach(function (path) {
rimraf.sync(path)
})

delete process.env.NYC_CWD

require('chai').should()
Expand Down Expand Up @@ -78,7 +74,7 @@ describe('nyc', function () {

it("loads 'extension' patterns from package.json#nyc", function () {
var nyc = new NYC({
cwd: path.resolve(__dirname, '../fixtures')
cwd: path.resolve(__dirname, '../fixtures/conf-multiple-extensions')
})

nyc.extensions.length.should.eql(3)
Expand Down Expand Up @@ -235,7 +231,7 @@ describe('nyc', function () {
describe('compile handlers for custom extensions are assigned', function () {
it('assigns a function to custom extensions', function () {
var nyc = new NYC({
cwd: path.resolve(__dirname, '../fixtures')
cwd: path.resolve(__dirname, '../fixtures/conf-multiple-extensions')
})
nyc.reset()
nyc.wrap()
Expand All @@ -252,16 +248,16 @@ describe('nyc', function () {
require('istanbul')

var nyc = new NYC({
cwd: path.resolve(__dirname, '../fixtures')
cwd: path.resolve(__dirname, '../fixtures/conf-multiple-extensions')
})

sinon.spy(nyc, '_handleJs')

nyc.reset()
nyc.wrap()

var check1 = require('../fixtures/check-instrumented.es6')
var check2 = require('../fixtures/check-instrumented.foo.bar')
var check1 = require('../fixtures/conf-multiple-extensions/check-instrumented.es6')
var check2 = require('../fixtures/conf-multiple-extensions/check-instrumented.foo.bar')
check1().should.be.true
check2().should.be.true
nyc._handleJs.callCount.should.equal(2)
Expand Down Expand Up @@ -545,14 +541,15 @@ describe('nyc', function () {
})

it('outputs an empty coverage report for multiple configured extensions', function (done) {
var cwd = path.resolve(fixtures, './conf-multiple-extensions')
var nyc = new NYC({
cwd: fixtures
cwd: cwd
})
nyc.reset()
nyc.addAllFiles()

var notLoadedPath1 = path.join(fixtures, './not-loaded.es6')
var notLoadedPath2 = path.join(fixtures, './not-loaded.js')
var notLoadedPath1 = path.join(cwd, './not-loaded.es6')
var notLoadedPath2 = path.join(cwd, './not-loaded.js')
var reports = _.filter(nyc._loadReports(), function (report) {
var apr = ap(report)
return apr[notLoadedPath1] || apr[notLoadedPath2]
Expand Down

0 comments on commit 4a15488

Please sign in to comment.