Skip to content

Commit

Permalink
Fix: No longer relying on system time for flakey test (#398)
Browse files Browse the repository at this point in the history
  • Loading branch information
JustinHoldstock authored Sep 20, 2017
1 parent 6c7b63a commit 1986f9a
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/lib/__tests__/Logger-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ let logger;
const sandbox = sinon.sandbox.create();

describe('lib/Logger', () => {
let dateNowStub = sandbox.stub(Date, 'now');

beforeEach(() => {
dateNowStub.returns(0);
logger = new Logger('FOO', {});
});

Expand All @@ -15,6 +18,7 @@ describe('lib/Logger', () => {
});

it('should have correct defaults', () => {
dateNowStub.returns(1); // Took 1 ms to run
const log = logger.done();

assert.ok(log.time.total < 5, 'Total time should be correct');
Expand All @@ -37,13 +41,13 @@ describe('lib/Logger', () => {
});

it('should set and get correctly', () => {
const dateStub = sandbox.stub(Date, 'now').returns(0);
dateNowStub.returns(0);
logger.setCached();
logger.setCacheStale();
logger.setFile({ id: 1 });
logger.setType('BAR');

dateStub.returns(100);
dateNowStub.returns(100);
logger.setUnConverted();

const log = logger.done();
Expand Down

0 comments on commit 1986f9a

Please sign in to comment.