UNPKG

2.9 kBMarkdownView Raw
1# [![unitest logo](https://cdn.rawgit.com/rtsao/unitest/logo/logo.svg "unitest")](https://github.com/rtsao/unitest)
2
3[![build status][build-badge]][build-href]
4[![dependencies status][deps-badge]][deps-href]
5[![npm version][npm-badge]][npm-href]
6
7Seamless node and browser unit testing with code coverage
8
9##### Features
10
11- Unified node and browser tests with merged TAP output, code coverage reports, and exit status codes.
12- [Electron](https://github.com/electron/electron)-powered browser testing for a fast, modern browser testing environment.
13- Bundler-agnostic usage. Use browserify, webpack, or something else.
14- Designed to be used with [Babel-powered coverage instrumentation](https://github.com/istanbuljs/babel-plugin-istanbul) for fast, efficient testing with code coverage.
15- Support for all coverage reporting options in [Istanbul](https://github.com/gotwarlost/istanbul), including `html`, `text`, `cobertura`, etc.
16
17
18## Usage
19```
20Usage: unitest {OPTIONS}
21
22Options:
23
24 --version, -v Print version and exit
25
26 --help, -h Print usage information
27
28 --node, -n Path to node test entry file
29
30 --browser, -c Path to browser test entry file
31
32 --report, -r Istanbul coverage report
33```
34
35## Getting Started
36
37### Run node and browser tests
38
391. Transpile source code with Babel *(optional)*
402. Bundle browser code *(this step is possibly optional since `require` works in electron)*
413. Run `unitest`, specifying test entry files
42
43```
44babel src -d build
45browserify build/test/browser.js > build/test/browser-bundle.js
46unitest --browser=build/test/browser-bundle.js --node=build/test/node.js
47```
48
49### Run node and browser tests with coverage report
50
51Running tests with coverage involves the exact same steps, but with an additional [coverage instrumentation Babel plugin](https://github.com/istanbuljs/babel-plugin-istanbul).
52
53```
54babel src -d build --plugins=istanbul
55browserify build/test/browser.js > build/test/browser-bundle.js
56unitest --browser=build/test/browser.js --node=build/test/node.js --report=html
57```
58
59#### Merged test output
60
61The separate TAP and coverage output along with exit code for your node and browser tests will be merged seamlessly.
62
63## Debugging
64
65### Debug node tests
66
67No magic here, just use [`node-inspector`](https://github.com/node-inspector/node-inspector) or plain node.
68
69```
70npm install node-inspector -g
71node-debug build/test/node.js
72```
73
74### Debug browser (electron) tests
75
76No magic here, just use [`devtool`](https://github.com/Jam3/devtool).
77
78```
79npm install devtool -g
80devtool build/test/browser-bundle.js
81```
82
83[build-badge]: https://travis-ci.org/rtsao/unitest.svg?branch=master
84[build-href]: https://travis-ci.org/rtsao/unitest
85[deps-badge]: https://david-dm.org/rtsao/unitest.svg
86[deps-href]: https://david-dm.org/rtsao/unitest
87[npm-badge]: https://badge.fury.io/js/unitest.svg
88[npm-href]: https://www.npmjs.com/package/unitest