speedskater / babel-plugin-rewire

A babel plugin adding the ability to rewire module dependencies. This enables to mock modules for testing purposes.
842 stars 90 forks source link

HTML error when using default function parameters #165

Open queicherius opened 7 years ago

queicherius commented 7 years ago
Cannot read property 'start' of undefined
TypeError: Cannot read property 'start' of undefined
    at /Users/david/Projects/abc-environment/node_modules/nyc/node_modules/istanbul-reports/lib/html/annotator.js:137:32
    at Array.forEach (native)
    at annotateBranches (/Users/david/Projects/abc-environment/node_modules/nyc/node_modules/istanbul-reports/lib/html/annotator.js:112:30)
    at Object.annotateSourceCode (/Users/david/Projects/abc-environment/node_modules/nyc/node_modules/istanbul-reports/lib/html/annotator.js:191:9)
    at HtmlReport.onDetail (/Users/david/Projects/abc-environment/node_modules/nyc/node_modules/istanbul-reports/lib/html/index.js:217:39)
    at LcovReport.(anonymous function) [as onDetail] (/Users/david/Projects/abc-environment/node_modules/nyc/node_modules/istanbul-reports/lib/lcov/index.js:24:24)
    at Visitor.(anonymous function) [as onDetail] (/Users/david/Projects/abc-environment/node_modules/nyc/node_modules/istanbul-lib-report/lib/tree.js:34:30)
    at ReportNode.Node.visit (/Users/david/Projects/abc-environment/node_modules/nyc/node_modules/istanbul-lib-report/lib/tree.js:123:17)
    at /Users/david/Projects/abc-environment/node_modules/nyc/node_modules/istanbul-lib-report/lib/tree.js:116:23
    at Array.forEach (native)


This is a minimal reproduction test case, which yields the HTML error.

// module
const answer = 42
export default function (something, punctuation = '!') {
  if (something === 'test') {
    console.log('Testing something.')
  }

  return answer + punctuation
}
// Test
import {expect} from 'chai'
import module from './module.js'

describe('my module', () => {
  it('should return the answer to life', async () => {
    let result = await module('hello')
    expect(result).to.equal('42!')
  })

  it('should return the answer to life', async () => {
    let result = await module('test', '?')
    expect(result).to.equal('42?')
  })
})
queicherius commented 7 years ago

I committed this pull request, but it would be better to figure out what generates the issue instead of patching it in the end result.

speedskater commented 7 years ago

@queicherius thanks for the PR. I would really like to fix the issue also from our side, but I do not understand what is meant by wrong meta data. Do you have a complete sample to reproduce the error?

queicherius commented 7 years ago

I would really like to fix the issue also from our side, but I do not understand what is meant by wrong meta data.

The generated branch array is [ 2, null ], while the generated meta array is only [ { start: { line: 8, column: 50 }, end: { line: 8, column: 53 } } ] triggering an error when going through the branch array and accessing the undefined meta element. Not sure why / how it does that, I just logged it when putting in the PR.

Do you have a complete sample to reproduce the error?

Sure, I made a repository for you here. Tried to make it as simple as possible.

speedskater commented 7 years ago

@queicherius thanks for your detailed example. I had a look at it and although the sample perfectly reproduces the error, I haven't found a solution until now. Sorry that I am not having a longer time slot to investigate the problem in the next week but I will try to find a solution ASAP.