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

Rewrite custom require hook & source map tests #73

Merged
merged 3 commits 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
8 changes: 5 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@
"exclude": [
"node_modules",
"bin",
"coverage"
"coverage",
"test/nyc-test.js",
"test/source-map-cache.js",
"test/fixtures/_generateCoverage.js"
]
}
},
Expand Down Expand Up @@ -57,10 +60,9 @@
"yargs": "^3.15.0"
},
"devDependencies": {
"babel-core": "^6.2.1",
"babel-preset-es2015": "^6.1.18",
"chai": "^3.0.0",
"sinon": "^1.15.3",
"source-map-fixtures": "^0.1.0",
"standard": "^5.2.1",
"tap": "^1.3.4"
},
Expand Down
48 changes: 48 additions & 0 deletions test/fixtures/_generateCoverage.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
'use strict'

// Generates the test/fixtures/coverage.js file, not otherwise used in the
// tests.

var fs = require('fs')
var path = require('path')

var _ = require('lodash')
var rimraf = require('rimraf')

var NYC = require('../../')

// Load the 'branching' source map fixture.
var fixture = require('source-map-fixtures').inline('branching')

// Prevent pollution from earlier nyc runs.
var tempDirectory = path.join(__dirname, '.nyc_output')
rimraf.sync(tempDirectory)

// Inject nyc into this process.
var nyc = (new NYC({
cwd: path.join(__dirname, '..', '..'),
tempDirectory: tempDirectory
})).wrap()
// Override the exclude option, source-map-fixtures is inside node_modules but
// should not be excluded when generating the coverage report.
nyc.exclude = []

// Require the fixture so nyc can instrument it, then run it so there's code
// coverage.
fixture.require().run()

// Write the coverage file so reports can be loaded.
nyc.writeCoverageFile()

var reports = _.values(nyc._loadReports()[0])
Copy link
Member

Choose a reason for hiding this comment

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

this is a great approach for generating the fixtures, and I love the module source-map-fixtures.

if (reports.length !== 1) {
console.error('Expected 1 report to be generated, got ' + reports.length)
process.exit(1)
}

var coverage = reports[0]
fs.writeFileSync(
path.join(__dirname, 'coverage.js'),
'// Generated using node test/fixtures/_generateCoverage.js\n' +
'exports[' + JSON.stringify(coverage.path) + '] = ' + JSON.stringify(coverage, null, 2) + '\n')
console.log('Written coverage report.')
32 changes: 0 additions & 32 deletions test/fixtures/code-with-map.js

This file was deleted.

Loading