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

Bring up to speed with newer SW stacks #11

Open
wants to merge 3 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
94 changes: 73 additions & 21 deletions config/testacular.conf.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,81 @@
basePath = '../app';
module.exports = function(config){
config.set({
// base path, that will be used to resolve files and exclude
basePath: '../app',

files = [
JASMINE,
JASMINE_ADAPTER,
'lib/angular/angular.js',
'lib/angular/angular-*.js',
'../test/lib/angular/angular-mocks.js',
// list of files / patterns to load in the browser
files: [
'lib/angular/angular.js',
'lib/angular/angular-*.js',
'../test/lib/angular/angular-mocks.js',
{pattern: '**/*.js', watched: true, included: true, served: true},

'js/app.js',
'js/**/*.js',
'../test/unit/**/*.js',
'js/app.js',
'js/**/*.js',
'../test/unit/**/*.js',

// templates
'js/directives/**/*.html'
];
// templates
'js/directives/**/*.html'
],

preprocessors = {
'**/*.html': 'html2js'
};
// list of files to exclude
exclude: [

],

preprocessors: {
'**/*.html': 'html2js'
},

proxies: {

},

// test results reporter to use
// possible values: 'dots', 'progress', 'junit', 'growl', 'coverage'
reporters: ['progress'],

// web server port
port: 9876,

// enable / disable colors in the output (reporters and logs)
colors: true,

// level of logging
// possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
logLevel: config.LOG_INFO,

autoWatch: true,

// frameworks to use
frameworks: ['jasmine'],

// Start these browsers, currently available:
// - Chrome
// - ChromeCanary
// - Firefox
// - Opera
// - Safari (only Mac)
// - PhantomJS
// - IE (only Windows)
browsers: [
'Chrome',
'Firefox',
'IE'
],

autoWatch = true;
plugins: [
'karma-chrome-launcher',
'karma-firefox-launcher',
'karma-script-launcher',
'karma-jasmine'
],

browsers = ['Chrome'];
// If browser does not capture in given timeout [ms], kill it
captureTimeout: 60000,

junitReporter = {
outputFile: 'test_out/unit.xml',
suite: 'unit'
// Continuous Integration mode
// if true, it capture browsers, run tests and exit
singleRun: false
});
};
16 changes: 14 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,22 @@
"express": ">= 3.0.0",
"csv": ">= 0.2.1",
"open": ">= 0.0.2",
"testacular": "canary"
"testacular": "canary",
"morgan": "~1.5.1",
"body-parser": "~1.11.0"
},
"engines": {
"node": ">= 0.8.4"
},
"license": "MIT"
"license": "MIT",
"devDependencies": {
"karma": "~0.12.31",
"jasmine-core": "~2.2.0",
"karma-jasmine": "~0.3.5",
"karma-firefox-launcher": "~0.1.4",
"karma-chrome-launcher": "~0.1.7",
"html2js": "~0.1.0",
"karma-script-launcher": "~0.1.0",
"karma-ie-launcher": "~0.1.5"
}
}
4 changes: 2 additions & 2 deletions scripts/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
BASE_DIR=`dirname $0`

echo ""
echo "Starting Testacular Server (http://vojtajina.github.com/testacular)"
echo "Starting Karma Server (http://vojtajina.github.com/testacular)"
echo "-------------------------------------------------------------------"

$BASE_DIR/../node_modules/testacular/bin/testacular start $BASE_DIR/../config/testacular.conf.js $*
$BASE_DIR/../node_modules/karma/bin/karma start $BASE_DIR/../config/testacular.conf.js $*
31 changes: 17 additions & 14 deletions server/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
var express = require('express');
var fs = require('fs');
var open = require('open');
var logger = require('morgan');
var bodyParser = require('body-parser');

var RestaurantRecord = require('./model').Restaurant;
var MemoryStorage = require('./storage').Memory;
Expand All @@ -27,18 +29,19 @@ exports.start = function(PORT, STATIC_DIR, DATA_FILE, TEST_DIR) {
var storage = new MemoryStorage();

// log requests
app.use(express.logger('dev'));
app.use(logger('dev'));

// serve static files for demo client
app.use(express.static(STATIC_DIR));

// parse body into req.body
app.use(express.bodyParser());
app.use(bodyParser.urlencoded({extended:true}));
app.use(bodyParser.json());


// API
app.get(API_URL, function(req, res, next) {
res.send(200, storage.getAll().map(removeMenuItems));
res.status(200).send(storage.getAll().map(removeMenuItems));
});


Expand All @@ -48,26 +51,26 @@ exports.start = function(PORT, STATIC_DIR, DATA_FILE, TEST_DIR) {

if (restaurant.validate(errors)) {
storage.add(restaurant);
return res.send(201, restaurant);
return res.status(201).send(restaurant);
}

return res.send(400, {error: errors});
return res.status(400).send({error: errors});
});

app.post(API_URL_ORDER, function(req, res, next) {
console.log(req.body)
return res.send(201, { orderId: Date.now()});
return res.status(201).send({ orderId: Date.now()});
});


app.get(API_URL_ID, function(req, res, next) {
var restaurant = storage.getById(req.params.id);

if (restaurant) {
return res.send(200, restaurant);
return res.status(200).send(restaurant);
}

return res.send(400, {error: 'No restaurant with id "' + req.params.id + '"!'});
return res.status(400).send({error: 'No restaurant with id "' + req.params.id + '"!'});
});


Expand All @@ -77,25 +80,25 @@ exports.start = function(PORT, STATIC_DIR, DATA_FILE, TEST_DIR) {

if (restaurant) {
restaurant.update(req.body);
return res.send(200, restaurant);
return res.status(200).send(restaurant);
}

restaurant = new RestaurantRecord(req.body);
if (restaurant.validate(errors)) {
storage.add(restaurant);
return res.send(201, restaurant);
return res.status(201).send(restaurant);
}

return res.send(400, {error: errors});
return res.status(400).send({error: errors});
});


app.del(API_URL_ID, function(req, res, next) {
app.delete(API_URL_ID, function(req, res, next) {
if (storage.deleteById(req.params.id)) {
return res.send(204, null);
return res.status(204).send(null);
}

return res.send(400, {error: 'No restaurant with id "' + req.params.id + '"!'});
return res.status(400).send({error: 'No restaurant with id "' + req.params.id + '"!'});
});


Expand Down