Running Jest with npx and npm
Get introduced to dev dependencies and running packages using npx and npm.
We'll cover the following...
Adding Jest as a dependency
Use npm
to install the jest
package:
$ npm install --save-dev jest@23.6.0 # 1
...
npm created a lockfile as package-lock.json. You should commit this file. # 2
+ jest@23.6.0
added 538 packages from 269 contributors in 24.446s # 3
...
- The
--save-dev
flag tellsnpm
, “I want to use thejest
package for development only. My project doesn’t need it at runtime.” Thejest@23.6.0
means “I want version23.6.0
of thejest
package.”- For reasons that are too involved to go into here, the information in
package.json
isn’t enough for two machines to be guaranteed to get the samenode_modules
, even if you specify exact versions for all dependencies. That’s whynpm
creates the lockfile. If you’re curious about the details, check out thenpm
docs.- The “538 packages” figure is striking, but it’s propper for Node packages: You depend on one package, which depends on several other packages, which each, in turn, depend