Skip to content
This repository has been archived by the owner on Apr 8, 2019. It is now read-only.

3.5 Testing with lab and code

zoe-1 edited this page Apr 3, 2015 · 13 revisions

Testing with lab and code

Make sure lab and code are installed.
Install Instructions

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

Configure package.json and Makefile for testing

 "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 test     // This executes: lab without %100 coverage.
npm run test-coverage      // executes:lab -t 100

  • step2: Use Makefile to simplify the commands you run.
    Important: put ".PHONY: test" and other commands in your make file to ensure the
    command "make test" does not conflict with the ./test directory.
    See Sample Makefile
    @todo write basic best practices for Makefile.

Build tests for corresponding files in /lib.

  • Make sure you get 100% coverage.

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

Exports and testing

Based on conversation with @chyld, as a general rule or best practice do not export
values from plugins just to get tests to pass (many of us were doing that).
This should be avoided

We were exporting values from ./lib/index.js just to pass tests in /lib/index.js.
This was because we did not understand node.js' singleton design of objects created by
required modules.
See Node.js Modules & Singleton Explanation

Sample Projects To Look At:

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