2014-05-23 20:53:50 +00:00
|
|
|
var Filer = require('../..');
|
|
|
|
var util = require('../lib/test-utils.js');
|
|
|
|
var expect = require('chai').expect;
|
2014-01-21 21:25:09 +00:00
|
|
|
|
2014-05-23 20:53:50 +00:00
|
|
|
describe('fs.writeFile truncation - issue 106', function() {
|
|
|
|
beforeEach(util.setup);
|
|
|
|
afterEach(util.cleanup);
|
2014-01-21 21:25:09 +00:00
|
|
|
|
2014-05-23 20:53:50 +00:00
|
|
|
it('should truncate an existing file', function(done) {
|
|
|
|
var fs = util.fs();
|
|
|
|
var filename = '/test';
|
2014-01-21 21:25:09 +00:00
|
|
|
|
2014-05-23 20:53:50 +00:00
|
|
|
fs.writeFile(filename, '1', function(err) {
|
|
|
|
if(err) throw err;
|
|
|
|
|
|
|
|
fs.stat(filename, function(err, stats) {
|
2014-01-21 21:25:09 +00:00
|
|
|
if(err) throw err;
|
2014-05-23 20:53:50 +00:00
|
|
|
expect(stats.size).to.equal(1);
|
2014-01-21 21:25:09 +00:00
|
|
|
|
2014-05-23 20:53:50 +00:00
|
|
|
fs.writeFile(filename, '', function(err) {
|
2014-01-21 21:25:09 +00:00
|
|
|
if(err) throw err;
|
|
|
|
|
2014-05-23 20:53:50 +00:00
|
|
|
fs.stat(filename, function(err, stats) {
|
2014-01-21 21:25:09 +00:00
|
|
|
if(err) throw err;
|
2014-05-23 20:53:50 +00:00
|
|
|
expect(stats.size).to.equal(0);
|
|
|
|
done();
|
2014-01-21 21:25:09 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|