Things are getting a bit more interesting...
It's time to add tests, verify coverage, confirm style, and automate all of this with CI. We will be using the lab module to perform all these tasks and automate it with travis.
- Add a
.travis.yml file, testing our project on node 0.10, 0.12, and io.js (latest).
- Add a test folder with two files,
version.js and index.js, each testing the corresponding file under /lib.
- Modify the
package.json file to include the tests, as well as the dev dependency to lab.
- Add the standard hapi.js Makefile to make it easy to generate other types of reports (e.g. HTML coverage report). Note: From Assignments5 on this project only uses npm. Between assignments 4 and 5, style rules changed and the Makefile was removed from hapijs projects.
- When using lab, enable coverage, require 100% coverage, enable linting with default rules, and use the code assertion library.
- Write a basic test to verify our version endpoint in
version.js.
- Change the
init() method to accept a port and a callback. Use the callback to return when the function completes or errors. The init() callback should return any error state as well as a reference to the newly created server. This will allow us to later stop the server when we test it.
- Export
init() and move the invocation to a new start.js file (which will call the init() function with the 8000 port and a callback the outputs the information to the console when started). Change the package.json file to use the start.js file as the starting place. This file will not be covered by tests.
- Write a basic test to verify the
init() function in index.js.
- Bring coverage to 100% by adding more tests as needed.
Everything up to (10) should be pretty straight forward. If you are not sure on how to use lab and code, look at other hapi.js modules like hoek, qs, items, and boom (e.g. simple modules) to copy their test scripts and setup.
Getting 100% coverage can be tricky sometimes so if you are not sure, get as much coverage as you can, and comment on the lines in your pull request where you are having a hard time reaching and someone will give you a clue.
Remember to properly stop() your servers when calling the init() method in each test.
For now, avoid using any of the before() and after() lab features.
As always, ask for help and help others!
Due: 4/4
Things are getting a bit more interesting...
It's time to add tests, verify coverage, confirm style, and automate all of this with CI. We will be using the lab module to perform all these tasks and automate it with travis.
.travis.ymlfile, testing our project on node 0.10, 0.12, and io.js (latest).version.jsandindex.js, each testing the corresponding file under/lib.package.jsonfile to include the tests, as well as the dev dependency to lab.version.js.init()method to accept a port and a callback. Use the callback to return when the function completes or errors. Theinit()callback should return any error state as well as a reference to the newly created server. This will allow us to later stop the server when we test it.init()and move the invocation to a newstart.jsfile (which will call theinit()function with the8000port and a callback the outputs the information to the console when started). Change thepackage.jsonfile to use thestart.jsfile as the starting place. This file will not be covered by tests.init()function inindex.js.Everything up to (10) should be pretty straight forward. If you are not sure on how to use lab and code, look at other hapi.js modules like hoek, qs, items, and boom (e.g. simple modules) to copy their test scripts and setup.
Getting 100% coverage can be tricky sometimes so if you are not sure, get as much coverage as you can, and comment on the lines in your pull request where you are having a hard time reaching and someone will give you a clue.
Remember to properly
stop()your servers when calling theinit()method in each test.For now, avoid using any of the
before()andafter()lab features.As always, ask for help and help others!
Due: 4/4