Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(coverage): fix coverage issues #139

Merged
merged 1 commit into from
Jun 21, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export const shouldReadStdin = (args) => {
});
let requiredNumArgs = cmdInfo ? cmdInfo.minArgs : -1;

// If a non-boolean option is passed in, incrememnt the required argument
// If a non-boolean option is passed in, increment the required argument
// count (this is the case for `-n` for `head` and `tail`)
if (parsedArgs.n && (cmd === 'head' || cmd === 'tail')) {
requiredNumArgs++;
Expand Down
1 change: 1 addition & 0 deletions src/shx.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ export function shx(argv) {
if (typeof code === 'number') {
return code;
} else if (shell.error()) {
/* istanbul ignore next */
return EXIT_CODES.CMD_FAILED;
}

Expand Down
17 changes: 16 additions & 1 deletion test/specs/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,10 @@ describe('cli', () => {
shouldReadStdin(['grep', 'a.*z']).should.equal(true);
});

it('reads stdin if only options are given', () => {
it('reads stdin if not enough arguments are given', () => {
process.stdin.isTTY = undefined;
shouldReadStdin(['head', '-n', '1']).should.equal(true);
shouldReadStdin(['tail', '-n', '1']).should.equal(true);
shouldReadStdin(['grep', '-i', 'a.*z']).should.equal(true);
});

Expand Down Expand Up @@ -216,6 +217,20 @@ describe('cli', () => {
}).should.throw(Error);
});

it('does not load any plugins if config file lacks plugin section', () => {
const config = {
notplugins: [ // the plugins attribute is mandatory for loading plugins
'shelljs-plugin-open',
],
};
shell.ShellString(JSON.stringify(config)).to(CONFIG_FILE);

const output = cli('help');
output.stderr.should.equal(''); // Runs successfully
output.stdout.should.match(/Usage/); // make sure help is printed
output.stdout.should.not.match(/- open/); // should *not* load the plugin
});

it('defends against malicious config files', () => {
const notValidJSON = `
var shell = require('shelljs');
Expand Down