1 | power-assert-formatter
|
2 | ================================
|
3 |
|
4 | [![Build Status][travis-image]][travis-url]
|
5 | [![NPM package][npm-image]][npm-url]
|
6 | [![Bower package][bower-image]][bower-url]
|
7 | [![Dependency Status][depstat-image]][depstat-url]
|
8 | [![Coverage Status][coverage-image]][coverage-url]
|
9 | [![Code Climate][codeclimate-image]][codeclimate-url]
|
10 | [![License][license-image]][license-url]
|
11 | [![Built with Gulp][gulp-image]][gulp-url]
|
12 |
|
13 | Power Assert output formatter.
|
14 |
|
15 |
|
16 | DESCRIPTION
|
17 | ---------------------------------------
|
18 | `power-assert-formatter` is a formatter module for Power Assert output.
|
19 |
|
20 | Pull-requests, issue reports and patches are always welcomed. See [power-assert](http://github.com/power-assert-js/power-assert) project for more documentation.
|
21 |
|
22 |
|
23 | CHANGELOG
|
24 | ---------------------------------------
|
25 | See [CHANGELOG](https://github.com/power-assert-js/power-assert-formatter/blob/master/CHANGELOG.md)
|
26 |
|
27 |
|
28 | API
|
29 | ---------------------------------------
|
30 |
|
31 | ### var createFormatter = require('power-assert-formatter');
|
32 |
|
33 | | return type |
|
34 | |:------------|
|
35 | | `function` |
|
36 |
|
37 | Returns creator function for power-assert.
|
38 |
|
39 | ### var formatter = createFormatter([options]);
|
40 |
|
41 | | return type |
|
42 | |:------------|
|
43 | | `function` |
|
44 |
|
45 | Create formatter function with options. `options` argument is optional.
|
46 |
|
47 | #### options
|
48 |
|
49 | | type | default value |
|
50 | |:---------|:--------------|
|
51 | | `object` | (return value of `createFormatter.defaultOptions()`) |
|
52 |
|
53 | Configuration options. If not passed, default options will be used.
|
54 |
|
55 | #### options.lineDiffThreshold
|
56 |
|
57 | | type | default value |
|
58 | |:---------|:--------------|
|
59 | | `number` | `5` |
|
60 |
|
61 | 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.
|
62 |
|
63 | #### options.maxDepth
|
64 |
|
65 | | type | default value |
|
66 | |:---------|:--------------|
|
67 | | `number` | `1` |
|
68 |
|
69 | 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#]`.
|
70 |
|
71 | #### options.outputOffset
|
72 |
|
73 | | type | default value |
|
74 | |:---------|:--------------|
|
75 | | `number` | `2` |
|
76 |
|
77 | Number of spaces inserted at the left in power-assert output.
|
78 |
|
79 | #### options.anonymous
|
80 |
|
81 | | type | default value |
|
82 | |:---------|:--------------|
|
83 | | `string` | `"Object"` |
|
84 |
|
85 | Type name to show when target object is created by anonymous constructor.
|
86 |
|
87 | #### options.circular
|
88 |
|
89 | | type | default value |
|
90 | |:---------|:----------------|
|
91 | | `string` | `"#@Circular#"` |
|
92 |
|
93 | Name to show when target object is detected as circular structure.
|
94 |
|
95 | #### options.lineSeparator
|
96 |
|
97 | | type | default value |
|
98 | |:---------|:--------------|
|
99 | | `string` | `"\n"` |
|
100 |
|
101 | Line separator in power assert output.
|
102 |
|
103 | #### options.ambiguousEastAsianCharWidth
|
104 |
|
105 | | type | default value |
|
106 | |:---------|:--------------|
|
107 | | `number` | `2` |
|
108 |
|
109 | Width of 'Ambiguous' characters defined in [Unicode Standard Annex \#11 EAST ASIAN WIDTH](http://www.unicode.org/reports/tr11/#Ambiguous). Configure `options.ambiguousEastAsianCharWidth` to treat ambiguous east asian character as fullwidth (= `2`) or narrow (= `1`). Default is `2`.
|
110 |
|
111 | #### options.widthOf
|
112 |
|
113 | | type | default value |
|
114 | |:-----------|:--------------|
|
115 | | `function` | [string-width.js](https://github.com/power-assert-js/power-assert-formatter/blob/master/lib/string-width.js) |
|
116 |
|
117 | Function to calculate width of string.
|
118 |
|
119 | #### options.stringify
|
120 |
|
121 | | type | default value |
|
122 | |:-----------|:--------------|
|
123 | | `function` | [stringifier module](https://github.com/twada/stringifier) |
|
124 |
|
125 | Function to stringify any target value.
|
126 |
|
127 | #### options.diff
|
128 |
|
129 | | type | default value |
|
130 | |:-----------|:--------------|
|
131 | | `function` | [udiff.js](https://github.com/power-assert-js/power-assert-formatter/blob/master/lib/udiff.js) |
|
132 |
|
133 | Function to create diff string between two strings.
|
134 |
|
135 | #### options.writerClass
|
136 |
|
137 | | type | default value |
|
138 | |:-----------|:--------------|
|
139 | | `function` | [string-writer.js](https://github.com/power-assert-js/power-assert-formatter/blob/master/lib/string-writer.js) |
|
140 |
|
141 | Constructor Function for output writer class.
|
142 |
|
143 | #### options.renderers
|
144 |
|
145 | | type | default value |
|
146 | |:------------------------------------|:--------------|
|
147 | | `Array` of (`string` or `function` )| shown below |
|
148 |
|
149 | ```javascript
|
150 | [
|
151 | './built-in/file',
|
152 | './built-in/assertion',
|
153 | './built-in/diagram',
|
154 | './built-in/binary-expression'
|
155 | ]
|
156 | ```
|
157 |
|
158 | Output renderers. Power assert output is rendered by renderers in order. You can create custom renderer and add its constructor function to customize power-assert-output.
|
159 |
|
160 | ```javascript
|
161 | [
|
162 | './built-in/file',
|
163 | './built-in/assertion',
|
164 | YourCustomRenderer,
|
165 | './built-in/binary-expression'
|
166 | ]
|
167 | ```
|
168 |
|
169 |
|
170 | ### var options = createFormatter.defaultOptions();
|
171 |
|
172 | Returns default options object for createFormatter function. In other words, returns
|
173 |
|
174 | ```javascript
|
175 | {
|
176 | lineDiffThreshold: 5,
|
177 | maxDepth: 1,
|
178 | anonymous: 'Object',
|
179 | circular: '#@Circular#',
|
180 | lineSeparator: '\n',
|
181 | ambiguousEastAsianCharWidth: 2,
|
182 | renderers: [
|
183 | './built-in/file',
|
184 | './built-in/assertion',
|
185 | './built-in/diagram',
|
186 | './built-in/binary-expression'
|
187 | ]
|
188 | };
|
189 | ```
|
190 |
|
191 |
|
192 | ### var formattedText = formatter(powerAssertContext);
|
193 |
|
194 | | return type |
|
195 | |:------------|
|
196 | | `string` |
|
197 |
|
198 | Format `powerAssertContext` into `formattedText`. `powerAssertContext` is an internal object structure, containing informations to render. Example of `powerAssertContext` is:
|
199 |
|
200 | ```javascript
|
201 | {
|
202 | source: {
|
203 | content: "assert.equal(foo, bar)",
|
204 | filepath: "/path/to/some_test.js",
|
205 | line: 1
|
206 | },
|
207 | args: [
|
208 | {
|
209 | value: "foo",
|
210 | events: [
|
211 | {
|
212 | value: "foo",
|
213 | espath: "arguments/0"
|
214 | }
|
215 | ]
|
216 | },
|
217 | {
|
218 | value: "bar",
|
219 | events: [
|
220 | {
|
221 | value: "bar",
|
222 | espath: "arguments/1"
|
223 | }
|
224 | ]
|
225 | }
|
226 | ]
|
227 | }
|
228 | ```
|
229 |
|
230 | Note that structure of powerAssertContext may change.
|
231 |
|
232 |
|
233 | INSTALL
|
234 | ---------------------------------------
|
235 |
|
236 | ### via npm
|
237 |
|
238 | Install
|
239 |
|
240 | $ npm install --save-dev power-assert-formatter
|
241 |
|
242 |
|
243 | #### use power-assert-formatter npm module on browser
|
244 |
|
245 | `powerAssertFormatter` function is exported
|
246 |
|
247 | <script type="text/javascript" src="./path/to/node_modules/power-assert-formatter/build/power-assert-formatter.js"></script>
|
248 |
|
249 |
|
250 | ### via bower
|
251 |
|
252 | Install
|
253 |
|
254 | $ bower install --save-dev power-assert-formatter
|
255 |
|
256 | Then load (`powerAssertFormatter` function is exported)
|
257 |
|
258 | <script type="text/javascript" src="./path/to/bower_components/power-assert-formatter/build/power-assert-formatter.js"></script>
|
259 |
|
260 |
|
261 | AUTHOR
|
262 | ---------------------------------------
|
263 | * [Takuto Wada](http://github.com/twada)
|
264 |
|
265 |
|
266 | CONTRIBUTORS
|
267 | ---------------------------------------
|
268 | * [James Talmage (jamestalmage)](https://github.com/jamestalmage)
|
269 |
|
270 |
|
271 | LICENSE
|
272 | ---------------------------------------
|
273 | Licensed under the [MIT](https://github.com/power-assert-js/power-assert-formatter/blob/master/MIT-LICENSE.txt) license.
|
274 |
|
275 |
|
276 | [npm-url]: https://npmjs.org/package/power-assert-formatter
|
277 | [npm-image]: https://badge.fury.io/js/power-assert-formatter.svg
|
278 |
|
279 | [bower-url]: http://badge.fury.io/bo/power-assert-formatter
|
280 | [bower-image]: https://badge.fury.io/bo/power-assert-formatter.svg
|
281 |
|
282 | [travis-url]: http://travis-ci.org/power-assert-js/power-assert-formatter
|
283 | [travis-image]: https://secure.travis-ci.org/power-assert-js/power-assert-formatter.svg?branch=master
|
284 |
|
285 | [depstat-url]: https://gemnasium.com/power-assert-js/power-assert-formatter
|
286 | [depstat-image]: https://gemnasium.com/power-assert-js/power-assert-formatter.svg
|
287 |
|
288 | [license-url]: https://github.com/power-assert-js/power-assert-formatter/blob/master/MIT-LICENSE.txt
|
289 | [license-image]: http://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat
|
290 |
|
291 | [codeclimate-url]: https://codeclimate.com/github/power-assert-js/power-assert-formatter
|
292 | [codeclimate-image]: https://codeclimate.com/github/power-assert-js/power-assert-formatter/badges/gpa.svg
|
293 |
|
294 | [coverage-url]: https://coveralls.io/r/power-assert-js/power-assert-formatter?branch=master
|
295 | [coverage-image]: https://coveralls.io/repos/power-assert-js/power-assert-formatter/badge.svg?branch=master
|
296 |
|
297 | [gulp-url]: http://gulpjs.com/
|
298 | [gulp-image]: http://img.shields.io/badge/built_with-gulp-brightgreen.svg
|