From f8d5db033bfca95a73745a39e1af331c4d28892d Mon Sep 17 00:00:00 2001 From: ryanp Date: Tue, 1 Sep 2015 20:57:52 -0500 Subject: [PATCH] refactor for mocha --- tests/all.js | 60 ++++++---------------- tests/{tests => cli}/deploy_api.js | 0 tests/{tests => cli}/deploy_lambda.js | 0 tests/{tests => cli}/env.js | 0 tests/{tests => cli}/install.js | 0 tests/cli/new.js | 74 +++++++++++++++++++++++++++ tests/{tests => cli}/tag.js | 0 tests/config.js | 27 ++++++++++ tests/tests/new.js | 69 ------------------------- 9 files changed, 118 insertions(+), 112 deletions(-) rename tests/{tests => cli}/deploy_api.js (100%) rename tests/{tests => cli}/deploy_lambda.js (100%) rename tests/{tests => cli}/env.js (100%) rename tests/{tests => cli}/install.js (100%) create mode 100644 tests/cli/new.js rename tests/{tests => cli}/tag.js (100%) create mode 100644 tests/config.js delete mode 100644 tests/tests/new.js diff --git a/tests/all.js b/tests/all.js index 422dfb5d8..20d603a65 100644 --- a/tests/all.js +++ b/tests/all.js @@ -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'); }); \ No newline at end of file + //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'); +}); \ No newline at end of file diff --git a/tests/tests/deploy_api.js b/tests/cli/deploy_api.js similarity index 100% rename from tests/tests/deploy_api.js rename to tests/cli/deploy_api.js diff --git a/tests/tests/deploy_lambda.js b/tests/cli/deploy_lambda.js similarity index 100% rename from tests/tests/deploy_lambda.js rename to tests/cli/deploy_lambda.js diff --git a/tests/tests/env.js b/tests/cli/env.js similarity index 100% rename from tests/tests/env.js rename to tests/cli/env.js diff --git a/tests/tests/install.js b/tests/cli/install.js similarity index 100% rename from tests/tests/install.js rename to tests/cli/install.js diff --git a/tests/cli/new.js b/tests/cli/new.js new file mode 100644 index 000000000..0fa62fdf0 --- /dev/null +++ b/tests/cli/new.js @@ -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(); + // }); + //}); +}); \ No newline at end of file diff --git a/tests/tests/tag.js b/tests/cli/tag.js similarity index 100% rename from tests/tests/tag.js rename to tests/cli/tag.js diff --git a/tests/config.js b/tests/config.js new file mode 100644 index 000000000..22d889d64 --- /dev/null +++ b/tests/config.js @@ -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; \ No newline at end of file diff --git a/tests/tests/new.js b/tests/tests/new.js deleted file mode 100644 index 1e8bd1036..000000000 --- a/tests/tests/new.js +++ /dev/null @@ -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(); - // }); - //}); - }); -}; \ No newline at end of file