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

quick fixes to handle CLI args errors #306

Merged
merged 5 commits into from
Apr 5, 2020
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
8 changes: 8 additions & 0 deletions lib/cli-command.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,14 @@ module.exports = {
description: 'creates a React Native library module for one or more platforms',
usage: '[options] <name>',
action: (args, options) => {
if (!args || args.length < 1) {
throw new Error('missing lib module name');
}

if (args.length > 1) {
throw new Error('too many arguments');
}

const name = args[0];

const beforeCreation = Date.now();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const action = require('../../../../../lib/cli-command.js').action;

test('create lib module with empty args - missing name', () => {
const args = [];

expect(() => { action(args, {}); }).toThrow('missing lib module name');
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const action = require('../../../../../lib/cli-command.js').action;

test('create module with too many args', () => {
const args = ['name1', 'name2'];

// ref:
// https://github.com/brodybits/create-react-native-module/issues/119
expect(() => { action(args, {}); }).toThrow('too many arguments');
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const action = require('../../../../../lib/cli-command.js').action;

test('create lib module with undefined args - missing name', () => {
const args = undefined;

// ref:
// https://github.com/brodybits/create-react-native-module/issues/305
expect(() => { action(args, {}); }).toThrow('missing lib module name');
});