refactor for mocha

This commit is contained in:
ryanp 2015-09-01 20:57:52 -05:00
parent 547631a66f
commit f8d5db033b
9 changed files with 118 additions and 112 deletions

View File

@ -1,48 +1,22 @@
'use strict';
/**
* JAWS: Spot Tests
* @type {async|exports|module.exports}
*/
var async = require('async'),
os = require('os'),
path = require('path'),
AWS = require('aws-sdk'),
shortid = require('shortid');
require('config'); //init config
// Require ENV vars
require('dotenv').config({ path: __dirname + '/.env' });
describe('AllTests', function() {
before(function(done) {
this.timeout(0); //dont timeout anything
done();
});
// Define Test Data
var testData = {};
testData.name = 'test-prj';
testData.notifyEmail = 'tester@jawsstack.com';
testData.stage = 'unittest';
testData.region = 'us-east-1';
testData.envBucket = process.env.TEST_JAWS_ENV_BUCKET;
testData.profile = process.env.TEST_JAWS_PROFILE;
testData.iamRoleARN = process.env.TEST_JAWS_IAM_ROLE;
after(function() {
});
// Add aws-sdk to Test Data Object (helps clean up test resources, etc.)
testData.AWS = require('aws-sdk');
testData.AWS.config.credentials = new testData.AWS.SharedIniFileCredentials({
profile: testData.profile,
});
testData.AWS.config.update({
region: testData.region,
});
// Require Tests ("new" must be last)
var tests = [
require('./tests/tag'),
require('./tests/deploy_lambda'),
require('./tests/deploy_api'),
require('./tests/install'),
require('./tests/env'),
require('./tests/new'),
];
// Run Tests
async.eachSeries(tests, function(test, cb) {
test(testData, function(testData) { return cb(); });
}, function(error) { console.log('Tests completed'); });
//require tests vs inline so we can run sequentially
// Require Tests ("new" must be last)
require('./cli/tag');
require('./cli/deploy_lambda');
require('./cli/deploy_api');
require('./cli/install');
require('./cli/env');
require('./cli/new');
});

74
tests/cli/new.js Normal file
View File

@ -0,0 +1,74 @@
'use strict';
/**
* JAWS Test: New Command
* - Creates a new project in your system's temp directory
* - Deletes the CF stack created by the project
*/
var path = require('path'),
os = require('os'),
assert = require('chai').assert,
shortid = require('shortid'),
AWS = require('aws-sdk');
var config = require('./config');
describe('Test new command', function() {
before(function(done) {
config.newName = 'jaws-test-' + shortid.generate();
process.chdir(os.tmpdir());
done();
});
after(function(done) {
done();
});
describe('Positive tests', function() {
it('Create new project', function(done) {
this.timeout(0);
// Require
var JAWS = require('../../lib/index.js'),
JawsError = require('../../lib/jaws-error');
// Test
JAWS.new(
config.newName,
config.stage,
config.envBucket,
config.region,
config.notifyEmail,
config.profile
)
.then(function() {
var jawsJson = require(path.join(os.tmpdir(), config.newName, 'jaws.json'));
assert.isTrue(!!jawsJson.project.regions['us-east-1'].stages[config.stage].iamRoleArn);
done();
})
.catch(JawsError, function(e) {
done(e);
})
.error(function(e) {
done(e);
});
});
});
describe('Error tests', function() {
it('Create new project', function(done) {
done();
})
});
//it('Delete Cloudformation stack from new project', function(done) {
// this.timeout(0);
// var CF = new config.AWS.CloudFormation();
// CF.deleteStack({ StackName: config.stage + '-' + config.name }, function(err, data) {
// if (err) console.log(err, err.stack);
// done();
// });
//});
});

27
tests/config.js Normal file
View File

@ -0,0 +1,27 @@
'use strict';
var path = require('path'),
AWS = require('aws-sdk');
// Require ENV vars
require('dotenv').config({path: __dirname + '/.env'});
var config = {
name: 'test-prj',
notifyEmail: 'tester@jawsstack.com',
stage: 'unittest',
region: 'us-east-1',
envBucket: process.env.TEST_JAWS_ENV_BUCKET,
profile: process.env.TEST_JAWS_PROFILE,
iamRoleARN: process.env.TEST_JAWS_IAM_ROLE,
};
AWS.config.credentials = new AWS.SharedIniFileCredentials({
profile: config.profile,
});
AWS.config.update({
region: config.region,
});
module.exports = config;

View File

@ -1,69 +0,0 @@
'use strict';
/**
* JAWS Test: New Command
* - Creates a new project in your system's temp directory
* - Deletes the CF stack created by the project
*/
var path = require('path'),
os = require('os'),
assert = require('chai').assert,
testUtils = require('../test_utils'),
shortid = require('shortid'),
AWS = require('aws-sdk');
module.exports = function(testData, cb) {
describe('Test new command', function() {
before(function(done) {
testData.newName = 'jaws-test-' + shortid.generate();
process.chdir(os.tmpdir());
done();
});
after(function(done) {
cb(testData);
done();
});
it('Create new project without errors', function(done) {
this.timeout(0);
// Require
var JAWS = require('../../lib/index.js'),
JawsError = require('../../lib/jaws-error');
// Test
JAWS.new(
testData.newName,
testData.stage,
testData.envBucket,
testData.region,
testData.notifyEmail,
testData.profile
)
.then(function() {
var jawsJson = require(path.join(os.tmpdir(), testData.newName, 'jaws.json'));
assert.isTrue(!!jawsJson.project.regions['us-east-1'].stages[testData.stage].iamRoleArn);
done();
})
.catch(JawsError, function(e) {
done(e);
})
.error(function(e) {
done(e);
});
});
//it('Delete Cloudformation stack from new project', function(done) {
// this.timeout(0);
// var CF = new testData.AWS.CloudFormation();
// CF.deleteStack({ StackName: testData.stage + '-' + testData.name }, function(err, data) {
// if (err) console.log(err, err.stack);
// done();
// });
//});
});
};