gotwarlost / istanbul

Yet another JS code coverage tool that computes statement, line, function and branch coverage with module loader hooks to transparently add coverage when running tests. Supports all JS coverage use cases including unit tests, server side functional tests and browser tests. Built for scale.
Other
8.7k stars 786 forks source link

Internal error: attempt to prepend statements in disallowed (non-array) context #621

Open ghost opened 8 years ago

ghost commented 8 years ago

I know this is a very very old bug, and supposed to be fixed in Istanbul 0.2.9. But it still exist, and isn't fixed. If you are running a combo of Rollup+Buble+Rollup-plugin-istanbul it will happend to you. Even if I replace Buble with Babel it will still happen inside the Karma test runner.

IF I comment out Istanbul, everything works just fine.

Ref: https://github.com/gotwarlost/istanbul/issues/202

gotwarlost commented 8 years ago

That statement is a generic catch-all for unexpected things seen in the AST. The bug was fixed for the specific case that was reproduced there.

Unless you can provide a minimal reproducible test case, I have no idea how to debug this. Is there any way you could provide a simple test case that fails?

kalitine commented 8 years ago

I had the same issue. For example for this it works fine:

// src/111.js
class A {
  helloWorld () {
    console.log('Hello world!')
  }
}

export {A}
// test/111.test.js
import {A} from '../src/111.js'

it('Test', () => {
  new A().helloWorld()
})

But if I add export const STATE = 'open' to 111.js

export const STATE = 'open'

class A {
  helloWorld () {
    console.log('Hello world!')
  }
}

export {A}

It throws this exception. And if I export the STATE constant like this

const STATE = 'open'

class A {
  helloWorld () {
    console.log('Hello world!')
  }
}

export {STATE, A}

it works fine again.

ghost commented 8 years ago

@gotwarlost This issue can be solved if you accept the PR that have been pending for months - https://github.com/gotwarlost/istanbul/pull/507. It's related to this issue.

ShadSterling commented 6 years ago

It would be helpful if the error message said where in the code it sees something unexpected. Then at least I could share the particular bit of code that triggered it.

ShadSterling commented 6 years ago

I looks like I can avoid the error by downgrading to mocha 3.5. Any newer version seems to be incompatible with istanbul 0.4.5.