Skip to content
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

Promise rejected with: 'cov_2itgu9hdrb is not defined #514

Closed
farhan2106 opened this issue Feb 5, 2017 · 15 comments
Closed

Promise rejected with: 'cov_2itgu9hdrb is not defined #514

farhan2106 opened this issue Feb 5, 2017 · 15 comments
Assignees

Comments

@farhan2106
Copy link

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)

@bcoe bcoe added the bug label Feb 6, 2017
@bcoe
Copy link
Member

bcoe commented Feb 6, 2017

@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.

@farhan2106
Copy link
Author

farhan2106 commented Feb 7, 2017

@bcoe I have created a sample project to replicate the error.

github project

Again, if we comment out the Nightmare.evaluate api, it will be able to generate the report properly.

The sample code is from Nightmare js github itself.

@JaKXz
Copy link
Member

JaKXz commented Feb 11, 2017

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

@farhan2106
Copy link
Author

@JaKXz Thanks for the help :)

@JaKXz
Copy link
Member

JaKXz commented Feb 12, 2017

@farhan2106 so I'm able to reproduce the issue, which is good.

I tried disabling nyc's instrumentation and going with babel-plugin-istanbul but they both produce the same error. Now I have to dive into the stack trace - but you can follow my progress here: JaKXz/temporary-nyc-error@master...fix/cov-error

@duytran
Copy link

duytran commented Apr 27, 2017

@JaKXz I have same issue with @farhan2106, Is issue fixed? thank you.

@JaKXz
Copy link
Member

JaKXz commented Apr 27, 2017

Thanks for the ping @duytran, I'm unfortunately not available to look deeper. FWIW my fork is still alive: https://github.com/JaKXz/temporary-nyc-error/tree/fix/cov-error and you should be able to reproduce the error there. If you're able, feel free to dig into the issue and for many bonus points try to add a failing test :) though that is a lot of bonus points, because the issue might be in the istanbuljs repo

@duytran
Copy link

duytran commented Apr 27, 2017

@JaKXz thank for reply :)! I will try look around. Thank you.

@bcoe
Copy link
Member

bcoe commented May 14, 2017

@duytran @farhan2106 doing some issue cleanup; sorry that I haven't gotten to this bug yet -- will try to get a test around it as soon as possible.

@duytran
Copy link

duytran commented Jun 8, 2017

Thank @bcoe!

@keithkml
Copy link

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
  )
  ...

PiotrKozlowski added a commit to openstax/mathify that referenced this issue Jun 27, 2018
add /* istanbul ignore next */ before page.evaluate accordingu to istanbuljs/nyc#514 (comment)
@JaKXz
Copy link
Member

JaKXz commented Jul 4, 2018

@keithkml great find. Thank you for your explanation. It would definitely be worth documenting this in a gotchas section or something. Making this comment to myself to get on it, or, for anyone who wants an easy contribution :)

@JaKXz JaKXz added doc and removed bug labels Jul 4, 2018
@epyx25
Copy link

epyx25 commented Oct 30, 2018

Without the fix I was getting

[Error: Evaluation failed: ReferenceError: cov_1khzuukk7w is not defined
at evaluate (:1:30)]

The line /* istanbul ignore next */ solves the problem

  const evaluateRes = await page.evaluate(
     /* istanbul ignore next */
     (selector) => {return selector}, this.selector
   )

I am trying to make a base scraper class, where the inherited scraper classes have different evaluate method.
@keithkml or someone could you explain who could I make this work too?

class ScraperBase{
  evaluate(selector) {
   return selector
  }

  run() {
    const browser = await puppeteer.launch()
    const page = await browser.newPage();
    // ...
   const evaluateRes = await page.evaluate(
      /* istanbul ignore next */
      this.evaluate, this.selector
    )  
  }
}

Now I am getting

[Error: Evaluation failed: ReferenceError: cov_1khzuukk7w is not defined

again

@coreyfarrell
Copy link
Member

@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.

@stale
Copy link

stale bot commented May 6, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label May 6, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants