Skip to content

Commit

Permalink
chore: Added sinon asserts to test.updates.js (#986)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jp-Rivera authored and kumar303 committed Jun 29, 2017
1 parent b0b6227 commit 4a4641c
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 33 deletions.
20 changes: 9 additions & 11 deletions tests/unit/test-util/test.desktop-notifier.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/* @flow */
import {it, describe} from 'mocha';
import {assert} from 'chai';
import sinon from 'sinon';

import {showDesktopNotification} from '../../../src/util/desktop-notifier';
Expand All @@ -22,13 +21,12 @@ describe('util/desktop-notifier', () => {
notifier: fakeNotifier,
})
.then(() => {
assert.ok(fakeNotifier.notify.called);
assert.equal(
fakeNotifier.notify.firstCall.args[0].title,
'web-ext run: title',
sinon.assert.calledWithMatch(
fakeNotifier.notify, {
title: 'web-ext run: title',
message: 'message',
}
);
assert.equal(fakeNotifier.notify.firstCall.args[0].message,
'message');
});
});

Expand All @@ -48,10 +46,10 @@ describe('util/desktop-notifier', () => {
})
.then(makeSureItFails())
.catch(() => {
assert.ok(fakeLog.debug.called);
assert.equal(fakeLog.debug.firstCall.args[0],
`Desktop notifier error: ${expectedError.message}, ` +
'response: response');
sinon.assert.calledWith(
fakeLog.debug,
`Desktop notifier error: ${expectedError.message}, ` +
'response: response');
});
});

Expand Down
29 changes: 15 additions & 14 deletions tests/unit/test-util/test.logger.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import sinon from 'sinon';
import {it, describe} from 'mocha';
import {assert} from 'chai';


import {createLogger, ConsoleStream} from '../../../src/util/logger';


Expand All @@ -16,7 +17,9 @@ describe('logger', () => {
it('makes file names less redundant', () => {
const createBunyanLog = sinon.spy(() => {});
createLogger('src/some-file.js', {createBunyanLog});
assert.equal(createBunyanLog.firstCall.args[0].name, 'some-file.js');
sinon.assert.calledWithMatch(
createBunyanLog, {name: 'some-file.js'}
);
});

});
Expand Down Expand Up @@ -77,31 +80,31 @@ describe('logger', () => {
const localProcess = fakeProcess();
// $FLOW_IGNORE: fake process for testing reasons.
log.write(packet({level: bunyan.DEBUG}), {localProcess});
assert.equal(localProcess.stdout.write.called, false);
sinon.assert.notCalled(localProcess.stdout.write);
});

it('does not log trace packets unless verbose', () => {
const log = new ConsoleStream({verbose: false});
const localProcess = fakeProcess();
// $FLOW_IGNORE: fake process for testing reasons.
log.write(packet({level: bunyan.TRACE}), {localProcess});
assert.equal(localProcess.stdout.write.called, false);
sinon.assert.notCalled(localProcess.stdout.write);
});

it('logs debug packets when verbose', () => {
const log = new ConsoleStream({verbose: true});
const localProcess = fakeProcess();
// $FLOW_IGNORE: fake process for testing reasons.
log.write(packet({level: bunyan.DEBUG}), {localProcess});
assert.equal(localProcess.stdout.write.called, true);
sinon.assert.called(localProcess.stdout.write);
});

it('logs trace packets when verbose', () => {
const log = new ConsoleStream({verbose: true});
const localProcess = fakeProcess();
// $FLOW_IGNORE: fake process for testing reasons.
log.write(packet({level: bunyan.TRACE}), {localProcess});
assert.equal(localProcess.stdout.write.called, true);
sinon.assert.called(localProcess.stdout.write);
});

it('logs info packets when verbose or not', () => {
Expand All @@ -112,7 +115,7 @@ describe('logger', () => {
log.makeVerbose();
// $FLOW_IGNORE: fake process for testing reasons.
log.write(packet({level: bunyan.INFO}), {localProcess});
assert.equal(localProcess.stdout.write.callCount, 2);
sinon.assert.callCount(localProcess.stdout.write, 2);
});

it('lets you capture logging', () => {
Expand All @@ -122,12 +125,10 @@ describe('logger', () => {
log.startCapturing();
// $FLOW_IGNORE: fake process for testing reasons.
log.write(packet({msg: 'message'}), {localProcess});
assert.equal(localProcess.stdout.write.called, false);
sinon.assert.notCalled(localProcess.stdout.write);
// $FLOW_IGNORE: fake process for testing reasons.
log.flushCapturedLogs({localProcess});
assert.equal(localProcess.stdout.write.called, true);
assert.equal(localProcess.stdout.write.firstCall.args[0],
'message\n');
sinon.assert.calledWith(localProcess.stdout.write, 'message\n');
});

it('only flushes captured messages once', () => {
Expand All @@ -144,7 +145,7 @@ describe('logger', () => {
localProcess = fakeProcess();
// $FLOW_IGNORE: fake process for testing reasons.
log.flushCapturedLogs({localProcess});
assert.equal(localProcess.stdout.write.callCount, 0);
sinon.assert.notCalled(localProcess.stdout.write);
});

it('lets you start and stop capturing', () => {
Expand All @@ -154,12 +155,12 @@ describe('logger', () => {
log.startCapturing();
// $FLOW_IGNORE: fake process for testing reasons.
log.write(packet(), {localProcess});
assert.equal(localProcess.stdout.write.callCount, 0);
sinon.assert.notCalled(localProcess.stdout.write);

log.stopCapturing();
// $FLOW_IGNORE: fake process for testing reasons.
log.write(packet(), {localProcess});
assert.equal(localProcess.stdout.write.callCount, 1);
sinon.assert.callCount(localProcess.stdout.write, 1);

// Make sure that when we start capturing again,
// the queue gets reset.
Expand All @@ -168,7 +169,7 @@ describe('logger', () => {
localProcess = fakeProcess();
// $FLOW_IGNORE: fake process for testing reasons.
log.flushCapturedLogs({localProcess});
assert.equal(localProcess.stdout.write.callCount, 1);
sinon.assert.callCount(localProcess.stdout.write, 1);
});

});
Expand Down
16 changes: 8 additions & 8 deletions tests/unit/test-util/test.updates.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/* @flow */
import {it, describe} from 'mocha';
import {assert} from 'chai';
import sinon from 'sinon';

import {checkForUpdates} from '../../../src/util/updates';
Expand All @@ -18,12 +17,13 @@ describe('util/updates', () => {
version: '1.0.0',
updateNotifier: updateNotifierStub,
});
assert.equal(updateNotifierStub.called, true);
assert.equal(updateNotifierStub.firstCall.args[0].pkg.name, 'web-ext');
assert.equal(updateNotifierStub.firstCall.args[0].pkg.version, '1.0.0');
assert.isNumber(updateNotifierStub.firstCall.args[0].updateCheckInterval);
assert.equal(updateNotifierStub.firstCall.args[0].updateCheckInterval,
1000 * 60 * 60 * 24 * 3);

sinon.assert.calledWithMatch(
updateNotifierStub, {
updateCheckInterval: 1000 * 60 * 60 * 24 * 3,
pkg: { name: 'web-ext', version: '1.0.0' },
}
);
});
});
});
});

0 comments on commit 4a4641c

Please sign in to comment.