Skip to content

Commit

Permalink
minor fixups / filename changes
Browse files Browse the repository at this point in the history
squashed commits:

rename instrument-index to build-self-coverage (more accurate description)

add leading `.` to self_coverage output directory

minor fixups to npm scripts

fix `npm run report` - it was using the old coverage folder name

move built tests to test/build/, originals sources to test/src

fix test script
  • Loading branch information
jamestalmage committed Dec 14, 2015
1 parent b4cc1e6 commit 3eb8cbf
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 34 deletions.
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
coverage
node_modules
!node_modules/spawn-wrap
test/built-*
self_coverage
test/build/
.self_coverage
*.covered.js
File renamed without changes.
9 changes: 6 additions & 3 deletions build-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,18 @@
var fs = require('fs')
var path = require('path')
var del = require('del')
var mkdirp = require('mkdirp')
var forkingTap = require('forking-tap')
var zeroFill = require('zero-fill')
var sanitizeFilename = require('sanitize-filename')

// Delete previous files.
process.chdir(__dirname)
del.sync(['test/built-*'])
del.sync(['test/build'])
mkdirp.sync(path.join(__dirname, 'test/build'))

var testDir = path.join(__dirname, 'test')
var testDir = path.join(__dirname, 'test/src')
var buildDir = path.join(__dirname, 'test/build')
var originalTestsFilename = path.join(testDir, 'nyc-test.js')
var originalTestSource = fs.readFileSync(originalTestsFilename, 'utf8')
var individualTests = forkingTap(originalTestSource, {
Expand All @@ -33,5 +36,5 @@ individualTests.forEach(function (test, i) {
// remove any illegal chars
filename = sanitizeFilename(filename)

fs.writeFileSync(path.join(testDir, filename), test.code)
fs.writeFileSync(path.join(buildDir, filename), test.code)
})
2 changes: 1 addition & 1 deletion lib/self-coverage-helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ onExit(function () {
if (typeof ___nyc_self_coverage___ === 'object') coverage = ___nyc_self_coverage___
if (!coverage) return

var selfCoverageDir = path.join(__dirname, '../self_coverage')
var selfCoverageDir = path.join(__dirname, '../.self_coverage')
mkdirp.sync(selfCoverageDir)
fs.writeFileSync(
path.join(selfCoverageDir, process.pid + '.json'),
Expand Down
16 changes: 8 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
"description": "a code coverage tool that works well with subprocesses.",
"main": "index.js",
"scripts": {
"clean": "rm -rf ./.nyc_output && rm -rf ./test/fixtures/.nyc_output && rm -f ./index.covered.js ./lib/source-map-cache.covered.js && rm -rf ./self_coverage",
"build": "node ./build-tests",
"pretest": "standard",
"test": "npm run cover",
"clean": "rm -rf ./.nyc_output ./.self_coverage ./test/fixtures/.nyc_output ./test/build && rm -f *covered.js ./lib/*covered.js",
"build": "node ./build-tests",
"instrument": "node ./build-self-coverage.js",
"run-tests": "tap -b ./test/build/*.js ./test/src/source-map-cache.js",
"report": "istanbul report --include=./.self_coverage/*.json lcov text",
"cover": "npm run clean && npm run build && npm run instrument && npm run run-tests && npm run report",
"dev": "npm run clean && npm run build && npm run run-tests",
"instrument": "node ./instrument-index.js",
"report": "istanbul report --include=self_coverage/*.json lcov text",
"run-tests": "tap -b ./test/built-*.js ./test/source-map-cache.js"
"dev": "npm run clean && npm run build && npm run run-tests"
},
"bin": {
"nyc": "./bin/nyc.js"
Expand All @@ -24,7 +24,7 @@
"bin",
"coverage",
"test/fixtures/coverage.js",
"test/built-*",
"test/build/*",
"test/nyc-test.js",
"test/source-map-cache.js",
"index.covered.js",
Expand All @@ -35,7 +35,7 @@
"standard": {
"ignore": [
"**/fixtures/**",
"**/test/built-*"
"**/test/build/*"
]
},
"keywords": [
Expand Down
28 changes: 14 additions & 14 deletions test/nyc-test.js → test/src/nyc-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@ var fs = require('fs')
var NYC

try {
NYC = require('../index.covered.js')
NYC = require('../../index.covered.js')
} catch (e) {
NYC = require('../')
NYC = require('../../')
}

var path = require('path')
var rimraf = require('rimraf')
var sinon = require('sinon')
var spawn = require('child_process').spawn
var fixtures = path.resolve(__dirname, './fixtures')
var bin = path.resolve(__dirname, '../bin/nyc')
var fixtures = path.resolve(__dirname, '../fixtures')
var bin = path.resolve(__dirname, '../../bin/nyc')

require('chai').should()
require('tap').mochaGlobals()
Expand All @@ -25,7 +25,7 @@ describe('nyc', function () {
describe('cwd', function () {
function afterEach () {
delete process.env.NYC_CWD
rimraf.sync(path.resolve(fixtures, './nyc_output'))
rimraf.sync(path.resolve(fixtures, '../nyc_output'))
}

it('sets cwd to process.cwd() if no environment variable is set', function () {
Expand All @@ -36,19 +36,19 @@ describe('nyc', function () {
})

it('uses NYC_CWD environment variable for cwd if it is set', function () {
process.env.NYC_CWD = path.resolve(__dirname, './fixtures')
process.env.NYC_CWD = path.resolve(__dirname, '../fixtures')

var nyc = new NYC()

nyc.cwd.should.equal(path.resolve(__dirname, './fixtures'))
nyc.cwd.should.equal(path.resolve(__dirname, '../fixtures'))
afterEach()
})
})

describe('config', function () {
it("loads 'exclude' patterns from package.json", function () {
var nyc = new NYC({
cwd: path.resolve(__dirname, './fixtures')
cwd: path.resolve(__dirname, '../fixtures')
})

nyc.exclude.length.should.eql(5)
Expand Down Expand Up @@ -115,7 +115,7 @@ describe('nyc', function () {
})
var shouldInstrumentFile = nyc.shouldInstrumentFile.bind(nyc)

var relPath = '../../nyc/node_modules/glob/glob.js'
var relPath = '../../../nyc/node_modules/glob/glob.js'
var fullPath = '/Users/user/nyc/node_modules/glob/glob.js'

shouldInstrumentFile(fullPath, relPath).should.equal(false)
Expand Down Expand Up @@ -152,11 +152,11 @@ describe('nyc', function () {

// clear the module cache so that
// we pull index.js in again and wrap it.
var name = require.resolve('../')
var name = require.resolve('../../')
delete require.cache[name]

// when we require index.js it should be wrapped.
var index = require('../')
var index = require('../../')
index.should.match(/__cov_/)
})

Expand All @@ -173,14 +173,14 @@ describe('nyc', function () {

// clear the module cache so that
// we pull index.js in again and wrap it.
var name = require.resolve('../')
var name = require.resolve('../../')
delete require.cache[name]

// install the custom require hook
require.extensions['.js'] = hook

// when we require index.js it should be wrapped.
var index = require('../')
var index = require('../../')
index.should.match(/__cov_/)

// and the hook should have been called
Expand Down Expand Up @@ -430,7 +430,7 @@ describe('nyc', function () {
var nyc = (new NYC({
cwd: fixtures
})).wrap()
require('./fixtures/not-loaded')
require('../fixtures/not-loaded')

nyc.writeCoverageFile()
var reports = _.filter(nyc._loadReports(), function (report) {
Expand Down
12 changes: 6 additions & 6 deletions test/source-map-cache.js → test/src/source-map-cache.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ var covered = _.mapValues({
return _.assign({
// Coverage for the fixture is stored relative to the root directory. Here
// compute the path to the fixture file relative to the root directory.
relpath: './' + path.relative(path.join(__dirname, '..'), fixture.file),
relpath: './' + path.relative(path.join(__dirname, '../..'), fixture.file),
// the sourcemap itself remaps the path.
mappedPath: './' + path.relative(path.join(__dirname, '..'), fixture.sourceFile),
mappedPath: './' + path.relative(path.join(__dirname, '../..'), fixture.sourceFile),
// Compute the number of lines in the original source, excluding any line
// break at the end of the file.
maxLine: fixture.sourceContentSync().trimRight().split(/\r?\n/).length
Expand All @@ -25,18 +25,18 @@ var covered = _.mapValues({

var SourceMapCache
try {
SourceMapCache = require('../lib/source-map-cache.covered.js')
require('../lib/self-coverage-helper.js')
SourceMapCache = require('../../lib/source-map-cache.covered.js')
require('../../lib/self-coverage-helper.js')
} catch (e) {
SourceMapCache = require('../lib/source-map-cache')
SourceMapCache = require('../../lib/source-map-cache')
}

var sourceMapCache = new SourceMapCache()
_.forOwn(covered, function (fixture) {
sourceMapCache.add(fixture.relpath, fixture.contentSync())
})

var coverage = require('./fixtures/coverage')
var coverage = require('../fixtures/coverage')
var fixture = covered.inline

require('chai').should()
Expand Down

0 comments on commit 3eb8cbf

Please sign in to comment.