I'm introducing unit testing in my project and for this, I need to make myself a package.json
file.
First question is, which unit testing suite
are you using? I'm looking forward mocha
which seem to be pretty much standard for Node.js
projects.
Second question is: Is there any magical way of generating a package.json
file? (for dependencies and versions)
Third question is: I've been testing a lot of npm packages
while developing my project and now I'm stuck with a lot of probably unused packages. Is there any way to tell which one are useless? (I saw npm list installed
which is useful though)
That's it, any advice is welcome! Thanks a lot and have a nice day!
I am using Mocha.
npm init
npm ls
will list "extraneous" next to ones that are not in your package.json. But, it sounds like you don't have a package.json yet.
Basically, your workflow is very backward. Here is how it is intended to work:
npm init
. It has no dependencies.express
? Add it to package.json
under dependencies, then run npm install
.mocha
? Add it to package.json
under devDependencies
, then run npm install
.You seem to have some existing code with manually-installed packages (via npm install <packageName>
), which is a mess. I suggest starting over and following the above workflow.
To answer the third question:
npm prune
will remove all installed modules that are no longer mentioned in your package.json.
And you should really have asked 3 separate questions.
I am also using Mocha. It has code coverage, BDD, TDD, runs in browser. It is pretty complete and also heavily maintained by I think one of the most brilliant javascript/node.js programmers named TJ.
It is almost impossible to guess which version(s) to use. Because npm does not know which version breaks which dependencies. You could probably install all dependencies using something like node-detective. Then you can just install them using npm.js from within javascript. Maybe I would like to tackle this in the future.
I would also probably delete all dependencies , next install needed dependencies back using step(2). But also disc-space is not such a big case anymore with the current HDs.
P.S: I think I also agree with Domenic
I am using vows. It's pretty good, but not perfect. I have found unit testing in node to often be challenging because of async callbacks to dbs & such, and have mostly been testing top level functionality.
Here's your magic: Managing Node.js Dependencies with Shrinkwrap.
The only way to know what packages you are using is to know. You can't generate this programmatically. My advice would be to remove packages aggressively, then retest all functionality - if it breaks, you'll know you need to reinstall one of your packages.
Answering your third question, you can use Sweeper to list unused dependencies, and them remove them from your package.json. Just npm install -g sweeper
then on your project directory call sweeper
on the command line.