A starting point with built-in testing, linting, continuous integration, and coverage support.
- Tutorial for a new project
- Tutorial for an existing project
- Setting up travis and coveralls
- How to use this repository
$ 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:
- A project name (e.g. if you pick
hello
, your project will live atmlibrary/hello
) - A brief project description
- 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
- Follow the instructions for a new project in a new folder.
- Copy the resulting files into your old project.
- Delete the project you created in step 1.
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}
After your first push to github, you'll need to do two things:
- Enable your repository at https://travis-ci.org (you may need to sync account).
- Enable your repository at https://coveralls.io/repos/new (you may need to sync repos).
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.