diff --git a/config/testacular.conf.js b/config/testacular.conf.js index 96b7bb36..9f5a56fb 100644 --- a/config/testacular.conf.js +++ b/config/testacular.conf.js @@ -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 + }); }; diff --git a/package.json b/package.json index b6aa6383..5f1656c2 100644 --- a/package.json +++ b/package.json @@ -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" + } } diff --git a/scripts/test.sh b/scripts/test.sh index 7bab1867..14b5c9c1 100755 --- a/scripts/test.sh +++ b/scripts/test.sh @@ -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 $* diff --git a/server/index.js b/server/index.js index 34813b22..4f350615 100644 --- a/server/index.js +++ b/server/index.js @@ -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; @@ -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)); }); @@ -48,15 +51,15 @@ 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()}); }); @@ -64,10 +67,10 @@ exports.start = function(PORT, STATIC_DIR, DATA_FILE, TEST_DIR) { 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 + '"!'}); }); @@ -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 + '"!'}); });