Skip to content

Commit

Permalink
test: changed chai assertions to sinon assertions (#1132)
Browse files Browse the repository at this point in the history
See #1132
  • Loading branch information
Jp-Rivera authored and kumar303 committed Nov 14, 2017
1 parent bd02dc3 commit a55ee4c
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 35 deletions.
16 changes: 9 additions & 7 deletions tests/unit/test-cmd/test.build.js
Original file line number Diff line number Diff line change
Expand Up @@ -263,16 +263,19 @@ describe('build', () => {
return buildResult;
})
.then((buildResult) => {
assert.equal(onSourceChange.called, true);
const args = onSourceChange.firstCall.args[0];
assert.equal(args.sourceDir, sourceDir);
assert.equal(args.artifactsDir, artifactsDir);

sinon.assert.called(onSourceChange);
sinon.assert.calledWithMatch(onSourceChange,
{artifactsDir, sourceDir}
);

assert.typeOf(args.onChange, 'function');

// Make sure it uses the file filter.
assert.typeOf(args.shouldWatchFile, 'function');
args.shouldWatchFile('/some/path');
assert.equal(fileFilter.wantFile.called, true);
sinon.assert.called(fileFilter.wantFile);

// Remove the built extension.
return fs.unlink(buildResult.extensionPath)
Expand Down Expand Up @@ -304,9 +307,8 @@ describe('build', () => {
manifestData: basicManifest, onSourceChange, packageCreator,
})
.then(() => {
assert.equal(onSourceChange.called, true);
assert.equal(packageCreator.callCount, 1);

sinon.assert.called(onSourceChange);
sinon.assert.calledOnce(packageCreator);
const {onChange} = onSourceChange.firstCall.args[0];
packageResult = Promise.reject(new Error(
'Simulate an error on the second call to packageCreator()'));
Expand Down
53 changes: 33 additions & 20 deletions tests/unit/test-cmd/test.lint.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,16 +62,14 @@ describe('lint', () => {
it('runs as a binary', () => {
const {lint, createLinter} = setUp();
return lint().then(() => {
const args = createLinter.firstCall.args[0];
assert.equal(args.runAsBinary, true);
sinon.assert.calledWithMatch(createLinter, {runAsBinary: true});
});
});

it('sets runAsBinary according shouldExitProgram option', () => {
const {lint, createLinter} = setUp();
return lint({}, {shouldExitProgram: false}).then(() => {
const args = createLinter.firstCall.args[0];
assert.strictEqual(args.runAsBinary, false);
sinon.assert.calledWithMatch(createLinter, {runAsBinary: false});
});
});

Expand All @@ -86,34 +84,46 @@ describe('lint', () => {
it('passes warningsAsErrors to the linter', () => {
const {lint, createLinter} = setUp();
return lint({warningsAsErrors: true}).then(() => {
const config = createLinter.firstCall.args[0].config;
assert.equal(config.warningsAsErrors, true);
sinon.assert.calledWithMatch(createLinter, {
config: {
warningsAsErrors: true,
},
});
});
});

it('passes warningsAsErrors undefined to the linter', () => {
const {lint, createLinter} = setUp();
return lint().then(() => {
const config = createLinter.firstCall.args[0].config;
assert.equal(config.warningsAsErrors, undefined);
sinon.assert.calledWithMatch(createLinter, {
config: {
warningsAsErrors: undefined,
},
});
});
});

it('configures the linter when verbose', () => {
const {lint, createLinter} = setUp();
return lint({verbose: true}).then(() => {
const config = createLinter.firstCall.args[0].config;
assert.equal(config.logLevel, 'debug');
assert.equal(config.stack, true);
sinon.assert.calledWithMatch(createLinter, {
config: {
logLevel: 'debug',
stack: true,
},
});
});
});

it('configures the linter when not verbose', () => {
const {lint, createLinter} = setUp();
return lint({verbose: false}).then(() => {
const config = createLinter.firstCall.args[0].config;
assert.equal(config.logLevel, 'fatal');
assert.equal(config.stack, false);
sinon.assert.calledWithMatch(createLinter, {
config: {
logLevel: 'fatal',
stack: false,
},
});
});
});

Expand All @@ -126,12 +136,15 @@ describe('lint', () => {
boring: true,
selfHosted: true,
}).then(() => {
const config = createLinter.firstCall.args[0].config;
assert.strictEqual(config.pretty, true);
assert.strictEqual(config.metadata, true);
assert.strictEqual(config.output, 'json');
assert.strictEqual(config.boring, true);
assert.strictEqual(config.selfHosted, true);
sinon.assert.calledWithMatch(createLinter, {
config: {
pretty: true,
metadata: true,
output: 'json',
boring: true,
selfHosted: true,
},
});
});
});

Expand Down
13 changes: 5 additions & 8 deletions tests/unit/test.watcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import path from 'path';
import {it, describe} from 'mocha';
import {fs} from 'mz';
import sinon from 'sinon';
import {assert} from 'chai';

import {default as onSourceChange, proxyFileChanges} from '../../src/watcher';
import {withTempDir} from '../../src/util/temp-dir';
Expand Down Expand Up @@ -42,7 +41,7 @@ describe('watcher', () => {
return whenFilesChanged
.then(() => {
watcher.close();
assert.equal(onChange.callCount, 1);
sinon.assert.calledOnce(onChange);
// This delay seems to avoid stat errors from the watcher
// which can happen when the temp dir is deleted (presumably
// before watcher.close() has removed all listeners).
Expand All @@ -67,7 +66,7 @@ describe('watcher', () => {
filePath: '/some/file.js',
onChange,
});
assert.equal(onChange.called, true);
sinon.assert.called(onChange);
});

it('ignores changes to artifacts', () => {
Expand All @@ -78,7 +77,7 @@ describe('watcher', () => {
artifactsDir: '/some/artifacts/dir/',
onChange,
});
assert.equal(onChange.called, false);
sinon.assert.notCalled(onChange);
});

it('provides a callback for ignoring files', () => {
Expand All @@ -98,11 +97,9 @@ describe('watcher', () => {
};

proxyFileChanges({...conf, filePath: '/somewhere/freaky'});
assert.equal(conf.onChange.called, false);

sinon.assert.notCalled(conf.onChange);
proxyFileChanges({...conf, filePath: '/any/file/'});
assert.equal(conf.onChange.called, true);

sinon.assert.called(conf.onChange);
});

});
Expand Down

0 comments on commit a55ee4c

Please sign in to comment.