1 | power-assert-formatter
|
2 | ================================
|
3 |
|
4 | [![Build Status](https://travis-ci.org/twada/power-assert-formatter.svg?branch=master)](https://travis-ci.org/twada/power-assert-formatter)
|
5 | [![NPM version](https://badge.fury.io/js/power-assert-formatter.svg)](http://badge.fury.io/js/power-assert-formatter)
|
6 | [![Dependency Status](https://gemnasium.com/twada/power-assert-formatter.svg)](https://gemnasium.com/twada/power-assert-formatter)
|
7 | [![Coverage Status](https://coveralls.io/repos/twada/power-assert-formatter/badge.png?branch=master)](https://coveralls.io/r/twada/power-assert-formatter?branch=master)
|
8 | [![Code Climate](https://codeclimate.com/github/twada/power-assert-formatter/badges/gpa.svg)](https://codeclimate.com/github/twada/power-assert-formatter)
|
9 | [![License](http://img.shields.io/badge/license-MIT-brightgreen.svg)](https://github.com/twada/power-assert-formatter/blob/master/MIT-LICENSE.txt)
|
10 | [![Built with Gulp](http://img.shields.io/badge/built_with-gulp-brightgreen.svg)](http://gulpjs.com/)
|
11 |
|
12 | Power Assert output formatter.
|
13 |
|
14 |
|
15 | DESCRIPTION
|
16 | ---------------------------------------
|
17 | `power-assert-formatter` is a formatter for Power Assert output.
|
18 |
|
19 | Please note that `power-assert-formatter` is a beta version product. Pull-requests, issue reports and patches are always welcomed. See [power-assert](http://github.com/twada/power-assert) project for more documentation.
|
20 |
|
21 |
|
22 | CHANGELOG
|
23 | ---------------------------------------
|
24 | See [CHANGELOG](https://github.com/twada/power-assert-formatter/blob/master/CHANGELOG.md)
|
25 |
|
26 |
|
27 | API
|
28 | ---------------------------------------
|
29 |
|
30 | ### var createFormatter = require('power-assert-formatter');
|
31 |
|
32 | | return type |
|
33 | |:------------|
|
34 | | `function` |
|
35 |
|
36 | Returns formatter creator function for power-assert.
|
37 |
|
38 | ### var formatter = createFormatter([options]);
|
39 |
|
40 | | return type |
|
41 | |:------------|
|
42 | | `function` |
|
43 |
|
44 | Create formatter function with options. `options` argument is optional.
|
45 |
|
46 | #### options
|
47 |
|
48 | | type | default value |
|
49 | |:---------|:--------------|
|
50 | | `object` | (return value of `createFormatter.defaultOptions()`) |
|
51 |
|
52 | Configuration options. If not passed, default options will be used.
|
53 |
|
54 | #### options.lineDiffThreshold
|
55 |
|
56 | | type | default value |
|
57 | |:---------|:--------------|
|
58 | | `number` | `5` |
|
59 |
|
60 | Threshold to show diff at character level or line level. If number of lines in target string is greater than `lineDiffThreshold`, then line diff mode will be used to show diff output.
|
61 |
|
62 | #### options.maxDepth
|
63 |
|
64 | | type | default value |
|
65 | |:---------|:--------------|
|
66 | | `number` | `1` |
|
67 |
|
68 | Depth of object traversal. If object depth is greater than `maxDepth`, compound object (IOW, `Array` or `object`) will be pruned with `#` like `["foo",#Array#,#Object#]`.
|
69 |
|
70 | #### options.anonymous
|
71 |
|
72 | | type | default value |
|
73 | |:---------|:--------------|
|
74 | | `string` | `"Object"` |
|
75 |
|
76 | Type name to show if target object is created by anonymous constructor.
|
77 |
|
78 | #### options.circular
|
79 |
|
80 | | type | default value |
|
81 | |:---------|:----------------|
|
82 | | `string` | `"#@Circular#"` |
|
83 |
|
84 | Name to show if target object is detected as circular structure.
|
85 |
|
86 | #### options.lineSeparator
|
87 |
|
88 | | type | default value |
|
89 | |:---------|:--------------|
|
90 | | `string` | `"\n"` |
|
91 |
|
92 | Line separator to use in power assert output.
|
93 |
|
94 | #### options.widthOf
|
95 |
|
96 | | type | default value |
|
97 | |:-----------|:--------------|
|
98 | | `function` | [string-width.js](https://github.com/twada/power-assert-formatter/blob/master/lib/string-width.js) |
|
99 |
|
100 | Function to calculate width of string.
|
101 |
|
102 | #### options.stringify
|
103 |
|
104 | | type | default value |
|
105 | |:-----------|:--------------|
|
106 | | `function` | [stringifier module](https://github.com/twada/stringifier) |
|
107 |
|
108 | Function to stringify any target value.
|
109 |
|
110 | #### options.writerClass
|
111 |
|
112 | | type | default value |
|
113 | |:-----------|:--------------|
|
114 | | `function` | [string-writer.js](https://github.com/twada/power-assert-formatter/blob/master/lib/string-writer.js) |
|
115 |
|
116 | Constructor Function for output writer class.
|
117 |
|
118 | #### options.renderers
|
119 |
|
120 | | type | default value |
|
121 | |:------------------------------------|:--------------|
|
122 | | `Array` of (`string` or `function` )| shown below |
|
123 |
|
124 | ```javascript
|
125 | [
|
126 | './built-in/file',
|
127 | './built-in/assertion',
|
128 | './built-in/diagram',
|
129 | './built-in/binary-expression'
|
130 | ]
|
131 | ```
|
132 |
|
133 | Output renderers to use. Output is rendered by renderers in order. You can create custom renderer and add its constructor function to customize power-assert-output.
|
134 |
|
135 | ```javascript
|
136 | [
|
137 | './built-in/file',
|
138 | './built-in/assertion',
|
139 | YourCustomRenderer,
|
140 | './built-in/binary-expression'
|
141 | ]
|
142 | ```
|
143 |
|
144 |
|
145 | ### var options = createFormatter.defaultOptions();
|
146 |
|
147 | Returns default options object for createFormatter function. In other words, returns
|
148 |
|
149 | ```javascript
|
150 | module.exports = function defaultOptions () {
|
151 | 'use strict';
|
152 | return {
|
153 | lineDiffThreshold: 5,
|
154 | maxDepth: 1,
|
155 | anonymous: 'Object',
|
156 | circular: '#@Circular#',
|
157 | lineSeparator: '\n',
|
158 | renderers: [
|
159 | './built-in/file',
|
160 | './built-in/assertion',
|
161 | './built-in/diagram',
|
162 | './built-in/binary-expression'
|
163 | ]
|
164 | };
|
165 | };
|
166 | ```
|
167 |
|
168 |
|
169 | ### var formattedText = formatter(powerAssertContext);
|
170 |
|
171 | | return type |
|
172 | |:------------|
|
173 | | `string` |
|
174 |
|
175 | Format `powerAssertContext` into `formattedText`. `powerAssertContext` is an internal object structure, containing informations to render. Example of `powerAssertContext` is:
|
176 |
|
177 | ```javascript
|
178 | {
|
179 | source: {
|
180 | content: "assert.equal(foo, bar)",
|
181 | filepath: "/path/to/some_test.js",
|
182 | line: 1
|
183 | },
|
184 | args: [
|
185 | {
|
186 | value: "foo",
|
187 | events: [
|
188 | {
|
189 | value: "foo",
|
190 | espath: "arguments/0"
|
191 | }
|
192 | ]
|
193 | },
|
194 | {
|
195 | value: "bar",
|
196 | events: [
|
197 | {
|
198 | value: "bar",
|
199 | espath: "arguments/1"
|
200 | }
|
201 | ]
|
202 | }
|
203 | ]
|
204 | }
|
205 | ```
|
206 |
|
207 | Note that structure of powerAssertContext may change.
|
208 |
|
209 |
|
210 | INSTALL
|
211 | ---------------------------------------
|
212 |
|
213 | ### via npm
|
214 |
|
215 | Install
|
216 |
|
217 | $ npm install --save-dev power-assert-formatter
|
218 |
|
219 |
|
220 | ### via bower
|
221 |
|
222 | Install
|
223 |
|
224 | $ bower install --save-dev power-assert-formatter
|
225 |
|
226 | Then load (`powerAssertFormatter` function is exported)
|
227 |
|
228 | <script type="text/javascript" src="./path/to/bower_components/power-assert-formatter/build/power-assert-formatter.js"></script>
|
229 |
|
230 |
|
231 | AUTHOR
|
232 | ---------------------------------------
|
233 | * [Takuto Wada](http://github.com/twada)
|
234 |
|
235 |
|
236 | LICENSE
|
237 | ---------------------------------------
|
238 | Licensed under the [MIT](https://github.com/twada/power-assert-formatter/blob/master/MIT-LICENSE.txt) license.
|