nyc: Promise rejected with: 'cov_2itgu9hdrb is not defined

I got the following bugs.

Promise rejected with: 'cov_2itgu9hdrb is not defined'

I am using Nightmare.js for browser automation. After investigation, the above error is thrown when I use Nightmare.evaluate api. When I remove any references to Nightmare.evaluate it is able to do coverage properly.

Am not sure it is an error with nyc or nightmare.

Forensic Information

v6.9.1 3.10.8 /Users/farhanghazali └── (empty)

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 15 (7 by maintainers)

Commits related to this issue

Most upvoted comments

Nightmarejs converts functions passed to evaluate into strings, then evals them within the Electron/Chrome context. This means when the function is actually executed, Istanbul’s coverage info variables are not present in scope.

The solution is to use Istanbul’s coverage comment syntax:

browser
  .goto('http://...')
  .evaluate(
    /* istanbul ignore next */ 
    () => document.getElement('my-div').innerText
  )
  ...

@epyx25 in the example you posted you need:

class ScraperBase{
  /* istanbul ignore next */
  evaluate(selector) {
   return selector
  }

// ...
}

It’s important that you prevent instrumentation of the body of the function that will be sent to the browser, so the /* istanbul ignore next */ goes before the function declaration.

@farhan2106 I have some capacity this weekend, I will try to get back to you on this soon! Thanks for your patience.

@farhan2106 could you share a minimal reproduction of this bug with nightmare.js? I think you’ve probably found a legitimate edge-case with the instrumenter, which is returning a line counting variable rather than a promise.