New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Usage with Istanbul #44

Closed
rgbkrk opened this Issue Feb 20, 2016 · 8 comments

Comments

Projects
None yet
3 participants
@rgbkrk
Contributor

rgbkrk commented Feb 20, 2016

Anyone seen a good setup using this with Istanbul?

@orbitbot

This comment has been minimized.

orbitbot commented Mar 29, 2016

There's a discussion and some useful snippets / links here: #19

@rgbkrk

This comment has been minimized.

Contributor

rgbkrk commented Apr 19, 2016

Here's what I tried today, even after reading through that thread and link chain:

$ $(npm bin)/istanbul cover $(npm bin)/electron-mocha -- --renderer --compilers js:babel-core/register 'test/renderer/**/*.js'
(electron) options.preload is deprecated. Use options.webPreferences.preload instead.


  Notebook
    ✓ accepts an Immutable.List of cells (75ms)

  setNotebook
    ✓ converts a JSON notebook to our commutable notebook and puts in state

  updateExecutionCount
    ✓ updates the execution count by id

  newCellAfter
    ✓ creates a brand new cell after the given id

  reducers
    ✓ has a function defined for each Symbol prop

  createStore
    ✓ sets up our store model


  6 passing (228ms)

No coverage information was collected, exit without writing coverage information
@rgbkrk

This comment has been minimized.

Contributor

rgbkrk commented Apr 19, 2016

Reading again, trying a bit harder. 😉

@inukshuk

This comment has been minimized.

Collaborator

inukshuk commented Apr 20, 2016

You won't be able to call istanbul cover electron-mocha: istanbul hooks into require to instrument your code, but electron-mocha is a node process which spawns an electron process (which in turn spawns a renderer process when called with --renderer) -- this can't work. You'd have to run istanbul from inside your electron processes.

Luckily, istanbul is pretty versatile: you can istanbul instrument your code first, then run electron-mocha, and write out the coverage information, which you can combine with istanbul report. I linked to an example in #19 which works fine both in the main process and in the renderer.

@inukshuk inukshuk closed this Apr 20, 2016

@rgbkrk

This comment has been minimized.

Contributor

rgbkrk commented Apr 20, 2016

How do you instrument with code that relies on a babel transpile before, like this:

electron-mocha --renderer --compilers js:babel-core/register 'test/renderer/**/*.js'

This means a couple stages then:

src --> build // ES6 --> ES5
build --> instanbuild // ES5 --> instanbullified ES5

tests will require from istanbuild
@rgbkrk

This comment has been minimized.

Contributor

rgbkrk commented Apr 20, 2016

Wondering about if there's a way for us to build in the instrumentation into electron-mocha itself. I would hate to require that people go through multiple explicit build steps in their setup.

@rgbkrk rgbkrk referenced this issue Apr 20, 2016

Closed

Instrument coverage testing #338

2 of 2 tasks complete
@orbitbot

This comment has been minimized.

orbitbot commented Apr 20, 2016

@rgbkrk I have the config I was able to work out based on the discussion in the other thread here: https://github.com/orbitbot/web-mqtt-client/blob/master/package.json -- it's kinda clunky to handle a multistep task with only npm run commands, but the pre/post hooks help (https://docs.npmjs.com/misc/scripts). If you're willing to use fe. gulp as a build tool, multistep stuff like what's required for transpiling => instrumenting => running is kind of what it's made for and shouldn't be too hard to configure.

@inukshuk

This comment has been minimized.

Collaborator

inukshuk commented Apr 20, 2016

You're right, running istanbul inside of electron should take care of the problem (you'd have to start instrumenting first thing in main and then, as a preload script in the renderer). I think you could probably get this done by using the --compiler option; but you'd also have to add a script or (as in my case) a mocha reporter which actually saves or prints the coverage information.

Regarding babel; I had not issue running istanbul instrument on ES6 code. However, I did run into problems with async/await, so, yes, I am currently instrumenting the transpiled code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment