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

Add source map tests #78

Merged
merged 3 commits into from
Dec 7, 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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
"devDependencies": {
"chai": "^3.0.0",
"sinon": "^1.15.3",
"source-map-fixtures": "^0.1.0",
"source-map-fixtures": "^0.2.0",
"standard": "^5.2.1",
"tap": "^1.3.4"
},
Expand Down
53 changes: 32 additions & 21 deletions test/fixtures/_generateCoverage.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,41 +8,52 @@ var path = require('path')

var _ = require('lodash')
var rimraf = require('rimraf')
var sourceMapFixtures = require('source-map-fixtures')

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)
// Load source map fixtures.
var fixtures = {
bundle: sourceMapFixtures.inline('bundle'),
inline: sourceMapFixtures.inline('branching'),
none: sourceMapFixtures.none('branching')
}

// Inject nyc into this process.
var nyc = (new NYC({
cwd: path.join(__dirname, '..', '..'),
tempDirectory: tempDirectory
cwd: path.join(__dirname, '..', '..')
})).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()
fixtures.bundle.require().branching()
fixtures.inline.require().run()
fixtures.none.require().run()

// Copy NYC#writeCoverageFile() behavior to get the coverage object, before
// source maps have been applied.
var coverage = global.__coverage__
if (typeof __coverage__ === 'object') coverage = __coverage__
if (!coverage) {
console.error('No coverage.')
process.exit(1)
}

var reports = _.values(nyc._loadReports()[0])
if (reports.length !== 1) {
console.error('Expected 1 report to be generated, got ' + reports.length)
var reports = _.values(coverage)
if (reports.length !== 3) {
console.error('Expected 3 reports 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.')
var out = fs.createWriteStream(path.join(__dirname, 'coverage.js'))
out.write('// Generated using node test/fixtures/_generateCoverage.js\n')
reports.forEach(function (coverage) {
out.write('exports[' + JSON.stringify(coverage.path) + '] = ' + JSON.stringify(coverage, null, 2) + '\n')
})
out.end()
out.on('finish', function () {
console.log('Written coverage report.')
})
Loading