Skip to content

Commit

Permalink
rewrite source-map-cache tests
Browse files Browse the repository at this point in the history
Use source-map-fixtures to get a fixture file with an inline source map. Add a
script to generate a coverage report for this specific fixture. Rewrite tests to
use the fixture, without (too much) hardcoding of values.

This will make it easier to upgrade the fixture in the future, as well as
regenerate the coverage report.

It does break the babel tests. Will fix that in the next commit.
  • Loading branch information
novemberborn committed Dec 3, 2015
1 parent 7d1fb6a commit d4c42b3
Show file tree
Hide file tree
Showing 7 changed files with 201 additions and 6,222 deletions.
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
"bin",
"coverage",
"test/nyc-test.js",
"test/source-map-cache.js"
"test/source-map-cache.js",
"test/fixtures/_generateCoverage.js"
]
}
},
Expand Down Expand Up @@ -63,6 +64,7 @@
"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])
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

0 comments on commit d4c42b3

Please sign in to comment.