Skip to content

A starting point with built-in testing, linting, continuous integration, and coverage support

License

Notifications You must be signed in to change notification settings

mlibrary/node-quickstart

Repository files navigation

Node Quickstart

Build Status Test Coverage

A starting point with built-in testing, linting, continuous integration, and coverage support.

Table of Contents

  1. Tutorial for a new project
  2. Tutorial for an existing project
  3. Setting up travis and coveralls
  4. How to use this repository

Tutorial for a new project

$ git clone https://github.com/mlibrary/node-quickstart your-project
$ cd your-project
$ ./configure

When running ./configure, you'll be asked a series of questions. You should be ready with:

  1. A project name (e.g. if you pick hello, your project will live at mlibrary/hello)
  2. A brief project description
  3. Your own name

It will:

  • check that you have npm installed,
  • check that you have a working test environment,
  • overwrite package.json and README.md,
  • set the correct git origin url,
  • delete itself, and
  • if everything worked, run git commit

Tutorial for an existing project

Using ./configure

  1. Follow the instructions for a new project in a new folder.
  2. Copy the resulting files into your old project.
  3. Delete the project you created in step 1.

By hand

You can look at the files in this repository and copy them mostly as-they-are into your own.

These four files can be copied without making changes:

  • .eslint.json
  • .travis.yml
  • COPYRIGHT.txt
  • LICENSE.txt

These five files can be ignored:

  • configure
  • README.md
  • index.js
  • lib/nothing.js
  • spec/nothing.spec.js

Make sure this line is in your .gitignore:

node_modules/

Lastly, I recommend you generate package.json by running

$ npm init

and answering its prompts (if you haven't already). You can install dev dependencies with the following:

$ npm install --save-dev chai coveralls eslint istanbul mocha eslint-{plugin-{import,node,promise,standard},config-standard}

Setting up travis and coveralls

After your first push to github, you'll need to do two things:

  1. Enable your repository at https://travis-ci.org (you may need to sync account).
  2. Enable your repository at https://coveralls.io/repos/new (you may need to sync repos).

How to use this repository

Your test files go under the spec/ directory, and I suggest that you put your code under the lib/ directory with relative includes to your public-facing stuff in index.js.

At the moment, spec/nothing.spec.js and lib/nothing.js serve as examples. The testing environment is mocha with the chai assertion library. Every test file should have these lines near the top:

/* eslint-env mocha */
const expect = require("chai").expect;

With that, you can safely delete both nothing files.

You can run tests with

$ npm test

The linter is ESLint, which is highly configurable using the .eslintrc.json file. You can (and should) run the linter with

$ npm run lint

By default, travis is set up to run the linter, run the tests, and submit test coverage data to coveralls. You can add or drop support for different versions of node using .travis.yml.

If you want to run test files that are not under the spec/ Directory, you should alter the test and travis scripts in package.json. The last argument in each is spec---you can add additional directories separated by whitespace or you can change spec to something else.

If you change the test script, it will change where npm test looks for tests. If you change the travis script, it will change where travis looks for tests.

For example, you could put some tests in a directory called slow-tests and then add slow-tests after spec in the travis script line. Those tests will be ignored when you run npm test but will still be run by travis every time you push to github.

About

A starting point with built-in testing, linting, continuous integration, and coverage support

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published