Skip to content

Commit 277af1b

Browse files
committed
httpie accepts custom indent options + tests
1 parent 73be04a commit 277af1b

2 files changed

Lines changed: 38 additions & 2 deletions

File tree

‎src/targets/httpie.js‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,12 @@
22

33
var 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
};

‎test/targets/httpie.js‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
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+
});

0 commit comments

Comments
 (0)