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

[WIP] Migrate test runner to Jest #51

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open
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
3 changes: 3 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"presets": ["env"]
}
36 changes: 19 additions & 17 deletions bin/initialize.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,24 +34,27 @@ program
} else {
const spinner = ora("creating directory structure").start();

init.initialize(projectname, gitrepository, options.eslint,
init.initialize(
projectname,
gitrepository,
options.eslint,
function initProject(res) {
if (res) {
setTimeout(() => {
spinner.text = "application created successfully";
spinner.succeed();
console.log(
`\t$ cd ${projectname}\n \t$ npm install \n \tHappy hacking ♥`
);
}, 1000);

} else {
setTimeout(() => {
spinner.text = "something went wrong!";
spinner.fail();
}, 1000);
if (res) {
setTimeout(() => {
spinner.text = "application created successfully";
spinner.succeed();
console.log(
`\t$ cd ${projectname}\n \t$ npm install \n \tHappy hacking ♥`
);
}, 1000);
} else {
setTimeout(() => {
spinner.text = "something went wrong!";
spinner.fail();
}, 1000);
}
}
});
);
}
})
.on("--help", function() {
Expand Down Expand Up @@ -325,5 +328,4 @@ program
/**
* parse commander object
*/

program.parse(process.argv);
1 change: 0 additions & 1 deletion lib/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ const path = require("path");
* @param {string} value - value to be changed
* @param {function} cb - callback
*/

function configReactCliRc(key, value, cb) {
fs.readFile(path.join(process.cwd(), ".reactclirc"), (err, buffer) => {
let jsonContent = JSON.parse(buffer.toString());
Expand Down
5 changes: 0 additions & 5 deletions lib/generate.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ generate.prototype.createComponentFile = function(re, componentName, answersInne
* @param {string} answersInner - options provided when creating component
* @param {function} cb - callback for status return
*/

generate.prototype.generateComponent = function(type, module, componentName, answers, answersInner, cb) {
try {
if(componentName !== undefined) {
Expand Down Expand Up @@ -90,7 +89,6 @@ generate.prototype.generateComponent = function(type, module, componentName, ans
* @param {string} answersInner - options provided when creating component
* @param {string} componentName - component name
*/

generate.prototype.createModFile = function(_modFile, answersInner, componentName) {
return _modFile.slice(0, Number(_modFile.indexOf('export'))-1) + this.generatePropTypesSet(answersInner, componentName) + _modFile.slice(Number(_modFile.indexOf('export'))-1);
}
Expand All @@ -100,7 +98,6 @@ generate.prototype.createModFile = function(_modFile, answersInner, componentNam
* @param {string} answersInner
* @param {string} componentName - component name
*/

generate.prototype.generatePropTypesSet = function(answersInner, componentName) {
let __propTypes = {};

Expand All @@ -123,7 +120,6 @@ generate.prototype.generatePropTypesSet = function(answersInner, componentName)
* @param {string} answersInner - options provided when creating component
* @param {function} cb - callback for status return
*/

generate.prototype.createComponent = function(module, componentName, answers, answersInner, cb) {
this.generateComponent(answers.componentType, module, componentName, answers, answersInner, cb);
}
Expand All @@ -134,7 +130,6 @@ generate.prototype.createComponent = function(module, componentName, answers, an
* @param {string} testName - test file name
* @param {function} cb - callback for status return
*/

generate.prototype.createTest = function(module, testName, cb) {
try {
if(testName !== undefined) {
Expand Down
153 changes: 70 additions & 83 deletions lib/init.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const fs = require("fs.extra");
const path = require("path");
var clone = require('git-clone');
const init = function () { };
const clone = require("git-clone");
const init = function() {};
const ora = require("ora");

/**
Expand All @@ -11,39 +11,35 @@ const ora = require("ora");
* @param {string} options - additional options for the project example: eslint configuration
* @param {function} cb - callback for status return
*/

init.prototype.initialize = function (projectName, gitrepository, eslint, cb) {
init.prototype.initialize = function(projectName, gitrepository, eslint, cb) {
if (gitrepository === undefined) {
if (eslint === undefined) {
let projectPath = projectName;
if (!fs.existsSync(projectName)) {
fs.mkdirp(projectPath, error => {
if (error) {
cb(error);
} else {
//resolve all promises async-ly
Promise.all([
this.copyCommonTemplates(projectName),
this.copyTemplate(projectName, "webpack.config.js", false),
this.copyTemplate(projectName, "reactclirc", true),
this.copyTemplate(projectName, "gitignore", true),
this.copyPackageJson(projectName)
])
.then(values => {
cb(true);
})
.catch(err => {
console.log(err);
cb(false);
});
}
});
}
else {
console.log('\x1b[1m\x1b[31m%s\x1b[0m','\n This project name is already exists \n try with different project name');
cb(false);

}
fs.mkdirp(projectPath, error => {
if (error) {
cb(error);
} else {
//resolve all promises async-ly
Promise.all([
this.copyCommonTemplates(projectName),
this.copyTemplate(
projectName,
"webpack.config.js",
false
),
this.copyTemplate(projectName, "reactclirc", true),
this.copyTemplate(projectName, "gitignore", true),
this.copyPackageJson(projectName)
])
.then(values => {
cb(true);
})
.catch(err => {
console.log(err);
cb(false);
});
}
});
} else {
if (eslint) {
Promise.all([
Expand All @@ -65,50 +61,45 @@ init.prototype.initialize = function (projectName, gitrepository, eslint, cb) {
} else {
if (eslint === undefined) {
let projectPath = projectName;
if (!fs.existsSync(projectName)) {

fs.mkdirp(projectPath, error => {
if (error) {
cb(error);
} else {
// resolve all promises async-ly
Promise.all(
[

this.copyTemplate(projectName, "webpack.config.js", false),
this.copyTemplate(projectName, "reactclirc", true),
this.copyTemplate(projectName, "gitignore", true),
this.copyPackageJson(projectName)
])
.then(values => {
const spinner = ora("cloning template").start();

clone(gitrepository, projectName + '/src', value => {
fs.mkdirp(projectPath, error => {
if (error) {
cb(error);
} else {
// resolve all promises async-ly
Promise.all([
this.copyTemplate(
projectName,
"webpack.config.js",
false
),
this.copyTemplate(projectName, "reactclirc", true),
this.copyTemplate(projectName, "gitignore", true),
this.copyPackageJson(projectName)
])
.then(values => {
const spinner = ora("cloning template").start();

clone(
gitrepository,
projectName + "/src",
value => {
setTimeout(() => {
spinner.text = "template cloned successfully";
spinner.text =
"template cloned successfully";
spinner.succeed();
cb(true);
}, 1000);
}
)
})
.catch(err => {
console.log(err);
cb(false);
});


}
});
}
else {
console.log('\x1b[1m\x1b[31m%s\x1b[0m','\n This project name is already exists \n try with different project name');
cb(false);
}
);
})
.catch(err => {
console.log(err);
cb(false);
});
}
});
} else {
if (eslint) {


Promise.all([
this.copyTemplate(projectName, "webpack.config.js", false),
this.copyTemplate(projectName, "gitignore", true),
Expand All @@ -118,14 +109,13 @@ init.prototype.initialize = function (projectName, gitrepository, eslint, cb) {
.then(values => {
const spinner = ora("cloning template").start();

clone(gitrepository, projectName + '/src', value => {
clone(gitrepository, projectName + "/src", value => {
setTimeout(() => {
spinner.text = "template cloned successfully";
spinner.succeed();
cb(true);
}, 1000);
}
)
});
})
.catch(err => {
console.log(err);
Expand All @@ -140,13 +130,12 @@ init.prototype.initialize = function (projectName, gitrepository, eslint, cb) {
* copy common templates recursively
* @param {string} projectName - project name
*/

init.prototype.copyCommonTemplates = function (projectName) {
return new Promise(function (resolve, reject) {
init.prototype.copyCommonTemplates = function(projectName) {
return new Promise(function(resolve, reject) {
fs.copyRecursive(
path.join(__dirname, "..", "templates/src"),
path.join(projectName, "src"),
function (err) {
function(err) {
if (err) {
console.log(err);
reject(err);
Expand All @@ -163,9 +152,8 @@ init.prototype.copyCommonTemplates = function (projectName) {
* @param {string} projectName - project name
* @param {string} file - name of the file to be copied
*/

init.prototype.copyTemplate = function (projectName, file, dotFile) {
return new Promise(function (resolve, reject) {
init.prototype.copyTemplate = function(projectName, file, dotFile) {
return new Promise(function(resolve, reject) {
let destFile = null;
if (dotFile) {
destFile = "." + file;
Expand All @@ -176,7 +164,7 @@ init.prototype.copyTemplate = function (projectName, file, dotFile) {
path.join(__dirname, "..", "templates", file),
path.join(projectName, destFile),
{ replace: false },
function (err) {
function(err) {
if (err) {
console.log(err);
reject(err);
Expand All @@ -192,9 +180,8 @@ init.prototype.copyTemplate = function (projectName, file, dotFile) {
* copy package.json file to project destination
* @param {string} projectName - project name
*/

init.prototype.copyPackageJson = function (projectName) {
return new Promise(function (resolve, reject) {
init.prototype.copyPackageJson = function(projectName) {
return new Promise(function(resolve, reject) {
fs.readFile(
path.join(__dirname, "..", "templates/package.json"),
(err, buffer) => {
Expand Down
1 change: 0 additions & 1 deletion lib/source.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ const path = require("path");
/**
* get source directory file
*/

const getSourceDirectory = function() {
const buffer = fs.readFileSync(path.join(process.cwd(), ".reactclirc"));
const jsonContent = JSON.parse(buffer.toString());
Expand Down
1 change: 0 additions & 1 deletion lib/utils/checkduplicateelement.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ const getSourceDirectory = require('../source');
* @param {string} elementName - propnames to compare
* @param {string} type - propnames to compare
*/

const checkDuplicateElement = function (type, moduleName, elementName) {

if(type === 'component'){
Expand Down
1 change: 0 additions & 1 deletion lib/utils/checkduplicates.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
* check for duplicates in provided set of propNames
* @param {string} propNames - propnames to compare
*/

const checkDuplicates = function(propNames) {
let currentValue = null;
for (let count = 0; count <= propNames.length; count++) {
Expand Down
1 change: 0 additions & 1 deletion lib/utils/checkspaces.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
* check for in a given array
* @param {string} propNames - propnames to check for spaces
*/

const checkSpaces = function(propNames) {
let sanitizedPropNames = [];
for (let count = 0; count <= propNames.length; count++) {
Expand Down
2 changes: 0 additions & 2 deletions lib/view.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ const getSourceDirectory = require("./source");
* @param {string} test - test file
* @param {function} cb - callback for status return
*/

const viewDirectoryStructure = function(component, test, cb) {
const src = getSourceDirectory();
if (component) {
Expand All @@ -27,7 +26,6 @@ const viewDirectoryStructure = function(component, test, cb) {
* rendering table
* @param {string} type - component/test
*/

const renderView = function(type) {
const table = new AsciiTable().fromJSON({
title: "",
Expand Down
Loading