tests: improve tests

This commit is contained in:
Austen Collins 2015-08-22 19:26:56 -07:00
parent 670fc826ee
commit 65e541dbed
2 changed files with 83 additions and 83 deletions

View File

@ -6,13 +6,13 @@
*/
var JawsError = require('../jaws-error'),
Promise = require('bluebird'),
path = require('path'),
fs = require('fs'),
del = require('del'),
wrench = require('wrench'),
shortid = require('shortid'),
Download = require('Download');
Promise = require('bluebird'),
path = require('path'),
fs = require('fs'),
del = require('del'),
wrench = require('wrench'),
shortid = require('shortid'),
Download = require('Download');
Promise.promisifyAll(fs);
@ -22,8 +22,8 @@ module.exports = function(JAWS) {
return new Promise(function(resolve, reject) {
if (!JAWS._meta.projectRootPath) {
reject(new JawsError(
'Could\'nt find your JAWS Project. Are you sure you are in the right directory?',
JawsError.errorCodes.UNKNOWN
'Could\'nt find your JAWS Project. Are you sure you are in the right directory?',
JawsError.errorCodes.UNKNOWN
));
}
@ -32,7 +32,7 @@ module.exports = function(JAWS) {
// Prepare URL
var repo = {};
url = url.replace('https://', '').replace('http://', '').replace('www.', '').split('/'); //TODO: why not regex?
url = url.replace('https://', '').replace('http://', '').replace('www.', '').split('/'); //TODO: why not regex?
repo.owner = url[1];
repo.repo = url[2];
repo.branch = 'master';
@ -46,8 +46,8 @@ module.exports = function(JAWS) {
// Throw error if invalid url
if (url[0] !== 'github.com' || !repo.owner || !repo.repo) {
reject(new JawsError(
'Must be a github url in this format: https://github.com/jaws-stack/JAWS',
JawsError.errorCodes.UNKNOWN
'Must be a github url in this format: https://github.com/jaws-stack/JAWS',
JawsError.errorCodes.UNKNOWN
));
}
@ -60,81 +60,81 @@ module.exports = function(JAWS) {
// Download module
new Download({
timeout: 30000,
extract: true,
strip: 1,
mode: '755',
})
.get(downloadUrl)
.dest(tempDirPath)
.run(function(error) {
timeout: 30000,
extract: true,
strip: 1,
mode: '755',
})
.get(downloadUrl)
.dest(tempDirPath)
.run(function(error) {
if (error) {
console.error('Module Download and installation failed.');
reject(error);
}
// Fetch module's jaws.json
try {
var jawsJson = require(tempDirPath + '/jaws.json');
} catch (e) {
// Remove module and report if malformed
return del([tempDirPath], {
force: true,
}, function(error) {
if (error) {
console.error(error);
}
reject(e);
});
}
var backPath = path.join(JAWS._meta.projectRootPath, 'back', jawsJson.name);
// Handle according to module profile
if (['lambda', 'lambdaGroup'].indexOf(jawsJson.profile) > -1) {
// If folder exists, create unique module folder name
if (fs.existsSync(backPath)) {
for (var i = 2; i < 500; i++) {
if (!fs.existsSync(backPath + '-' + i)) {
jawsJson.name = jawsJson.name + '-' + i;
break;
}
}
}
// Copy folders into new module folder
wrench.copyDirSyncRecursive(tempDirPath, backPath, {
forceDelete: false, // Whether to overwrite existing directory or not
excludeHiddenUnix: false, // Whether to copy hidden Unix files or not (preceding .)
// filter: regexpOrFunction // A filter to match files against; if matches, do nothing (exclude).
});
} else if (jawsJson.profile === 'front') {
//TODO: implement
} else if (jawsJson.profile === 'project') {
//TODO: implement after v1
} else {
reject(new JawsError('This module has an unknown profile', JawsError.errorCodes.UNKNOWN));
}
// Delete temp directory
del([tempDirPath], {
force: true,
}, function(error) {
if (error) {
console.error('Module Download and installation failed.');
reject(error);
}
// Fetch module's jaws.json
try {
var jawsJson = require(tempDirPath + '/jaws.json');
} catch (e) {
// Remove module and report if malformed
return del([tempDirPath], {
force: true,
}, function(error) {
if (error) {
console.error(error);
}
reject(e);
});
}
var backPath = path.join(JAWS._meta.projectRootPath, 'back', jawsJson.name);
// Handle according to module profile
if (['lambda', 'lambdaGroup'].indexOf(jawsJson.profile) > -1) {
// If folder exists, create unique module folder name
if (fs.existsSync(backPath)) {
for (var i = 2; i < 500; i++) {
if (!fs.existsSync(backPath + '-' + i)) {
jawsJson.name = jawsJson.name + '-' + i;
break;
}
}
}
// Copy folders into new module folder
wrench.copyDirSyncRecursive(tempDirPath, backPath, {
forceDelete: false, // Whether to overwrite existing directory or not
excludeHiddenUnix: false, // Whether to copy hidden Unix files or not (preceding .)
// filter: regexpOrFunction // A filter to match files against; if matches, do nothing (exclude).
});
} else if (jawsJson.profile === 'front') {
//TODO:implement
} else if (jawsJson.profile === 'project') {
//TODO: implement
} else {
reject(new JawsError('This module has an unknown profile', JawsError.errorCodes.UNKNOWN));
}
// Delete temp directory
del([tempDirPath], {
force: true,
}, function(error) {
if (error) {
reject(error);
}
console.log('Module successfully installed');
resolve();
});
console.log('Module successfully installed');
resolve();
});
});
});
};
};

View File

@ -14,8 +14,8 @@ var JAWS = {};
JAWS._meta = {};
JAWS._meta.version = require('./../package.json').version;
JAWS._meta.cwd = process.cwd();
JAWS._meta.projectRootPath = utils.findProjectRootPath(process.cwd()); // Full path to project root
JAWS._meta.projectJson = utils.projectRootPath ? require(utils.projectRootPath + '/jaws.json') : false;
JAWS._meta.projectRootPath = process.env.NODE_ENV !== 'test' ? utils.findProjectRootPath(process.cwd()) : process.env.TEST_PROJECT_DIR; // Full path to project root
JAWS._meta.projectJson = JAWS._meta.projectRootPath ? require(JAWS._meta.projectRootPath + '/jaws.json') : false;
// Fetch AWS Profile
if (JAWS._meta.projectRootPath) {