Browse Source

Implemented and tested rmrf.

ci/travis-osximage
JP Richardson 13 years ago
parent
commit
ec64f4397e
  1. 4
      index.coffee
  2. 10
      lib/remove.coffee
  3. 11
      test/copy.test.coffee
  4. 3
      test/mocha.opts
  5. 48
      test/remove.test.coffee

4
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

10
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

11
spec/copy.spec.coffee → 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 ->
T bufMd5 is destMd5
T srcMd5 is destMd5
done()

3
test/mocha.opts

@ -0,0 +1,3 @@
--reporter spec
--ui bdd
--growl

48
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()
Loading…
Cancel
Save