Reconstruction of 2: Mocha / Chai testing environment based environment to build NodeJS

Recently reading Refactoring: Improving the Design of Existing Code (2nd edition), Chapter 4, which referred to the need to build a test system, because the reconstruction is based on the test, it must have a test system, so that reconstruction can proceed smoothly.

Because the reconstruction of the second edition of the language is different with the first edition, using Javascript, rather than Java, Java before a little familiar, I know if Java, then use JUnit on it, but Javascript bit different, but is used in the back end of Javascript, which is our theme, because it is the first contact nodejs, who say there is not the right place, please correct me.

Please refer to the following steps to build

1. Download NodeJS, and install it on the Internet side has a lot of tutorials in this regard, I would mention here.

https://nodejs.org/en/

2. The installation is divided into two test Mocha mounting frame, extension package.

  • Global installed $ npm install --global mocha, if Qiaoxia line command in cmd, then, nodejs package will be extended in the following path, C: \ Users \ xx \ AppData \ Roaming \ npm \ node_modules \
  • Local installation $ npm install mocha, if Qiaoxia line command in cmd, then, nodejs will the expansion pack installed in the current path, if there is a folder in the current cmd node_modules running path, it will extend this library installation path if not currently node_modules folder, nodejs will automatically help you create a node_modules folder and install the extensions entered,

Personally recommend local installation, according to the structure nodejs project, the project will nodejs with node_modules folder, you can just run locally installed cmd in the project root directory, specific directory structure, please refer to the figure.

3. Install the extension package Chai

The method of using the local installation, open cmd, positioned to project root path, enter the following instruction to $ npm install chai

4. Verify that the installation was successful, go to node_modules project directory to see if there mocha chai and two folders, yes it indicates that the installation is complete

 

  

 

Guess you like

Origin www.cnblogs.com/alvinwu/p/11135542.html