官术网_书友最值得收藏!

Creating a new Jest project

The Git tag for this section is starting-point. It doesn't contain any code; just a README.md file. If you want to follow along using the book's Git repository then you should ensure you've branched from this tag. Detailed instructions from doing that are in the Getting started before Chapter 1 section of the Preface.

Now that NPM is installed, we can create our project:

  1. If you're following along with the book's Git repository, open a Terminal window and navigate to the repository directory that you cloned in the Getting started before Chapter 1 section of the Preface. Otherwise, simply navigate to your local projects directory.
  2. Create a new directory using mkdir appointments and then change to it using cd appointments.
  3. Enter the npm init command, which begins the process of initializing a new NPM project and generating a package.json file for you.
  4. The first questions ask you to provide a package name, version, description, and an entrypoint. Since we're building an appointments system, you can call it appointments. Accept the default version (by just hitting Enter), and enter a description of Appointments system. You can accept the default entrypoint too.
  5. Next, you'll be asked for a test command, for which you should type in jest. This will enable you to run tests by using the npm test shortcut command.
Don't worry if you miss this; you can set it afterward by adding "test": "jest" to the scripts section of the generated package.json.
  1. You'll be asked to specify a repository, which you could just set as example.com for now. If you don’t fill these fields in, npm will print warnings every time you run a command.
  1. You can accept the defaults for everything else.
You may wonder why we filled out the repository field. TDD loves fast feedback cycles. Prioritize cleaning your screen and command outputs of as much noise as possible. Any time you see something that is destroying clarity, either fix it right then and there, or put it as an action at the top of your to-do list.

In this particular case, you could also add "private": true to your package.json, instead of setting the repository field.
  1. Hit Enter on the remaining questions to finish the initialization process.
  2. Install Jest using npm install --save-dev jest.

You will see the bottom line of your Terminal fill up with a fast-changing stream of package information as NPM installs dependent packages (a paltry 553 packages at the time of writing). You may see some warnings depending on the platform you are installing on, but these can be ignored. Once complete, you should see this:

npm notice created a lockfile as package-lock.json. You should commit this file.

+ jest@24.7.1
+ added 553 packages from 373 contributors and audited 849842 packages in 16.304s
+ found 0 vulnerabilities
主站蜘蛛池模板: 女性| 昌吉市| 博白县| 郁南县| 镇江市| 长葛市| 永昌县| 赞皇县| 横山县| 平泉县| 榆社县| 舒城县| 繁峙县| 基隆市| 泗洪县| 凌海市| 连山| 绿春县| 沾化县| 潍坊市| 东乌| 嵊泗县| 赣州市| 南开区| 聂荣县| 怀来县| 万年县| 宁南县| 玛纳斯县| 罗源县| 台山市| 信丰县| 淳安县| 孝义市| 乌拉特中旗| 全州县| 辉南县| 会理县| 吉安县| 收藏| 开江县|