herbsjs / herbs-cli

Herbs CLI
https://herbsjs.org/
MIT License
30 stars 30 forks source link

unit tests getting so much time to run #24

Closed italojs closed 2 years ago

italojs commented 3 years ago

Today we have a problem to write unit tests into CLI, for most part of CLI functions I need to import something about generated project to collect the metadata, because this I need to install the node_modules every time I will test something, it make the test to take sooooooo much time to run.

My first suggestion is:

Install node_modules once and reuse it for all unit tests pros:

Cons:

euduardo commented 2 years ago

The performance problem occurs because the new command runs npm install or yarn add everytime it's called. But, for this cli purposes, how important is installing the dependencies when the user creates the application? Can't we let this task for him? We could put a simple instruction in the documentation.

If it's very important to install the dependencies automatically, can't we just mock the install packages step when running our tests?

Since yarn and npm are external dependencies and we trust they are already tested, we could just verify if they were called when necessary.

italojs commented 2 years ago

we need to install the libs because when I'm generating the files I need to 'require' the entities and usecases... because this I need to install the libs(like @herbsjs/herbs')

Buuuuuuuuuuuuuutttt I got an idea with your question, I think we could to install all dependencies inside the CLI, SOOOOOOOOO instead apply the "npm install XXX", we could to ask the CLI to use yourself node_modules https://stackoverflow.com/a/26293141