Skip to content

Commit

Permalink
Tests for atime and mtime
Browse files Browse the repository at this point in the history
- should not modify file mtime and atime when not provided on the vinyl stat
- should write file mtime using the vinyl mtime
- should write file atime and mtime using the vinyl stat
  • Loading branch information
piranna committed Oct 15, 2015
1 parent d7a53d5 commit 573b8b6
Showing 1 changed file with 84 additions and 0 deletions.
84 changes: 84 additions & 0 deletions test/dest.js
Original file line number Diff line number Diff line change
Expand Up @@ -574,13 +574,94 @@ describe('dest stream', function() {
stream.end();
});

it('should not modify file mtime and atime when not provided on the vinyl stat', function(done) {
var inputPath = path.join(__dirname, './fixtures/test.coffee');
var inputBase = path.join(__dirname, './fixtures/');
var expectedPath = path.join(__dirname, './out-fixtures/test.coffee');
var expectedContents = fs.readFileSync(inputPath);
var expectedCwd = __dirname;
var expectedBase = path.join(__dirname, './out-fixtures');
var expectedAtime = new Date();
var expectedMtime = new Date();

var expectedFile = new File({
base: inputBase,
cwd: __dirname,
path: inputPath,
contents: expectedContents,
stat: {}
});

var onEnd = function(){
buffered.length.should.equal(1);
buffered[0].should.equal(expectedFile);
fs.existsSync(expectedPath).should.equal(true);
fs.lstatSync(expectedPath).atime.setMilliseconds(0).should.equal(expectedAtime.setMilliseconds(0));
fs.lstatSync(expectedPath).mtime.setMilliseconds(0).should.equal(expectedMtime.setMilliseconds(0));
done();
};

var stream = vfs.dest('./out-fixtures/', {cwd: __dirname});

var buffered = [];
var bufferStream = through.obj(dataWrap(buffered.push.bind(buffered)), onEnd);

stream.pipe(bufferStream);
stream.write(expectedFile);
stream.end();
});

it('should write file mtime using the vinyl mtime', function(done) {
var inputPath = path.join(__dirname, './fixtures/test.coffee');
var inputBase = path.join(__dirname, './fixtures/');
var expectedPath = path.join(__dirname, './out-fixtures/test.coffee');
var expectedContents = fs.readFileSync(inputPath);
var expectedCwd = __dirname;
var expectedBase = path.join(__dirname, './out-fixtures');
var expectedAtime = new Date();
var expectedMtime = fs.lstatSync(inputPath).mtime;

var expectedFile = new File({
base: inputBase,
cwd: __dirname,
path: inputPath,
contents: expectedContents,
stat: {
mtime: expectedMtime
}
});

// Node.js uses `utime()`, so `fs.utimes()` has a resolution of 1 second
expectedAtime.setMilliseconds(0)
expectedMtime.setMilliseconds(0)

var onEnd = function(){
buffered.length.should.equal(1);
buffered[0].should.equal(expectedFile);
fs.existsSync(expectedPath).should.equal(true);
fs.lstatSync(expectedPath).atime.getTime().should.equal(expectedAtime.getTime());
fs.lstatSync(expectedPath).mtime.getTime().should.equal(expectedMtime.getTime());
done();
};

var stream = vfs.dest('./out-fixtures/', {cwd: __dirname});

var buffered = [];
var bufferStream = through.obj(dataWrap(buffered.push.bind(buffered)), onEnd);

stream.pipe(bufferStream);
stream.write(expectedFile);
stream.end();
});

it('should write file atime and mtime using the vinyl stat', function(done) {
var inputPath = path.join(__dirname, './fixtures/test.coffee');
var inputBase = path.join(__dirname, './fixtures/');
var expectedPath = path.join(__dirname, './out-fixtures/test.coffee');
var expectedContents = fs.readFileSync(inputPath);
var expectedCwd = __dirname;
var expectedBase = path.join(__dirname, './out-fixtures');
var expectedAtime = fs.lstatSync(inputPath).atime;
var expectedMtime = fs.lstatSync(inputPath).mtime;

var expectedFile = new File({
Expand All @@ -589,17 +670,20 @@ describe('dest stream', function() {
path: inputPath,
contents: expectedContents,
stat: {
atime: expectedAtime,
mtime: expectedMtime
}
});

// Node.js uses `utime()`, so `fs.utimes()` has a resolution of 1 second
expectedAtime.setMilliseconds(0)
expectedMtime.setMilliseconds(0)

var onEnd = function(){
buffered.length.should.equal(1);
buffered[0].should.equal(expectedFile);
fs.existsSync(expectedPath).should.equal(true);
fs.lstatSync(expectedPath).atime.getTime().should.equal(expectedAtime.getTime());
fs.lstatSync(expectedPath).mtime.getTime().should.equal(expectedMtime.getTime());
done();
};
Expand Down

0 comments on commit 573b8b6

Please sign in to comment.