Skip to content

Commit

Permalink
test: regression tests for istanbuljs#7
Browse files Browse the repository at this point in the history
  • Loading branch information
motiz88 committed Aug 26, 2016
1 parent e4624ad commit 9747dff
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 0 deletions.
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@
"coveralls": "^2.11.9",
"cross-env": "^2.0.0",
"mocha": "^3.0.2",
"mock-fs": "^3.11.0",
"nyc": "^7.0.0",
"pmock": "^0.2.3",
"standard": "^7.1.2",
"standard-version": "^2.3.1"
},
Expand Down
77 changes: 77 additions & 0 deletions test/babel-plugin-istanbul.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
/* eslint-env mocha */

const babel = require('babel-core')
import mockFs from 'mock-fs'
import mockProcess from 'pmock'
import fs from 'fs'
import makeVisitor from '../src'

require('chai').should()
Expand Down Expand Up @@ -49,4 +52,78 @@ describe('babel-plugin-istanbul', function () {
result.code.should.not.match(/statementMap/)
})
})

// Regression tests for /~https://github.com/istanbuljs/babel-plugin-istanbul/issues/7
context('when current path uses a symlink', function () {
beforeEach(function () {
mockFs({
'/project': {
'fixtures': {
'should-cover.js': fs.readFileSync('./fixtures/should-cover.js')
},
'package.json': fs.readFileSync('./package.json')
},
'/symlink': mockFs.symlink({path: '/project'})
})
})

const shouldInstrument = file => {
var result = babel.transformFileSync(file, {
plugins: [
makeVisitor({types: babel.types})
]
})
result.code.should.match(/statementMap/)
}

context('and NYC_CWD is set', function () {
var env

beforeEach(function () {
env = mockProcess.env({
NYC_CWD: '/symlink'
})
})

it('should instrument file accessed via link', function () {
shouldInstrument('/symlink/fixtures/should-cover.js')
})

it('should instrument file accessed via real path', function () {
shouldInstrument('/project/fixtures/should-cover.js')
})

afterEach(function () {
env.reset()
})
})

context('and only process.cwd() is set', function () {
var env, cwd

beforeEach(function () {
env = mockProcess.env({
NYC_CWD: ''
})
cwd = mockProcess.cwd(fs.realpathSync('/symlink')) // realpath because of mock-fs Windows quirk re: process.cwd
})

it('should instrument file accessed via link', function () {
shouldInstrument('/symlink/fixtures/should-cover.js')
})

it('should instrument file accessed via real path', function () {
shouldInstrument('/project/fixtures/should-cover.js')
})

afterEach(function () {
env.reset()
cwd.reset()
})
})

afterEach(function () {
mockFs.restore()
})
})
})
1 change: 1 addition & 0 deletions test/mocha.opts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
--require mock-fs

0 comments on commit 9747dff

Please sign in to comment.