Coder Social home page Coder Social logo

Preliminary Concepts about learningfs HOT 2 OPEN

oldoc63 avatar oldoc63 commented on August 21, 2024
Preliminary Concepts

from learningfs.

Comments (2)

oldoc63 avatar oldoc63 commented on August 21, 2024

Install Mocha

Before writing any test you'll need to use Node.js and npm to set up a JavaScript project and install Mocha.

  • Node allows you to run JavaScript in the terminal
  • npm is a Node tool that allows you to download packages from the web, and manage them in a JavaScript project
  • Mocha is one of those packages and is used to test other JavaScript code

A JavaScript project is a directory of files. The following command creates a file package.json that can be used to manage packages for the project.

npm init

After running this command you will be prompted to enter information about your project. It's okay to skip some fields if you're not ready to enter that information.

With your project setup, you can install packages.

npm install mocha -D

Here's what this command means:

  • npm install tells npm to install a package from the internet and any other packages it depends on
  • mocha is the package you want to download
  • -D signifies that this package is a development dependency and will show up under the devDependecies section in package.json. This means that the package will only be included in development mode and will not be included in the production bundle.

Once you npm install packages, you can find the packages and all their dependencies in the node_modules folder. The new directory structure contains the following:

project
|_ node_modules
|___ .bin
|___ mocha
|___ ...
|_ package.json

The ... in the file structure represents other packages that are a dependency for Mocha.
Initialize the project:

npm init

Install Mocha:

npm install mocha -D

You can view package.json in the text editor. You can now see mocha as a dependency.

from learningfs.

oldoc63 avatar oldoc63 commented on August 21, 2024

After installing Mocha as a dependency we can run it in two ways.
The first (and more tedious) method is to call it directly from node_modules:

./node_modules/mocha/bin/mocha

The second (and recommended) method is to add a script to package.json. In the scripts object in package.json, set the value of "test": "mocha". It should look like this:

"scripts": {
"test": "mocha"
}

Now you can call Mocha with the following command:

npm test

Instead of manually running each test in the test directory, you can use this command to run the full test suite automatically.

from learningfs.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.