diff --git a/src/helpers/file-stat.js b/src/helpers/file-stat.js index 3891c2cc..5187da9a 100644 --- a/src/helpers/file-stat.js +++ b/src/helpers/file-stat.js @@ -18,7 +18,8 @@ module.exports = function (fileStat, format = 'ls') { function ls(fileStat) { const now = moment.utc(); const mtime = moment.utc(new Date(fileStat.mtime)); - const dateFormat = now.diff(mtime, 'months') < 6 ? 'MMM DD HH:mm' : 'MMM DD YYYY'; + const timeDiff = now.diff(mtime, 'months'); + const dateFormat = timeDiff < 6 ? 'MMM DD HH:mm' : 'MMM DD YYYY'; return [ fileStat.mode ? [ diff --git a/test/connector/passive.spec.js b/test/connector/passive.spec.js index e6b45879..6be87f7c 100644 --- a/test/connector/passive.spec.js +++ b/test/connector/passive.spec.js @@ -64,7 +64,7 @@ describe('Connector - Passive //', function () { return passive.setupServer() .then(shouldNotResolve) .catch(err => { - expect(err.name).to.equal('RangeError'); + expect(err).to.be.instanceOf(RangeError); }); }); diff --git a/test/helpers/file-stat.spec.js b/test/helpers/file-stat.spec.js index d273a124..eb8618f8 100644 --- a/test/helpers/file-stat.spec.js +++ b/test/helpers/file-stat.spec.js @@ -1,9 +1,20 @@ const {expect} = require('chai'); +const sinon = require('sinon'); +const moment = require('moment'); const fileStat = require('../../src/helpers/file-stat'); const errors = require('../../src/errors'); describe('helpers // file-stat', function () { + let sandbox; + + before(function () { + sandbox = sinon.sandbox.create(); + }); + afterEach(function () { + sandbox.restore(); + }); + const STAT = { name: 'test1', dev: 2114, @@ -44,6 +55,11 @@ describe('helpers // file-stat', function () { describe('format - ls //', function () { it('formats correctly', () => { + const momentStub = sandbox.stub(moment, 'utc').callThrough(); + momentStub.onFirstCall().callsFake(function () { + return moment.utc(new Date('Sept 10 2016')); + }); + const format = fileStat(STAT, 'ls'); expect(format).to.equal('-rwxrwxrwx 1 85 100 527 Oct 10 23:24 test1'); });