Skip to content

Commit

Permalink
Fix #9
Browse files Browse the repository at this point in the history
  • Loading branch information
jczaplew committed Jul 26, 2017
1 parent efc8a22 commit c3e7bb6
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/csv-express.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ res.csv = function(data, csvHeaders, headers, status) {

// Append the header row to the response if requested
if (csvHeaders) {
body += headerRow + '\r\n';
body += headerRow.join(exports.separator) + '\r\n';
}

// Convert the data to a CSV-like structure
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "csv-express",
"description": "Adds a CSV response method to expressjs applications.",
"version": "1.2.1",
"version": "1.2.2",
"author": "John J Czaplewski (forked from Seiya Konno)",
"contributors": [
{
Expand Down
25 changes: 25 additions & 0 deletions test/2/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,14 @@ app.get('/test/cyrillic/cp1251', function(req, res) {
]);
});

app.get('/test/separator', function(req, res) {
csv.separator = '|'
res.csv([
{ foo: "a", bar: 1 },
{ foo: "b", bar: 2}
], true);
});

app.listen(8383);

describe('csv-express', function() {
Expand Down Expand Up @@ -281,3 +289,20 @@ describe('when given cyrillyc data', function() {
});
});
});

describe('when pipe-delimited', function() {
it('should output a pipe-delimited file', function(done) {
request
.get('http://127.0.0.1:8383/test/separator')
.end(function(error, res) {
var responseBody = res.text.split('\r\n')
var rows = responseBody.map(function(row) {
return row.split('|')
})
// Make sure the header row uses the provided delimeter
rows[0].length.should.equal(2)
rows[0][0].should.equal('foo')
done();
});
});
});
25 changes: 25 additions & 0 deletions test/3+/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,14 @@ app.get('/test/cyrillic/cp1251', function(req, res) {
]);
});

app.get('/test/separator', function(req, res) {
csv.separator = '|'
res.csv([
{ foo: "a", bar: 1 },
{ foo: "b", bar: 2}
], true);
});

app.listen(8383);

describe('csv-express', function() {
Expand Down Expand Up @@ -284,3 +292,20 @@ describe('when given cyrillyc data', function() {
});
});
});

describe('when pipe-delimited', function() {
it('should output a pipe-delimited file', function(done) {
request
.get('http://127.0.0.1:8383/test/separator')
.end(function(error, res) {
var responseBody = res.text.split('\r\n')
var rows = responseBody.map(function(row) {
return row.split('|')
})
// Make sure the header row uses the provided delimeter
rows[0].length.should.equal(2)
rows[0][0].should.equal('foo')
done();
});
});
});

0 comments on commit c3e7bb6

Please sign in to comment.