From be26be07614f315ec29f3fbacf80e5920cbf79d9 Mon Sep 17 00:00:00 2001 From: Kelly Selden Date: Thu, 31 Dec 2015 15:34:13 -0500 Subject: [PATCH] adding acceptance test --- .gitignore | 1 + appveyor.yml | 4 +++ package.json | 6 ++-- test/acceptance/to-csv-test.js | 50 ++++++++++++++++++++++++++++++++++ test/acceptance/to-csv.js | 12 -------- to-csv.js | 4 ++- 6 files changed, 62 insertions(+), 15 deletions(-) create mode 100644 test/acceptance/to-csv-test.js delete mode 100644 test/acceptance/to-csv.js diff --git a/.gitignore b/.gitignore index ba2a97b..efb4937 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ node_modules coverage +tmp diff --git a/appveyor.yml b/appveyor.yml index 3c321c3..bd22d12 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -13,6 +13,10 @@ platform: - x86 - x64 +# Fix line endings in Windows. (runs before repo cloning) +init: + - git config --global core.autocrlf true + # Install scripts. (runs after repo cloning) install: - ps: Install-Product node $env:nodejs_version $env:platform diff --git a/package.json b/package.json index 6d39f13..da84e80 100644 --- a/package.json +++ b/package.json @@ -4,8 +4,8 @@ "description": "JSON to CSV and vice-versa for ember-i18n", "main": "to-csv.js", "scripts": { - "test": "mocha test/acceptance/*.js", - "cover": "istanbul cover node_modules/mocha/bin/_mocha -- test/acceptance/*.js" + "test": "mocha test/**/*-test.js", + "cover": "istanbul cover node_modules/mocha/bin/_mocha -- test/**/*-test.js" }, "repository": { "type": "git", @@ -17,9 +17,11 @@ "6to5": "^3.5.3", "csv-parse": "0.0.6", "csv-stringify": "0.0.6", + "eol": "0.2.0", "yargs": "^3.0.0" }, "devDependencies": { + "chai": "^3.0.0", "coveralls": "^2.0.0", "istanbul": "0.4.1", "mocha": "^2.0.0" diff --git a/test/acceptance/to-csv-test.js b/test/acceptance/to-csv-test.js new file mode 100644 index 0000000..662cb2d --- /dev/null +++ b/test/acceptance/to-csv-test.js @@ -0,0 +1,50 @@ +var expect = require('chai').expect; +var test = require('../../lib/test'); +var spawn = require('child_process').spawn; +var path = require('path'); +var fs = require('fs'); + +describe('Array', function() { + describe('#indexOf()', function() { + it('should return -1 when the value is not present', function() { + test(); + expect([1,2,3].indexOf(5)).to.equal(-1); + expect([1,2,3].indexOf(0)).to.equal(-1); + }); + }); +}); + +describe('to-csv', function() { + it('should return -1 when the value is not present', function(done) { + // process.chdir(__dirname); + + fs.mkdir('tmp', function(err) { + expect(err).to.be.falsy; + + var ps = spawn(process.execPath, [ + // path.resolve(__dirname, '../bin/cmd.js'), + 'to-csv', + 'test/fixtures/locales', + 'tmp/i18n.csv', + ]); + + var out = ''; + var err = ''; + ps.stdout.on('data', function(buffer) { out += buffer; }); + ps.stderr.on('data', function(buffer) { err += buffer; }); + + ps.on('exit', function(code) { + fs.readFile('tmp/i18n.csv', 'utf-8', function(err, actual) { + expect(err).to.be.falsy; + fs.readFile('test/fixtures/i18n.csv', 'utf-8', function(err, expected) { + expect(err).to.be.falsy; + expect(actual).to.equal(expected); + done(); + }); + }); + expect(err).to.be.falsy; + expect(code).to.equal(0); + }); + }); + }); +}); diff --git a/test/acceptance/to-csv.js b/test/acceptance/to-csv.js deleted file mode 100644 index 92ba061..0000000 --- a/test/acceptance/to-csv.js +++ /dev/null @@ -1,12 +0,0 @@ -var assert = require('assert'); -var test = require('../../lib/test'); - -describe('Array', function() { - describe('#indexOf()', function () { - it('should return -1 when the value is not present', function () { - test(); - assert.equal(-1, [1,2,3].indexOf(5)); - assert.equal(-1, [1,2,3].indexOf(0)); - }); - }); -}); diff --git a/to-csv.js b/to-csv.js index 41adaac..b5992ca 100644 --- a/to-csv.js +++ b/to-csv.js @@ -1,6 +1,7 @@ var fs = require('fs'); var path = require('path'); var stringify = require('csv-stringify'); +var eol = require('eol'); var argv = require('yargs').argv; require('6to5/register'); @@ -62,5 +63,6 @@ for (var i in keys) { } stringify(lines, function(err, csv) { - fs.writeFileSync(csvPath, csv); + var normalized = eol.auto(csv); + fs.writeFileSync(csvPath, normalized); });