File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 22
33var util = require ( 'util' ) ;
44
5- module . exports = function ( opts ) {
5+ module . exports = function ( options ) {
6+ var opts = util . _extend ( {
7+ lineBreaks : true ,
8+ indent : ' '
9+ } , options ) ;
10+
611 var code = [ ] ;
712
813 if ( this . source . postData ) {
@@ -30,5 +35,5 @@ module.exports = function (opts) {
3035 } ) ;
3136 }
3237
33- return code . join ( ' \\\n ' ) ;
38+ return code . join ( opts . lineBreaks ? ' \\\n' + opts . indent : ' ') ;
3439} ;
Original file line number Diff line number Diff line change 1+ 'use strict' ;
2+
3+ var fixtures = require ( '../fixtures' ) ;
4+ var HTTPSnippet = require ( '../../src' ) ;
5+
6+ require ( 'should' ) ;
7+
8+ describe ( 'httpie' , function ( ) {
9+ it ( 'should convert simple request to httpie command' , function ( done ) {
10+ var result = new HTTPSnippet ( fixtures . simple ) . httpie ( {
11+ lineBreaks : false
12+ } ) ;
13+
14+ result . should . be . a . String ;
15+ result . should . eql ( 'echo "{\\"foo\\": \\"bar\\"}" | http POST httpconsole.com/debug Content-Type:application/json Content-Type:application/json' ) ;
16+
17+ done ( ) ;
18+ } ) ;
19+
20+ it ( 'should use custom indentation' , function ( done ) {
21+ var result = new HTTPSnippet ( fixtures . simple ) . httpie ( {
22+ lineBreaks : true ,
23+ indent : '@'
24+ } ) ;
25+
26+ result . should . be . a . String ;
27+ result . replace ( / \\ \n / g, '' ) . should . eql ( 'echo "{\\"foo\\": \\"bar\\"}" | @http POST httpconsole.com/debug @Content-Type:application/json @Content-Type:application/json' ) ;
28+
29+ done ( ) ;
30+ } ) ;
31+ } ) ;
You can’t perform that action at this time.
0 commit comments