diff --git a/index.coffee b/index.coffee index 39195eb..3a9d21a 100644 --- a/index.coffee +++ b/index.coffee @@ -5,4 +5,8 @@ copy = require('./lib/copy') fs.copyFileSync = copy.copyFileSync fs.copyFile = copy.copyFile +remove = require('./lib/remove') +fs.rmrfSync = remove.rmrfSync +fs.rmrf = remove.rmrf + module.exports = fs \ No newline at end of file diff --git a/lib/remove.coffee b/lib/remove.coffee new file mode 100644 index 0000000..e1c4229 --- /dev/null +++ b/lib/remove.coffee @@ -0,0 +1,10 @@ +rimraf = require('rimraf') + +rmrfSync = (dir) -> + rimraf.sync(dir) + +rmrf = (dir,cb) -> + rimraf(dir,cb) + +module.exports.rmrfSync = rmrfSync +module.exports.rmrf = rmrf \ No newline at end of file diff --git a/spec/copy.spec.coffee b/test/copy.test.coffee similarity index 86% rename from spec/copy.spec.coffee rename to test/copy.test.coffee index 59dd87e..ab6d244 100644 --- a/spec/copy.spec.coffee +++ b/test/copy.test.coffee @@ -20,7 +20,7 @@ buildBuffer = (size) -> bytesWritten += buf.write(d.substring(0,4), bytesWritten) buf -describe 'fs-extra', -> +describe 'fs-extra: copy', -> describe 'copyFileSync', -> it 'should copy synchronously', -> @@ -40,7 +40,7 @@ describe 'fs-extra', -> describe 'copyFile', -> - it 'should copy asynchronously', -> + it 'should copy asynchronously', (done) -> buf = buildBuffer(16*64*1024+7) ex = Date.now() fileSrc = path.join(path.tempdir(), "TEST_fs-extra_write-#{ex}") @@ -52,13 +52,14 @@ describe 'fs-extra', -> destMd5 = '' - runs -> - fs.copyFile fileSrc, fileDest, (err) -> - destMd5 = crypto.createHash('md5').update(fs.readFileSync(fileDest)).digest("hex") - waitsFor -> destMd5 isnt '' - runs -> + fs.copyFile fileSrc, fileDest, (err) -> + destMd5 = crypto.createHash('md5').update(fs.readFileSync(fileDest)).digest("hex") T bufMd5 is destMd5 T srcMd5 is destMd5 + done() + + + diff --git a/test/mocha.opts b/test/mocha.opts new file mode 100644 index 0000000..d7e33fb --- /dev/null +++ b/test/mocha.opts @@ -0,0 +1,3 @@ +--reporter spec +--ui bdd +--growl \ No newline at end of file diff --git a/test/remove.test.coffee b/test/remove.test.coffee new file mode 100644 index 0000000..4684d97 --- /dev/null +++ b/test/remove.test.coffee @@ -0,0 +1,48 @@ +crypto = require('crypto') +fs = require('fs-extra') +path = require('path-extra') +assert = require('assert') + +T = (v) -> assert(v) +F = (v) -> assert(!v) + +buildDir = -> + buf = new Buffer(5) #small buffer for data + bytesWritten = 0 + while bytesWritten < buf.length + buf[bytesWritten] = Math.floor((Math.random()*256)) + bytesWritten += 1 + + ex = Date.now() + baseDir = path.join(path.tempdir(), "TEST_fs-extra_rmrf-#{ex}") + fs.mkdirSync(baseDir) + + fs.writeFileSync(path.join(baseDir, Math.random() + ''), buf) + fs.writeFileSync(path.join(baseDir, Math.random() + ''), buf) + + subDir = path.join(path.tempdir(), Math.random() + '') + fs.mkdirSync(subDir) + + fs.writeFileSync(path.join(subDir, Math.random() + '')) + baseDir + +describe 'fs-extra: remove', -> + + describe 'rmrfSync', -> + it 'should remove directories and files synchronously', -> + dir = buildDir() + T path.existsSync(dir) + fs.rmrfSync(dir) + F path.existsSync(dir) + + + describe 'rmrf', -> + it 'should remove directories and files asynchronously', (done) -> + dir = buildDir() + T path.existsSync(dir) + fs.rmrf dir, -> + F path.existsSync(dir) + done() + + +