liveBook · Manning

Blanket.js

As explained in Functional Programming in JavaScript

A JavaScript code-coverage tool that instruments source code and reports execution coverage.

Blanket.js measures which JavaScript statements run during unit tests. It reveals untested paths, including error handling that tests may overlook, while complementing—not replacing—judgments about code quality. section 6.5

Blanket.js works in three steps:

  • Loads the source files. section 6.5
  • Instruments the code by adding tracker lines that record statement execution. section 6.5
  • Connects test-runner hooks to a report, such as a QUnit coverage report. section 6.5

Comparing imperative and functional tests

A QUnit test can invoke showStudent with a valid identifier and assert the returned student string. Blanket.js reports 80% coverage for the imperative version when 12 of 15 lines execute, while the functional version reaches 100% for the same positive path. Null-input tests expose another contrast: the imperative version reaches only 40%, whereas the functional version skips irrelevant data-manipulation lines and continues to produce strong coverage. section 6.5

<script src="imperative-show-student-program.js" data-cover></script>

Mark a JavaScript source include with data-cover so Blanket.js instruments that program for coverage reporting. section 6.5

How Functional Programming in JavaScript covers it

How deep it goes
Explains loading, instrumentation, tracker hooks, and reporting, but defers setup details to an appendix.
Examples
Uses QUnit showStudent tests with valid and null inputs to compare imperative and functional coverage results.
What it assumes
Assumes familiarity with JavaScript source files and unit tests, especially QUnit-style tests.
What you can do after
Apply it via Blanket.js to identify untested JavaScript statements and guide additional unit tests.
How it connects
Connects code coverage with unit testing, QUnit, instrumentation, statement coverage, and functional programming.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Functional Programming in JavaScript. The section links point to the parts of the book it draws on.