Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

the combination of #73 and #66 broke tests on master #76

Merged
merged 1 commit into from
Dec 6, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,16 @@ function NYC (opts) {
}

NYC.prototype._loadAdditionalModules = function () {
require.main.paths.push(path.resolve(this.cwd, '/node_modules'))
var _this = this
this.require.forEach(function (r) {
require(r)
try {
// first attempt to require the module relative to
// the directory being instrumented.
require(path.resolve(_this.cwd, './node_modules', r))
} catch (e) {
// now try other locations, .e.g, the nyc node_modules folder.
require(r)
}
})
}

Expand Down
26 changes: 14 additions & 12 deletions test/source-map-cache.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ var fixture = require('source-map-fixtures').inline('branching')
// Coverage for the fixture is stored relative to the root directory. Here
// compute the path to the fixture file relative to the root directory.
var relpath = './' + path.relative(path.join(__dirname, '..'), fixture.file)
// the sourcemap itself remaps the path.
var mappedPath = './' + path.join(path.dirname(relpath), '../src/branching.js')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll see if I can add this to to the fixture object instead.

// Compute the number of lines in the original source, excluding any line break
// at the end of the file.
var maxLine = fixture.sourceContentSync().trimRight().split(/\r?\n/).length
Expand All @@ -24,15 +26,15 @@ describe('source-map-cache', function () {
describe('statements', function () {
it('drops statements that have no mapping back to the original source code', function () {
var mappedCoverage = sourceMapCache.applySourceMaps(coverage)
Object.keys(mappedCoverage[relpath].s)
Object.keys(mappedCoverage[mappedPath].s)
.should.be.lt(coverage[relpath].s)
Object.keys(mappedCoverage[relpath].statementMap).length
.should.equal(Object.keys(mappedCoverage[relpath].s).length)
Object.keys(mappedCoverage[mappedPath].statementMap).length
.should.equal(Object.keys(mappedCoverage[mappedPath].s).length)
})

it('maps all statements back to their original loc', function () {
var mappedCoverage = sourceMapCache.applySourceMaps(coverage)
var statements = _.values(mappedCoverage[relpath].statementMap)
var statements = _.values(mappedCoverage[mappedPath].statementMap)
var maxStatement = _.max(statements, function (s) {
return Math.max(s.start.line, s.end.line)
})
Expand All @@ -43,15 +45,15 @@ describe('source-map-cache', function () {
describe('functions', function () {
it('drops functions that have no mapping back to the original source code', function () {
var mappedCoverage = sourceMapCache.applySourceMaps(coverage)
Object.keys(mappedCoverage[relpath].f)
Object.keys(mappedCoverage[mappedPath].f)
.should.be.lt(coverage[relpath].f)
Object.keys(mappedCoverage[relpath].fnMap).length
.should.equal(Object.keys(mappedCoverage[relpath].f).length)
Object.keys(mappedCoverage[mappedPath].fnMap).length
.should.equal(Object.keys(mappedCoverage[mappedPath].f).length)
})

it('maps all functions back to their original loc', function () {
var mappedCoverage = sourceMapCache.applySourceMaps(coverage)
var functions = _.values(mappedCoverage[relpath].fnMap)
var functions = _.values(mappedCoverage[mappedPath].fnMap)
var maxFunction = _.max(functions, function (f) {
return f.line
})
Expand All @@ -62,15 +64,15 @@ describe('source-map-cache', function () {
describe('branches', function () {
it('drops branches that have no mapping back to the original source code', function () {
var mappedCoverage = sourceMapCache.applySourceMaps(coverage)
Object.keys(mappedCoverage[relpath].b)
Object.keys(mappedCoverage[mappedPath].b)
.should.be.lt(coverage[relpath].b)
Object.keys(mappedCoverage[relpath].branchMap).length
.should.equal(Object.keys(mappedCoverage[relpath].b).length)
Object.keys(mappedCoverage[mappedPath].branchMap).length
.should.equal(Object.keys(mappedCoverage[mappedPath].b).length)
})

it('maps all branches back to their original loc', function () {
var mappedCoverage = sourceMapCache.applySourceMaps(coverage)
var branches = _.values(mappedCoverage[relpath].branchMap)
var branches = _.values(mappedCoverage[mappedPath].branchMap)
var maxBranch = _.max(branches, function (b) {
return b.line
})
Expand Down