Allan Ebdrup
Allan Ebdrup

Reputation: 142

What javascript parser sould I use to re-implement jsCoverage in JavaScript for node?

I really like code-coverage reports for my code in node.js. I've already created a node.js module that can inject instrumented code (and mock our require statements) called requiremock

I'm using that in my other module nodecoverage together with the binary version of jsCoverage (windows) to generate code coverage reports, injecting instrumented versions of code with requiremock.

The problems with using jsCoverage are

  1. It needs compilation for the platform, because it's written in C(++), I would like to implement it in JavaScript so it can be used on any platform without compilation.
  2. It writes the instrumented versions of code as files on disk. With requiremock I can generate the instrumented JavaScript files in memory and run those when the original file is required.
  3. jsCoverage does not report code coverage correctly when using function hoisting, and I use that a lot in node.js

So my question is:

What JavaScript parser written in JavaScript should I choose to reimplement jsCoverage as a node.js module?

I have to be able to know the linenumber of the code in the original file, and also know what whitespacing was like.

Upvotes: 2

Views: 635

Answers (1)

Andrey Sidorov
Andrey Sidorov

Reputation: 25466

Try esprima. It's awesome. Also node-cover potentially already does have what you need

Upvotes: 2

Related Questions