Skip to content

Commit

Permalink
Adapt tests to vinyl stats changes
Browse files Browse the repository at this point in the history
  • Loading branch information
erikkemperman committed Jan 17, 2016
1 parent 4b69b73 commit 7d0001a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 54 deletions.
53 changes: 3 additions & 50 deletions test/dest.js
Original file line number Diff line number Diff line change
Expand Up @@ -613,7 +613,7 @@ describe('dest stream', function() {
stream.end();
});

it('should not modify file mtime and atime when not provided on the vinyl stat', function(done) {
it('should not modify file mtime 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');
Expand All @@ -638,7 +638,7 @@ describe('dest stream', function() {
fs.lstatSync(expectedPath).atime.setMilliseconds(0).should.equal(expectedAtime.setMilliseconds(0));
fs.lstatSync(expectedPath).mtime.setMilliseconds(0).should.equal(expectedMtime.setMilliseconds(0));
expectedFile.stat.should.not.have.property('mtime');
expectedFile.stat.should.not.have.property('atime');
expectedFile.stat.should.have.property('atime');
done();
};

Expand Down Expand Up @@ -677,7 +677,7 @@ describe('dest stream', function() {
fs.lstatSync(expectedPath).mtime.getTime().should.equal(expectedMtime.getTime());
expectedFile.stat.should.have.property('mtime');
expectedFile.stat.mtime.should.equal(expectedMtime);
expectedFile.stat.should.not.have.property('atime');
expectedFile.stat.should.have.property('atime');
done();
};

Expand Down Expand Up @@ -765,53 +765,6 @@ describe('dest stream', function() {
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 expectedAtime = fs.lstatSync(inputPath).atime;
var expectedMtime = fs.lstatSync(inputPath).mtime;

var expectedFile = new File({
base: inputBase,
cwd: __dirname,
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 buffered = [];

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());
expectedFile.stat.should.have.property('mtime');
expectedFile.stat.mtime.should.equal(expectedMtime);
expectedFile.stat.should.have.property('atime');
expectedFile.stat.atime.should.equal(expectedAtime);
done();
};

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

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

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

it('should change to the specified base as string', function(done) {
var inputBase = path.join(__dirname, './fixtures');
var inputPath = path.join(__dirname, './fixtures/wow/suchempty');
Expand Down
10 changes: 6 additions & 4 deletions test/src.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,12 @@ describe('source stream', function() {
});
stream.once('end', function() {
files.length.should.equal(2);
files[0].should.eql(expectedFile);
bufEqual(files[0].contents, expectedContent).should.equal(true);
files[1].should.eql(expectedFile);
bufEqual(files[1].contents, expectedContent).should.equal(true);
for (var i = 0; i < files.length; i++) {
files[i].base.should.equal(expectedFile.base);
files[i].cwd.should.equal(expectedFile.cwd);
files[i].path.should.equal(expectedFile.path);
bufEqual(files[i].contents, expectedContent).should.equal(true);
}
done();
});
stream.write(expectedFile);
Expand Down

0 comments on commit 7d0001a

Please sign in to comment.