Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
chefArchitect committed Jun 10, 2016
2 parents c421ffa + 78568ba commit d091dec
Show file tree
Hide file tree
Showing 10 changed files with 254 additions and 194 deletions.
11 changes: 11 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# editorconfig.org

root = true

[*]
charset = utf-8
insert_final_newline = true
trim_trailing_whitespace = true
end_of_line = lf
indent_style = space
indent_size = 2
36 changes: 36 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"env": {
"node": true
},
"parserOptions": {
"ecmaVersion": 6,
"sourceType": "module",
"ecmaFeatures": {
"jsx": true
}
},
"rules": {
"array-bracket-spacing": [2, "never"],
"block-scoped-var": 2,
"brace-style": [2, "1tbs"],
"camelcase": 1,
"computed-property-spacing": [2, "never"],
"curly": 2,
"eol-last": 2,
"eqeqeq": [2, "smart"],
"max-depth": [1, 3],
"max-len": [1, 80],
"max-statements": [1, 15],
"new-cap": 1,
"no-extend-native": 2,
"no-mixed-spaces-and-tabs": 2,
"no-trailing-spaces": 2,
"no-unused-vars": 1,
"no-use-before-define": [2, "nofunc"],
"object-curly-spacing": [2, "never"],
"quotes": [2, "single", "avoid-escape"],
"semi": [2, "always"],
"keyword-spacing": [2, {"before": true, "after": true}],
"space-unary-ops": 2
}
}
16 changes: 16 additions & 0 deletions .jshintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"camelcase": true,
"curly": true,
"eqeqeq": true,
"freeze": true,
"indent": 2,
"newcap": true,
"quotmark": "single",
"maxdepth": 3,
"maxstatements": 15,
"maxlen": 80,
"eqnull": true,
"funcscope": true,
"node": true,
"esversion": 6
}
24 changes: 7 additions & 17 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
##################################################################
# API Spots - BDD Testing API
#
# API Spots - BDD Testing API
#
# Description
# -----------
# Installs a RESTful API that can be used for executing BDD
Expand All @@ -10,26 +10,17 @@
# Author: Chris Spiliotopoulos (@chefArchitect)
##################################################################

# Use latest Ubuntu image
FROM ubuntu:latest

# Install nodejs from repos
RUN apt-get update
RUN apt-get install -y nodejs
RUN apt-get install -y nodejs-legacy

# Install latest 'npm' service
RUN apt-get install -y npm
# Use latest Node image
FROM node:latest

# Install 'forever' service
RUN npm install forever -g

# Install 'wget'
RUN apt-get install -y wget

# Copy sources to a new folder called 'app'
COPY . /app

RUN node --version

# Install app dependencies
RUN cd app && npm install

Expand All @@ -40,5 +31,4 @@ WORKDIR /app
EXPOSE 3000

# Start the app using 'forever' service
CMD node rest/server.js

CMD forever rest/server.js
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name":"apispots-testing-bdd",
"version":"1.0.0",
"version":"1.0.1",
"description":"Adds a BDD layer to API automated testing.",
"author": "Chris Spiliotopoulos (@chefArchitect)",
"contributors":[
Expand Down
116 changes: 61 additions & 55 deletions rest/routes.js
Original file line number Diff line number Diff line change
@@ -1,67 +1,73 @@
/**
* API Routes.
*
*
* @author Chris Spiliotopoulos
*/
var Joi = require('joi');
var fs = require('fs');
var path = require('path');

var TestsService = require('./services/TestsService');

/*
* API routes
*/
module.exports = function(server) {

/**
* POST /tests/run
*
* Executes a single BDD test file
*/
server
.route({
path : '/tests/run',
method : 'POST',
config : {
tags : [ 'api' ],
description : 'Executes a single BDD test',
notes : 'Upload and execute a BDD test feature file described using the Gherkin3 syntax.',
validate : {
payload : Joi.object().keys({
'file' : Joi.object().meta({
swaggerType : 'file'
}).required().description('A file containing a valid test feature written in Gherkin3 syntax'),
'tags' : Joi.string().description('A comma-separated list of @ tags to be executed within the test file, e.g @dev,@test'),
})

},
payload : {
allow : 'multipart/form-data',
output : 'file',
parse : true
},
handler : function(request, reply) {

var payload = request.payload;

// get the request data
var file = payload.file.path;
var tags = payload.tags;

if (typeof tags !== 'undefined')
tags = decodeURIComponent(tags);

/*
* Run the test
*/
TestsService.runTest(file, tags, function(success, logs) {

return reply(logs).code( (success ? 200 : 400) );
});

}
}
});

}

/**
* POST /tests/run
*
* Executes a single BDD test file
*/
server
.route({
path: '/tests/run',
method: 'POST',
config: {
tags: ['api'],
description: 'Executes a single BDD test',
notes: 'Upload and execute a BDD test feature file described ' +
' using the Gherkin3 syntax.',
validate: {
payload: Joi.object().keys({
'file': Joi.object().meta({
swaggerType: 'file'
}).required().description('A file containing a valid ' +
'test feature written in Gherkin3 syntax'),
'tags': Joi.string().description('A comma-separated list ' +
'of @ tags to be executed within the test file, e.g @dev,@test'),
'format': Joi.string().required()
.valid(['pretty', 'summary', 'json'])
.description('Format to be used for presenting test results')
.default('pretty')
})
},
payload: {
allow: 'multipart/form-data',
output: 'file',
parse: true
},
handler: function(request, reply) {

var payload = request.payload;

// get the request data
var file = payload.file.path;
var tags = payload.tags;
var format = payload.format;

if (typeof tags !== 'undefined') {
tags = decodeURIComponent(tags);
}

/*
* Run the test
*/
TestsService.runTest(file, tags, format, function(success, logs) {

return reply(logs).code((success ? 200 : 400));
});

}
}
});

};
5 changes: 1 addition & 4 deletions rest/server.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
var nconf = require('nconf');
var path = require('path');

var BootstrapService = require('./services/BootstrapService');


/**
* Setup the service
*/
BootstrapService.setup(function(){
BootstrapService.setup(function() {



Expand Down
40 changes: 19 additions & 21 deletions rest/services/BootstrapService.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,10 @@
*/

var log = require('winston');
var fs = require('fs');
var async = require("async");
var nconf = require('nconf');
var Hapi = require('hapi');
var Path = require('path');
var Good = require('good');
var Joi = require('joi');
var Inert = require("inert");
var Vision = require("vision");
var Inert = require('inert');
var Vision = require('vision');
var hapiSwaggered = require('hapi-swaggered');
var hapiSwaggeredUi = require('hapi-swaggered-ui');

Expand All @@ -22,9 +17,6 @@ module.exports = function() {
// is the environment initialized?
var _initialized = false;

// Array to hold async tasks
var _asyncTasks = [];

// the server instance
var _server = null;

Expand All @@ -39,7 +31,10 @@ module.exports = function() {
log.info('Initializing logging framework...');

// Console transport
if ((nconf.get()) && (typeof nconf.get().logging != 'undefined') && (typeof nconf.get().logging.console != 'undefined') && (typeof nconf.get().logging.console.level != 'undefined')) {
if ((nconf.get()) &&
(typeof nconf.get().logging !== 'undefined') &&
(typeof nconf.get().logging.console !== 'undefined') &&
(typeof nconf.get().logging.console.level !== 'undefined')) {

// log.transports.Console.level = nconf.get().logging.console.level;
log.remove(log.transports.Console);
Expand All @@ -49,11 +44,13 @@ module.exports = function() {
colorize: true
});

log.info('|_ Added Console transport [Level: ' + nconf.get().logging.console.level + ']');
log.info('|_ Added Console transport [Level: ' +
nconf.get().logging.console.level + ']');
}

if (callback)
if (callback) {
callback();
}
}

/**
Expand All @@ -73,7 +70,7 @@ module.exports = function() {
* and Swagger plugin
*/
_server.connection({
port: 3000,
port: 3000,
labels: ['api'],
routes: {
cors: false
Expand Down Expand Up @@ -114,8 +111,7 @@ module.exports = function() {
_server.register([
Inert,
Vision,
/* register other plugins including hapi-swaggered and hapi-swaggered-ui */
], function(err) {})
]);

_server.register({
register: hapiSwaggered,
Expand All @@ -127,7 +123,7 @@ module.exports = function() {
}
}, function(err) {
if (err) {
throw err
throw err;
}
});

Expand All @@ -146,7 +142,7 @@ module.exports = function() {
}
}, function(err) {
if (err) {
throw err
throw err;
}
});

Expand All @@ -158,7 +154,7 @@ module.exports = function() {
/**
* Sets up the server plugins
*/
function _setupRouting(callback) {
function _setupRouting() {

try {

Expand All @@ -179,8 +175,9 @@ module.exports = function() {
*/
setup: function(callback) {

if (_initialized)
if (_initialized) {
return;
}

log.info('==========================================');
log.info('Setting up contexts...');
Expand Down Expand Up @@ -209,8 +206,9 @@ module.exports = function() {
_initialized = true;

// notify listeners
if (callback)
if (callback) {
callback();
}
});

}
Expand Down
Loading

0 comments on commit d091dec

Please sign in to comment.