privatenumber / instant-mocha

☕️ Build tests with Webpack and run with Mocha in one command
MIT License
47 stars 6 forks source link

Failed to install #6

Closed serut closed 3 years ago

serut commented 3 years ago

Hello,

I struggle to use your fork with Webpack 5:

node:14344) [DEP_WEBPACK_MODULE_ID] DeprecationWarning: Module.id: Use new ChunkGraph API
Error: Module.id: There was no ChunkGraph assigned to the Module for backward-compat (Use the new API)
    at /home/leo/CS/rs-dev/regards-oss-frontend/webapp/plugins/criterion/data-with-picture-only/node_modules/webpack/lib/ChunkGraph.js:1548:12
    at deprecated (internal/util.js:89:15)
    at Function.getChunkGraphForModule (/home/leo/CS/rs-dev/regards-oss-frontend/webapp/plugins/criterion/data-with-picture-only/node_modules/webpack/lib/ChunkGraph.js:1539:18)
    at CompatGetDefaultExportRuntimeModule.get id [as id] (/home/leo/CS/rs-dev/regards-oss-frontend/webapp/plugins/criterion/data-with-picture-only/node_modules/webpack/lib/Module.js:172:21)
    at /home/leo/CS/rs-dev/regards-oss-frontend/webapp/plugins/criterion/data-with-picture-only/node_modules/mochapack/src/webpack/util/getAffectedModuleIds.ts:43:51
    at Array.reduce (<anonymous>)
    at Set.set.<computed> [as reduce] (/home/leo/CS/rs-dev/regards-oss-frontend/webapp/plugins/criterion/data-with-picture-only/node_modules/webpack/lib/util/deprecation.js:87:35)
    at buildModuleMap (/home/leo/CS/rs-dev/regards-oss-frontend/webapp/plugins/criterion/data-with-picture-only/node_modules/mochapack/src/webpack/util/getAffectedModuleIds.ts:42:29)
    at Object.getAffectedModuleIds [as default] (/home/leo/CS/rs-dev/regards-oss-frontend/webapp/plugins/criterion/data-with-picture-only/node_modules/mochapack/src/webpack/util/getAffectedModuleIds.ts:144:32)
    at Object.getBuildStats [as default] (/home/leo/CS/rs-dev/regards-oss-frontend/webapp/plugins/criterion/data-with-picture-only/node_modules/mochapack/src/webpack/util/getBuildStats.ts:20:47)

did you test with a real project ?

serut commented 3 years ago

You can reproduce using :

git clone https://github.com/serut/regards-frontend-webpack-5
cd webapp
npm i
npm run test:mocha

Webpack config is inside /webapp/webpack-config-front/src/app/webpack.test.config.js

privatenumber commented 3 years ago

Yep, tested and working with a large enterprise project.

Thanks for the repro. I'm getting a different error than you. Can you provide your instant-mocha command?

Could it be that even though you installed instant-mocha, you're still using mochapack?

PS, this isn't a fork

privatenumber commented 3 years ago

Also seems like you upgraded to Webpack 5 without confirming that instant-mocha is working. So the error you provided above is completely irrelevant to instant-mocha.

instant-mocha supports both Webpack 4 & 5. Please test in isolation with Webpack 4 if that was already working for you.

And if possible, please provide a minimal reproduction of the error.

serut commented 3 years ago

With or without webpack 5 I have the same error (after fixing test cmd) :

Cannot find module 'chai'
Require stack:
- /main.js
- /home/leo/CS/rs-dev/regards-oss-frontend/webapp/node_modules/instant-mocha/dist/lib/memfs.js
- /home/leo/CS/rs-dev/regards-oss-frontend/webapp/node_modules/instant-mocha/dist/lib/mocha.js
- /home/leo/CS/rs-dev/regards-oss-frontend/webapp/node_modules/instant-mocha/dist/instant-mocha.js
- /home/leo/CS/rs-dev/regards-oss-frontend/webapp/node_modules/instant-mocha/dist/cli.js
- /home/leo/CS/rs-dev/regards-oss-frontend/webapp/node_modules/instant-mocha/bin/instant-mocha.js
npm ERR! code ELIFECYCLE

Sorry I thought it was a fork..

serut commented 3 years ago

If I had /chai/, to the whitelist inside externals: [nodeExternals it founds chai, but then it's another dependency that's missing...

serut commented 3 years ago

I removed externals and module.noParse from my webpack test conf to make it compiles. Now some mocks are not working anymore, but it looks like a lot of things are working as expected. Congratz !

serut commented 3 years ago

Now I've fixed my stub, the runner does not stop when finished (I'm still using Webpack 4).

The command just hangs with :

  3082 passing (3s)

[mochawesome] Report JSON saved to /home/leo/CS/rs-dev/regards-oss-frontend/webapp/reports/mocha/mochawesome.json

[mochawesome] Report HTML saved to /home/leo/CS/rs-dev/regards-oss-frontend/webapp/reports/mocha/mochawesome.html

Edit: Same behavior with Webpack 5. I pushed a new branch feature/webpack5 : https://github.com/serut/regards-frontend-webpack-5/tree/feature/webpack5