mocha-vite-puppeteer
mocha-vite-puppeteer copied to clipboard
tests fail with v2 and svelte-kit
Hello.
Just spent some time to set up a plain svelte-kit project with a simple mocha-vite-puppeteer test. This test runs through without problem with mocha-vite-puppeteer v1.x, but fails when switching to v2.
https://github.com/michaelvogt/kit-testing/tree/main/tmp/my-app
The stack trace looks like this:
C:\tmp\my-app\node_modules\puppeteer\lib\cjs\puppeteer\common\ExecutionContext.js:221
throw new Error('Evaluation failed: ' + helper_js_1.helper.getExceptionMessage(exceptionDetails));
^
Error: Evaluation failed: ReferenceError: mocha is not defined
at __puppeteer_evaluation_script__:3:5
at ExecutionContext._evaluateInternal (C:\tmp\my-app\node_modules\puppeteer\lib\cjs\puppeteer\common\ExecutionContext.js:221:19)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at async ExecutionContext.evaluate (C:\tmp\my-app\node_modules\puppeteer\lib\cjs\puppeteer\common\ExecutionContext.js:110:16)
at async file:///C:/tmp/my-app/node_modules/mocha-vite-puppeteer/cli.js:140:24
I have the feeling that this is something simple, but I don't know how to debug this.
Hey @michaelvogt thank your for creating a repo with reproduction! I have been sick this week, but hope to look into this shortly.
No worries, please take your time to get healthy again.
When I create an empty index.html
(or with any html content really) next to test.html
in the my-app
folder of your repo, then npm test
will run successfully no matter whether enableBarePath
is set to true or false:
13:39:28 /c/r/github/michaelvogt/kit-testing/tmp/my-app
$ ls -l index.html
-rw-r--r-- 1 lars 197609 0 Nov 7 13:33 index.html
13:39:31 /c/r/github/michaelvogt/kit-testing/tmp/my-app
$ npm test
> [email protected] test
> mocha-vite-puppeteer
[vite] connecting...
Counter
✔ should count
1 passing (7ms)
To me it seems like this is a requirement of Vite, rather than being something we can do anything about in mocha-vite-puppeteer.
@michaelvogt Could you verify if this "solution" also works with your other svelte-kit project?
Assuming the "solution" above is confirmed, we could improve the developer experience by giving a better error message in this case...
I think the important information here is, that the 1.x version of mocha-vite-puppeteer work fine, only the 2.x version is broken.