Skip to content

Commit

Permalink
chore: sinon assertions for test.program.js and test.lint.js (#1059)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jp-Rivera authored and kumar303 committed Oct 2, 2017
1 parent 0e51fb0 commit 42a46bf
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 35 deletions.
10 changes: 4 additions & 6 deletions tests/unit/test-cmd/test.lint.js
Expand Up @@ -42,8 +42,8 @@ describe('lint', () => {
const {lint, createLinter, runLinter, lintResult} = setUp();
return lint().then((actualLintResult) => {
assert.equal(actualLintResult, lintResult);
assert.equal(createLinter.called, true);
assert.equal(runLinter.called, true);
sinon.assert.called(createLinter);
sinon.assert.called(runLinter);
});
});

Expand Down Expand Up @@ -145,14 +145,12 @@ describe('lint', () => {
ignoreFiles: ['file1', '**/file2'],
};
return lint(params).then(() => {
assert.ok(createFileFilter.called);
assert.deepEqual(createFileFilter.firstCall.args[0], params);
sinon.assert.calledWith(createFileFilter, params);

assert.ok(createLinter.called);
const {shouldScanFile} = createLinter.firstCall.args[0].config;
shouldScanFile('path/to/file');
assert.ok(fileFilter.wantFile.called);
assert.equal(fileFilter.wantFile.firstCall.args[0], 'path/to/file');
sinon.assert.calledWith(fileFilter.wantFile, 'path/to/file');
});
});

Expand Down
64 changes: 35 additions & 29 deletions tests/unit/test.program.js
Expand Up @@ -40,7 +40,7 @@ describe('program.Program', () => {
.command('thing', 'does a thing', thing);
return execProgram(program)
.then(() => {
assert.equal(thing.called, true);
sinon.assert.called(thing);
});
});

Expand Down Expand Up @@ -115,10 +115,9 @@ describe('program.Program', () => {
});
return execProgram(program)
.then(() => {
assert.equal(handler.called, true);
// This ensures that the default configuration for the option has
// been applied.
assert.equal(handler.firstCall.args[0].someOption, 'default value');
sinon.assert.calledWithMatch(handler, {someOption: 'default value'});
});
});

Expand All @@ -139,11 +138,14 @@ describe('program.Program', () => {
});
return execProgram(program)
.then(() => {
assert.equal(handler.called, true);
// By checking the global default, it ensures that default configuration
// will be applied to sub commands.
assert.equal(handler.firstCall.args[0].globalOption, 'the default');
assert.equal(handler.firstCall.args[0].someOption, 'default value');
sinon.assert.calledWithMatch(
handler,
{
someOption: 'default value',
globalOption: 'the default',
});
});
});

Expand Down Expand Up @@ -183,7 +185,7 @@ describe('program.Program', () => {
logStream,
})
.then(() => {
assert.equal(logStream.makeVerbose.called, true);
sinon.assert.called(logStream.makeVerbose);
});
});

Expand Down Expand Up @@ -213,7 +215,7 @@ describe('program.Program', () => {
});
return execProgram(program, {logStream})
.then(() => {
assert.equal(logStream.makeVerbose.called, false);
sinon.assert.notCalled(logStream.makeVerbose);
});
});

Expand Down Expand Up @@ -259,8 +261,8 @@ describe('program.Program', () => {
globalEnv: 'production',
})
.then(() => {
assert.equal(checkForUpdates.firstCall.args[0].version,
'some-package-version');
sinon.assert.calledWith(
checkForUpdates, {version: 'some-package-version'});
});
});

Expand All @@ -276,7 +278,7 @@ describe('program.Program', () => {
globalEnv: 'development',
})
.then(() => {
assert.equal(checkForUpdates.called, false);
sinon.assert.notCalled(checkForUpdates);
});
});
});
Expand All @@ -303,7 +305,7 @@ describe('program.main', () => {
// This is a smoke test mainly to make sure main() configures
// options with handlers. It does not extensively test the
// configuration of all handlers.
assert.equal(fakeCommands.build.called, true);
sinon.assert.called(fakeCommands.build);
});
});

Expand Down Expand Up @@ -331,8 +333,7 @@ describe('program.main', () => {
getVersion: fakeVersionGetter,
})
.then(() => {
assert.equal(fakeVersionGetter.called, true);
assert.equal(fakeVersionGetter.firstCall.args[0], projectRoot);
sinon.assert.calledWith(fakeVersionGetter, projectRoot);
});
});

Expand All @@ -343,9 +344,10 @@ describe('program.main', () => {
return execProgram(
['build', '--source-dir', '..'], {commands: fakeCommands})
.then(() => {
assert.equal(fakeCommands.build.called, true);
assert.equal(fakeCommands.build.firstCall.args[0].sourceDir,
path.resolve(path.join(process.cwd(), '..')));
sinon.assert.calledWithMatch(
fakeCommands.build,
{sourceDir: path.resolve(path.join(process.cwd(), '..'))}
);
});
});

Expand All @@ -358,9 +360,10 @@ describe('program.main', () => {
['build', '--artifacts-dir', process.cwd() + path.sep + path.sep],
{commands: fakeCommands})
.then(() => {
assert.equal(fakeCommands.build.called, true);
assert.equal(fakeCommands.build.firstCall.args[0].artifactsDir,
process.cwd() + path.sep);
sinon.assert.calledWithMatch(
fakeCommands.build,
{artifactsDir: process.cwd() + path.sep}
);
});
});

Expand All @@ -372,9 +375,10 @@ describe('program.main', () => {
['run', '--firefox-binary', '/path/to/firefox-binary'],
{commands: fakeCommands})
.then(() => {
assert.equal(fakeCommands.run.called, true);
assert.equal(fakeCommands.run.firstCall.args[0].firefox,
'/path/to/firefox-binary');
sinon.assert.calledWithMatch(
fakeCommands.run,
{firefox: '/path/to/firefox-binary'}
);
});
});

Expand All @@ -386,9 +390,10 @@ describe('program.main', () => {
['run', '--start-url', 'www.example.com'],
{commands: fakeCommands})
.then(() => {
assert.equal(fakeCommands.run.called, true);
assert.equal(fakeCommands.run.firstCall.args[0].startUrl,
'www.example.com');
sinon.assert.calledWithMatch(
fakeCommands.run,
{startUrl: 'www.example.com'}
);
});
});

Expand All @@ -400,9 +405,10 @@ describe('program.main', () => {
['run', '--browser-console'],
{commands: fakeCommands})
.then(() => {
assert.equal(fakeCommands.run.called, true);
assert.equal(fakeCommands.run.firstCall.args[0].browserConsole,
true);
sinon.assert.calledWithMatch(
fakeCommands.run,
{browserConsole: true}
);
});
});

Expand Down

0 comments on commit 42a46bf

Please sign in to comment.