Skip to content

Commit 1b6def9

Browse files
committed
nodejs test
1 parent 75b22c0 commit 1b6def9

2 files changed

Lines changed: 19 additions & 1 deletion

File tree

‎src/targets/node.js‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ module.exports = function (options) {
3030

3131
code.push(null);
3232

33-
code.push(util.format('var options = %s;', JSON.stringify(reqOpts, null, 2)));
33+
code.push(util.format('var options = %s;', JSON.stringify(reqOpts, null, opts.indent)));
3434

3535
code.push(null);
3636

@@ -59,6 +59,7 @@ module.exports = function (options) {
5959
code.push('req.end();');
6060

6161
code.push(null);
62+
6263
return code.join('\n');
6364
};
6465

‎test/targets/nodejs.js‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
'use strict';
2+
3+
var fixtures = require('../fixtures');
4+
var HTTPSnippet = require('../../src');
5+
var should = require('should');
6+
7+
describe('Node.js', function () {
8+
it('should convert full request to cURL command', function (done) {
9+
var result = new HTTPSnippet(fixtures.full).node({
10+
indent: '\t'
11+
});
12+
13+
result.replace(/\n/g, '').should.eql('var http = require("http");var options = {\t"method": "POST",\t"hostname": "httpconsole.com",\t"port": null,\t"path": "/debug?baz=abc&foo=bar&foo=baz",\t"headers": {\t\t"Accept": "text/plain",\t\t"Content-Type": "application/json",\t\t"X-Pretty-Print": "2",\t\t"Cookie": "foo=bar; bar=baz"\t}};var req = http.request(options, function (res) {\tvar chunks = [];\tres.on("data", function (chunk) {\t\tchunks.push(chunk);\t});\tres.on("end", function () {\t\tvar body = Buffer.concat(chunks);\t});});req.write("{\\"foo\\": \\"bar\\"}")req.end();');
14+
15+
done();
16+
});
17+
});

0 commit comments

Comments
 (0)