0

I'm using the code in several projects and it works fine:

await page.$eval("input[id*='virtual_course']", elem => elem.click())

Except in one project, I get the following error:

Error: Evaluation failed: ReferenceError: cov_77g31rban is not defined
    at __puppeteer_evaluation_script__:3:7

I'm using the same version of all libraries and all projects so not sure why there would be the difference?

ggorlen
  • 44,755
  • 7
  • 76
  • 106
  • Hard to say without the site. Every site is different and there are no silver bullets. Just because something works on one site doesn't mean it'll work on others. `cov_77g31rban` seems totally unrelated to your code, for starters. – ggorlen Jan 02 '23 at 05:35
  • Here's some more information. I noticed that the error only seems to happen when I'm running the function as a test using Jest. The error happens with every instance of $eval. It's also happening with this line: const test = await page.$eval(`#courseID`, el => el.textContent.trim()) Here's the error Error: Evaluation failed: ReferenceError: cov_77g31rban is not defined at __puppeteer_evaluation_script__:3:7 at ExecutionContext._evaluateInternal (/Users/et/src/WebstormProjects/sal/node_modules/puppeteer/src/common/ExecutionContext.ts:273:13) – Coderdude Jan 02 '23 at 16:04

1 Answers1

0

Once I realized that running through Jest was the culprit, I found this thread which fixed the problem.

In Puppeteer, while running tests, istanbul was inserting the following:

/* istanbul ignore next */cov_4kq3tptqc.f[7]++;
                   cov_4kq3tptqc.s[19]++;

This was fixed by adding config.collectCoverage = false; to the jest.config.

ggorlen
  • 44,755
  • 7
  • 76
  • 106