Configuring Jest, Travis and Coveralls
Easy steps to use travis, jest and coveralls.
Prerequisites
Start the project
mkdir cover-project
cd cover-project
npm init --yes
Create your first test
Install Jest
npm install --save-dev jest
Configure package.json
part of file: package.json
"scripts": {
"test": "jest --coverage"
}
Edit a test file
file: src/index.test.js
const greeter = require(".");
test("should return hello message", () => {
expect(greeter()).toBe("Hello, world!");
});
Make your test pass
file: src/index.js
module.exports = () => "Hello, world!";
Coveralls
Install coveralls node package
npm install --save-dev coveralls
Travis CI
Add travis configuration
file: .travis.yml
language: node_js
node_js:
- "8"
after_script:
- cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js
Git
Create .gitignore
file: .gitignore
coverage
node_modules
Init git project
git init
git add --all
git commit --message="First commit"
Push git project to GitHub
git remote add origin https://github.com/<user>/<project>
git push -u origin master
Register projects
- Register repository at travis
- Register repository at coveralls
Done!
-
Copy your badges to your
README.md
and be happy :-) -
Example: