Skip to content

Commit 91006bc

Browse files
committed
Finished up testing, bumped up to v1.1.1
1 parent c635889 commit 91006bc

File tree

7 files changed

+411
-72
lines changed

7 files changed

+411
-72
lines changed

.npmignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
test/
22
.git*
3+
npm-debug.log
34
.travis.yml
5+
node_modules/
6+
node_modules/*

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ _Note_: This requires `mocha`, `should`, `async`, and `underscore`.
143143
- Custom ordering of columns (see F.A.Q. for more information)
144144
- Ability to re-generate the JSON documents that were used to generate the CSV (including nested documents)
145145
- Allows for custom field delimiters, end of line delimiters, etc.
146+
- Promisifiable via bluebird's .promisify(<function) and .promisifyAll() (as of 1.1.1)
146147

147148
## F.A.Q.
148149

bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "json-2-csv",
3-
"version": "1.1.0",
3+
"version": "1.1.1",
44
"homepage": "https://github.com/mrodrig/json-2-csv",
55
"moduleType": [
66
"node"

package.json

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,7 @@
22
"author": "mrodrig",
33
"name": "json-2-csv",
44
"description": "A JSON to CSV and CSV to JSON converter that natively supports sub-documents and auto-generates the CSV heading.",
5-
<<<<<<< HEAD
6-
"version": "1.1.0",
7-
=======
8-
"version": "1.0.9",
9-
>>>>>>> Making the json2csv and csv2json functions promisifiable
5+
"version": "1.1.1",
106
"repository": {
117
"type": "git",
128
"url": "http://github.com/mrodrig/json-2-csv.git"
@@ -33,11 +29,10 @@
3329
"devDependencies": {
3430
"mocha": "~2.2.4",
3531
"should": "~5.2.0",
36-
"async": "~0.2.10",
37-
"bluebird": "~2.9.24"
32+
"async": "~0.2.10"
3833
},
3934
"engines": {
4035
"node": "*"
4136
},
4237
"license": "MIT"
43-
}
38+
}

test/testComma.js

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ var json2csvTests = function () {
367367
});
368368
});
369369

370-
it('should parse a single JSON document to CSV', function (done) {
370+
it('should parse an array of JSON documents to CSV', function (done) {
371371
converter.json2csvAsync(json_arrayValue, options)
372372
.then(function (csv) {
373373
csv.should.equal(csv_arrayValue);
@@ -379,6 +379,29 @@ var json2csvTests = function () {
379379
});
380380
});
381381

382+
it('should parse an array of JSON documents with the same schema but different ordering of fields', function (done) {
383+
converter.json2csvAsync(json_sameSchemaDifferentOrdering, options)
384+
.then(function (csv) {
385+
csv.should.equal(csv_regularJson);
386+
csv.split(options.EOL).length.should.equal(6);
387+
done();
388+
})
389+
.catch(function (err) {
390+
throw err;
391+
});
392+
});
393+
394+
it('should throw an error if the documents do not have the same schema', function (done) {
395+
converter.json2csvAsync(json_differentSchemas, options)
396+
.then(function (csv) {
397+
throw new Error('should not hit');
398+
})
399+
.catch(function (err) {
400+
err.message.should.equal('Not all documents have the same schema.');
401+
done();
402+
});
403+
});
404+
382405
it('should throw an error about not having been passed data - 1', function (done) {
383406
converter.json2csvAsync(null, options)
384407
.then(function (csv) {
@@ -475,7 +498,7 @@ var json2csvTests = function () {
475498
});
476499
});
477500

478-
it('should parse a single JSON document to CSV', function (done) {
501+
it('should parse an array of JSON documents to CSV', function (done) {
479502
converter.json2csvAsync(json_arrayValue)
480503
.then(function (csv) {
481504
csv.should.equal(csv_arrayValue.replace(/\//g, ';'));
@@ -487,6 +510,29 @@ var json2csvTests = function () {
487510
});
488511
});
489512

513+
it('should parse an array of JSON documents with the same schema but different ordering of fields', function (done) {
514+
converter.json2csvAsync(json_sameSchemaDifferentOrdering)
515+
.then(function (csv) {
516+
csv.should.equal(csv_regularJson);
517+
csv.split(options.EOL).length.should.equal(6);
518+
done();
519+
})
520+
.catch(function (err) {
521+
throw err;
522+
});
523+
});
524+
525+
it('should throw an error if the documents do not have the same schema', function (done) {
526+
converter.json2csvAsync(json_differentSchemas)
527+
.then(function (csv) {
528+
throw new Error('should not hit');
529+
})
530+
.catch(function (err) {
531+
err.message.should.equal('Not all documents have the same schema.');
532+
done();
533+
});
534+
});
535+
490536
it('should throw an error about not having been passed data - 1', function (done) {
491537
converter.json2csvAsync(null)
492538
.then(function (csv) {

test/testQuoted.js

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -246,10 +246,10 @@ var json2csvTests = function () {
246246
});
247247
});
248248

249-
it('should parse a single JSON document to CSV', function (done) {
249+
it('should parse an array of JSON documents to CSV', function (done) {
250250
converter.json2csvAsync(json_arrayValue, options)
251251
.then(function (csv) {
252-
csv.should.equal(csv_arrayValue);
252+
csv.should.equal(csv_arrayValue.replace(/,/g, options.DELIMITER.FIELD));
253253
csv.split(options.EOL).length.should.equal(5);
254254
done();
255255
})
@@ -258,6 +258,29 @@ var json2csvTests = function () {
258258
});
259259
});
260260

261+
it('should parse an array of JSON documents with the same schema but different ordering of fields', function (done) {
262+
converter.json2csvAsync(json_sameSchemaDifferentOrdering, options)
263+
.then(function (csv) {
264+
csv.should.equal(csv_regularJson);
265+
csv.split(options.EOL).length.should.equal(6);
266+
done();
267+
})
268+
.catch(function (err) {
269+
throw err;
270+
});
271+
});
272+
273+
it('should throw an error if the documents do not have the same schema', function (done) {
274+
converter.json2csvAsync(json_differentSchemas, options)
275+
.then(function (csv) {
276+
throw new Error('should not hit');
277+
})
278+
.catch(function (err) {
279+
err.message.should.equal('Not all documents have the same schema.');
280+
done();
281+
});
282+
});
283+
261284
it('should throw an error about not having been passed data - 1', function (done) {
262285
converter.json2csvAsync(null, options)
263286
.then(function (csv) {

0 commit comments

Comments
 (0)