Skip to content

Commit

Permalink
chore: add unit test: addAllFiles should work correctly with non-.js …
Browse files Browse the repository at this point in the history
…files (#335)
  • Loading branch information
rundef authored and bcoe committed Jul 30, 2016
1 parent de1defa commit 109818f
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
5 changes: 5 additions & 0 deletions test/fixtures/transpile-hook.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,8 @@ require.extensions['.js'] = function (module, filename) {
var content = fs.readFileSync(filename, 'utf8');
module._compile(content.replace('--> pork chop sandwiches <--', ''), filename);
}

require.extensions['.whatever'] = function (module, filename) {
var content = fs.readFileSync(filename, 'utf8');
module._compile(content.replace('--> pork chop sandwiches <--', ''), filename);
}
31 changes: 30 additions & 1 deletion test/src/nyc-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ describe('nyc', function () {
return done()
})

it('transpiles files added via addAllFiles', function (done) {
it('transpiles .js files added via addAllFiles', function (done) {
fs.writeFileSync(
'./test/fixtures/needs-transpile.js',
'--> pork chop sandwiches <--\nvar a = 99',
Expand Down Expand Up @@ -440,6 +440,35 @@ describe('nyc', function () {
})
})

it('transpiles non-.js files added via addAllFiles', function (done) {
fs.writeFileSync(
'./test/fixtures/needs-transpile.whatever',
'--> pork chop sandwiches <--\nvar a = 99',
'utf-8'
)

var nyc = (new NYC({
cwd: fixtures,
require: './test/fixtures/transpile-hook',
extension: ['.whatever']
}))

nyc.reset()
nyc.addAllFiles()

var needsTranspilePath = path.join(fixtures, './needs-transpile.whatever')
var reports = _.filter(nyc._loadReports(), function (report) {
return ap(report)[needsTranspilePath]
})
var report = reports[0][needsTranspilePath]

reports.length.should.equal(1)
report.s['1'].should.equal(0)

fs.unlinkSync(needsTranspilePath)
return done()
})

describe('cache', function () {
it('handles collisions', function (done) {
var nyc = new NYC({cwd: fixtures})
Expand Down

0 comments on commit 109818f

Please sign in to comment.