Skip to content

Commit

Permalink
test: fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
trs committed May 7, 2018
1 parent 1b5d22a commit a794f1e
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/helpers/file-stat.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 ? [
Expand Down
2 changes: 1 addition & 1 deletion test/connector/passive.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});

Expand Down
16 changes: 16 additions & 0 deletions test/helpers/file-stat.spec.js
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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');
});
Expand Down

0 comments on commit a794f1e

Please # to comment.