Skip to content

Commit

Permalink
Add tests and ci
Browse files Browse the repository at this point in the history
  • Loading branch information
mayankchd committed Feb 9, 2016
1 parent 703a950 commit ab2f7c1
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 4 deletions.
6 changes: 6 additions & 0 deletions .travis.yml
@@ -0,0 +1,6 @@
language: node_js
node_js:
- '5'
- '4'
before_install:
- 'npm install -g npm@latest'
10 changes: 8 additions & 2 deletions bin/init.js
Expand Up @@ -9,7 +9,7 @@ require('shelljs/global');

program
.description('Create a MERN app in current directory!')
.option('-i, --init [type]', 'Init a new mern boilerplate')
.option('-i, --init [name]', 'Init a new mern boilerplate')
.parse(process.argv);


Expand All @@ -18,6 +18,12 @@ if (!which('git')) {
exit(1);
}

if(! program.init) {
console.log(chalk.cyan('Please pass correct options or type --help or -h for help!'));
exit(1);
}


if(program.init && program.init !== true) {
if(test('-d', program.init)) {
console.log(chalk.red(program.init+ ' already exits! Please choose some another name!!!'));
Expand All @@ -30,7 +36,7 @@ if(program.init && program.init !== true) {
exec('git init');

var interval = setInterval(function() {
logUpdate("Fetching the boilerplate..." + chalk.cyan.bold.dim(frame()));
logUpdate("Fetching the boilerplate..." + chalk.cyan.bold(frame()));
}, 50)

var e = exec('git pull https://github.com/Hashnode/mern-starter.git', function(code, stdout, stderr) {
Expand Down
11 changes: 9 additions & 2 deletions package.json
@@ -1,10 +1,13 @@
{
"name": "mern-cli",
"version": "1.0.0",
"version": "1.0.1",
"description": "A cli for generating MERN boilerplate",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"test": "ava tests/*.js"
},
"engines": {
"node": ">=4"
},
"repository": {
"type": "git",
Expand All @@ -29,5 +32,9 @@
"elegant-spinner": "^1.0.1",
"log-update": "^1.0.2",
"shelljs": "^0.6.0"
},
"devDependencies": {
"ava": "^0.11.0",
"pify": "^2.3.0"
}
}
20 changes: 20 additions & 0 deletions tests/test.js
@@ -0,0 +1,20 @@
import test from 'ava';
import path from 'path';
import childProcess from 'child_process';
import pify from 'pify';

const exec = pify(childProcess.exec);


test('shows help on --help', async t => {
const stdout = await exec('../bin/init.js --help');
t.is(stdout.trim(), 'Usage: init [options]\n\n Create a MERN app in current directory!\n\n Options:\n\n -h, --help output usage information\n -i, --init [type] Init a new mern boilerplate');
});


test('shows help on --h', async t => {
const stdout = await exec('../bin/init.js --help');
t.is(stdout.trim(), 'Usage: init [options]\n\n Create a MERN app in current directory!\n\n Options:\n\n -h, --help output usage information\n -i, --init [type] Init a new mern boilerplate');
});


0 comments on commit ab2f7c1

Please sign in to comment.