Skip to content

Commit

Permalink
Added tests to take mtime into account
Browse files Browse the repository at this point in the history
  • Loading branch information
danielgindi committed Jan 26, 2019
1 parent 5c4a95a commit a45a22d
Showing 1 changed file with 36 additions and 12 deletions.
48 changes: 36 additions & 12 deletions tests/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@ var TreeSync = require('../');
var quickTemp = require('quick-temp');
var walkSync = require('walk-sync');
var fs = require('fs');
var path = require('path');

function expectMode(entry, prop, mode) {
if (process.platform === 'win32') { return; }
expect(entry).to.have.deep.property(prop, mode);
}

var sourcePath = __dirname + '/fixtures/';

describe('TreeSync', function() {
var tmp;

Expand All @@ -24,7 +27,7 @@ describe('TreeSync', function() {
var treeSync;

beforeEach(function() {
treeSync = new TreeSync(__dirname + '/fixtures/', tmp);
treeSync = new TreeSync(sourcePath, tmp);
});

describe('nothing -> populated', function() {
Expand All @@ -40,6 +43,20 @@ describe('TreeSync', function() {
'one/foo.txt'
]);
});

it('validate mtime stays the same', function() {
treeSync = new TreeSync(sourcePath, tmp);
treeSync.sync();

var entries = walkSync.entries(tmp);
var originalEntries = walkSync.entries(sourcePath);

for (var i = 0, len = entries.length; i < len; i++) {
if (fs.statSync(path.join(entries[i].basePath, entries[i].relativePath)).isDirectory())
continue;
expect(entries[i].mtime).to.equal(originalEntries[i].mtime);
}
});
});

describe('existing empty directory -> populated', function() {
Expand All @@ -59,7 +76,6 @@ describe('TreeSync', function() {
});
});


describe('rmdir operation is sync', function() {
var newFolderPath = __dirname + '/fixtures/two';

Expand Down Expand Up @@ -99,17 +115,23 @@ describe('TreeSync', function() {
treeSync.sync(); // setup initial
});

it('has stable output (mtime, size, mode, relativePath)', function() {
it('has stable output (mtime, size, mode, relativePath)', function(cb) {
var beforeTree = walkSync.entries(tmp);

expect(beforeTree.length).to.eql(4);

treeSync.sync();

var afterTree = walkSync.entries(tmp);

expect(afterTree.length).to.eql(4);
expect(beforeTree).to.deep.equal(afterTree);
setTimeout(function () {
// build a new `TreeSync` that does not have `lastInput` populated
treeSync = new TreeSync(sourcePath, tmp);
treeSync.sync();

var afterTree = walkSync.entries(tmp);

expect(afterTree.length).to.eql(4);
expect(beforeTree).to.deep.equal(afterTree);

cb();
}, 10);
});
});

Expand Down Expand Up @@ -184,7 +206,7 @@ describe('TreeSync', function() {
fs.writeFileSync(changeFilePath, 'OMG');

// build a new `TreeSync` that does not have `lastInput` populated
treeSync = new TreeSync(__dirname + '/fixtures/', tmp);
treeSync = new TreeSync(sourcePath, tmp);

treeSync.sync();
});
Expand Down Expand Up @@ -212,6 +234,7 @@ describe('TreeSync', function() {
describe('input(same) -> input(same - file)', function() {
var removedFilePath = __dirname + '/fixtures/one/foo.txt';
var removedFileContent = fs.readFileSync(removedFilePath);
var removedFileStat = fs.statSync(removedFilePath);

beforeEach(function() {
treeSync.sync(); // setup initial
Expand All @@ -221,6 +244,7 @@ describe('TreeSync', function() {

afterEach(function() {
fs.writeFileSync(removedFilePath, removedFileContent);
fs.utimesSync(removedFilePath, removedFileStat.atime, removedFileStat.mtime);
});

it('has stable output (mtime, size, mode, relativePath)', function() {
Expand All @@ -246,7 +270,7 @@ describe('TreeSync', function() {
expect(walkSync(tmp)).to.deep.equal([]);

// We need our own treeSync instance with options
treeSync = new TreeSync(__dirname + '/fixtures/', tmp, {
treeSync = new TreeSync(sourcePath, tmp, {
ignore: ['**/bar']
});

Expand All @@ -261,7 +285,7 @@ describe('TreeSync', function() {
it('should only include globs it is told to include', function() {
expect(walkSync(tmp)).to.deep.equal([]);

treeSync = new TreeSync(__dirname + '/fixtures/', tmp, {
treeSync = new TreeSync(sourcePath, tmp, {
globs: ['one', 'one/foo.txt']
});

Expand Down

0 comments on commit a45a22d

Please sign in to comment.