Skip to content

3.5 Testing with lab and code

zoe-1 edited this page Mar 29, 2015 · 36 revisions

Testing with lab and code

Make sure lab and code are installed.
Install Instructions

Make directory and files:
./test/index.js and
./test/version.js.

Configure package.json and Makefile

 "scripts": {
    "start": "node start.js",
    "test": "lab",
    "test-coverage": "lab -t 100",
    "test-coverage-html": "lab -r html -o test/coverage.html"
  },
  

The above part of the package.json file allows you to run commands like:
npm run test     // This executes: lab -t 100.
npm run test-coverage      // executes:lab -t 100

  • step2: Use Makefile to simplify the commands you run.
    Important: put ".PHONY: all test clean" in your make file to ensure the
    command "make test" does not conflict with the ./test directory.
    See Sample Makefile

  • step3: Build tests for corresponding file under /lib.
    Make sure you get 100% coverage.

  • Important: Use your Makefile commands as short cuts to execute your test.
    For example:
    make test (should run your tests)
    make cov (should run your coverage tests)
    See Sample Makefile

Sample Projects To Look At:

@TheAlphaNerd Assignment3
@Chyld Assignment3
@idanwe Assignment3
@zoe-1 Assignment3

Clone this wiki locally