Skip to content

Commit

Permalink
Added nodeunit dependency, first dummy test passes and script for run…
Browse files Browse the repository at this point in the history
…ning tests.
  • Loading branch information
yin committed Dec 31, 2013
1 parent a53aea1 commit f2e4caf
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 7 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
"bitstamp": "0.1.x",
"async": "0.2.x",
"nedb": "*",
"line-reader": "0.2.x"
"line-reader": "0.2.x",
"nodeunit": "0.8.2"
},
"engines": { "node": "0.10.x" },
"repository": {
Expand Down
5 changes: 5 additions & 0 deletions scripts/run_unit_tests
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env node

var nodeunit = require('nodeunit');
var reporter = nodeunit.reporters.default;
reporter.run(['test']);
47 changes: 41 additions & 6 deletions test/csv.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,50 @@
var fs = require('fs');
var zlib = require('zlib');
var async = require('async');

var TMPDIR = "./tmp/"
var TMPDIR = "./tmp/";
var CSVFILE = TMPDIR + "test.csv";

exports = {
function deflate(file, data, next) {
zlib.deflate(data, function(err, buffer) { next(err, file, buffer) });
}

function save(file, buffer, next) {
console.log("save", file, buffer, !!next);
fs.writeFile(file, buffer, function(err) { next(err); });
}

function cleanUp(path, next) {
if( fs.existsSync(path) ) {
var files = [];
files = fs.readdirSync(path);
files.forEach(function(file,index){
var curPath = path + "/" + file;
if(fs.statSync(curPath).isDirectory()) {
// recurse
cleanUp(curPath);
} else {
// delete file
fs.unlinkSync(curPath);
}
});
fs.rmdirSync(path);
}
next(null, path);
}

module.exports = {
setUp: function(done) {
var data = "1,2,3,4,5\n10,20,30,40,50";
fs.existsSync(TMPDIR) || fs.mkdir(TMPDIR);
fs.writeFile(CSVFLE, data, done);
fs.existsSync(TMPDIR) || fs.mkdirSync(TMPDIR);
async.compose(save, deflate)(CSVFILE, data, done);
},
tearDown: function(done) {
fs.existsSync(TMPDIR) && fs.rm(TMPDIR);
}
fs.existsSync(TMPDIR) && cleanUp(TMPDIR, done);
},
test_nodeunit: function(test) {
console.log("Nodeunit invoked, Great!");
test.ok(true);
test.done();
},
};

0 comments on commit f2e4caf

Please sign in to comment.