larsthorup / mocha-vite-puppeteer

Run your Mocha tests with Vite bundler and Puppeteer.
MIT License
40 stars 5 forks source link

Add docs on how to run on project in subdirectory? #27

Open fatso83 opened 2 years ago

fatso83 commented 2 years ago

I am getting these quite cryptic error message when trying your mocha runner and I assume it might be due to the file directory layout of my project.

The relevant bits of my NPM scripts look like this:

  dev:app1
    vite -c code/app1/vite.config.ts code/app1
  dev:app2
    vite -c code/app2/vite.config.ts code/app2
  test
    mocha -- --reporter mocha-teamcity-reporter --recursive code/app1/test/ --timeout 5000

So I have basically two apps sharing the same node_modules folder, with their separate setups. If I try to launch your tool from a sub-directory like code/app1 I just get this error:

$ npx mocha-vite-puppeteer
✔ Install the following package: mocha-vite-puppeteer@latest? (Y/n) · true
Packages: +186
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Packages are hard linked from the content-addressable store to the virtual store.
  Content-addressable store is at: /home/my-user/.pnpm-store/v3
  Virtual store is at:             node_modules/.pnpm
Progress: resolved 202, reused 162, downloaded 34, added 186, done
node_modules/.pnpm/esbuild@0.13.12/node_modules/esbuild: Running postinstall script, done in 48ms
node_modules/.pnpm/puppeteer@10.4.0/node_modules/puppeteer: Running install script, done in 92ms

/home/my-user/.pnpm-store/v3/tmp/_npx/29559/5:
+ mocha-vite-puppeteer 2.0.0
Pre-bundling dependencies:
  dayjs/locale/nb
  dayjs
  react
  react-dom
  tcomb/lib/installTypeFormatter
  (...and 192 more)
(this will be run only when your dependencies or config have changed)
[vite] connecting...
[vite] connected.
16:04:07 [vite] new dependencies found: chai, proxyquire, sinon, sinon-chai, @sinonjs/fake-timers, enzyme-to-json, redux-mock-store, tcomb-validation, @testing-library/react, @testing-library/dom, enzyme, updating...
16:04:08 [vite] Failed to load source map for /@fs/home/my-user/dev/my-project/frontend/node_modules/.vite/chunk-6MRIKF33.js?v=54d1b7f1.
16:04:08 [vite] Failed to load source map for /@fs/home/my-user/dev/my-project/frontend/node_modules/.vite/chunk-I3LIQQ36.js?v=54d1b7f1.
16:04:08 [vite] Failed to load source map for /@fs/home/my-user/dev/my-project/frontend/node_modules/.vite/chunk-CUDBNUXQ.js?v=54d1b7f1.
16:04:08 [vite] Failed to load source map for /@fs/home/my-user/dev/my-project/frontend/node_modules/.vite/chunk-APW4DFJS.js?v=54d1b7f1.
Sourcemap for "/home/my-user/dev/my-project/frontend/node_modules/.pnpm/tcomb-additional-types@0.0.2/node_modules/tcomb-additional-types/lib/string/index.js" points to missing source files
Sourcemap for "/home/my-user/dev/my-project/frontend/node_modules/.pnpm/ts-is-present@1.2.1/node_modules/ts-is-present/lib/index.js" points to missing source files
16:04:10 [vite] ✨ dependencies updated, reloading page...
file:///home/my-user/.pnpm-store/v3/tmp/_npx/29559/5/node_modules/.pnpm/mocha-vite-puppeteer@2.0.0/node_modules/mocha-vite-puppeteer/cli.js:126
    throw new Error(request.url() + ' ' + request.failure().errorText);
          ^

Error: http://localhost:3001/test/utils/examinations-logic/summaries/weight-summary.test.js net::ERR_ABORTED
    at file:///home/my-user/.pnpm-store/v3/tmp/_npx/29559/5/node_modules/.pnpm/mocha-vite-puppeteer@2.0.0/node_modules/mocha-vite-puppeteer/cli.js:126:11
    at /home/my-user/.pnpm-store/v3/tmp/_npx/29559/5/node_modules/.pnpm/puppeteer@10.4.0/node_modules/puppeteer/lib/cjs/vendor/mitt/src/index.js:51:62
    at Array.map (<anonymous>)
    at Object.emit (/home/my-user/.pnpm-store/v3/tmp/_npx/29559/5/node_modules/.pnpm/puppeteer@10.4.0/node_modules/puppeteer/lib/cjs/vendor/mitt/src/index.js:51:43)
    at Page.emit (/home/my-user/.pnpm-store/v3/tmp/_npx/29559/5/node_modules/.pnpm/puppeteer@10.4.0/node_modules/puppeteer/lib/cjs/puppeteer/common/EventEmitter.js:72:22)
    at /home/my-user/.pnpm-store/v3/tmp/_npx/29559/5/node_modules/.pnpm/puppeteer@10.4.0/node_modules/puppeteer/lib/cjs/puppeteer/common/Page.js:153:106
    at /home/my-user/.pnpm-store/v3/tmp/_npx/29559/5/node_modules/.pnpm/puppeteer@10.4.0/node_modules/puppeteer/lib/cjs/vendor/mitt/src/index.js:51:62
    at Array.map (<anonymous>)
    at Object.emit (/home/my-user/.pnpm-store/v3/tmp/_npx/29559/5/node_modules/.pnpm/puppeteer@10.4.0/node_modules/puppeteer/lib/cjs/vendor/mitt/src/index.js:51:43)
    at NetworkManager.emit (/home/my-user/.pnpm-store/v3/tmp/_npx/29559/5/node_modules/.pnpm/puppeteer@10.4.0/node_modules/puppeteer/lib/cjs/puppeteer/common/EventEmitter.js:72:22)

I seem to recollect that I got this working the last time I tried in August, but then I was deep into Vite internals (to figure out how to do module mocking), all of which is long gone. Any pointers?

larsthorup commented 2 years ago

In https://github.com/larsthorup/mocha-vite-puppeteer/blob/main/package.json we have this npm script: "test:app": "cd test/app && npm test", which works just fine.

I am not sure I understand from your description above how your setup differs from that?

What's in your code/app1/vite.config.ts?

Would you have time to create a small public repo that reproduces your issue?