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
- fix cov_2c8uh5it19 is not defined add /* istanbul ignore next */ before page.evaluate accordingu to https://github.com/istanbuljs/nyc/issues/514#issuecomment-322784724 — committed to openstax/mathify by PiotrKozlowski 6 years ago
- windowPerformance: fix "ReferenceError: cov_xxx is not defined" See https://github.com/istanbuljs/nyc/issues/514#issuecomment-322784724 — committed to macbre/phantomas by macbre 3 years ago
Nightmarejs converts functions passed to
evaluate
into strings, theneval
s 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:
@epyx25 in the example you posted you need:
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.