From e10ddf3c0902b7488e353054d8b1b37fcfd2c1ab Mon Sep 17 00:00:00 2001 From: Tomer Barletz Date: Tue, 10 Feb 2015 01:49:55 -0800 Subject: [PATCH 1/3] Update to support latest Express (morga, body-parser). --- package.json | 4 +++- server/index.js | 7 +++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index b6aa6383..09bd2e86 100644 --- a/package.json +++ b/package.json @@ -22,7 +22,9 @@ "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" diff --git a/server/index.js b/server/index.js index 34813b22..cb0cbedb 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,13 +29,14 @@ 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 From 6b18bc84ab5bc733fe644084ada14700af463c9c Mon Sep 17 00:00:00 2001 From: Tomer Barletz Date: Tue, 10 Feb 2015 01:56:22 -0800 Subject: [PATCH 2/3] Fix deprecated functions. --- server/index.js | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/server/index.js b/server/index.js index cb0cbedb..4f350615 100644 --- a/server/index.js +++ b/server/index.js @@ -41,7 +41,7 @@ exports.start = function(PORT, STATIC_DIR, DATA_FILE, TEST_DIR) { // API app.get(API_URL, function(req, res, next) { - res.send(200, storage.getAll().map(removeMenuItems)); + res.status(200).send(storage.getAll().map(removeMenuItems)); }); @@ -51,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()}); }); @@ -67,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 + '"!'}); }); @@ -80,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 + '"!'}); }); From a6e50a511c8698938d520c7b46ef9a84be47c2f5 Mon Sep 17 00:00:00 2001 From: Tomer Barletz Date: Tue, 10 Feb 2015 02:03:08 -0800 Subject: [PATCH 3/3] Migrate testacular->karma. --- config/testacular.conf.js | 94 ++++++++++++++++++++++++++++++--------- package.json | 12 ++++- scripts/test.sh | 4 +- 3 files changed, 86 insertions(+), 24 deletions(-) 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 09bd2e86..5f1656c2 100644 --- a/package.json +++ b/package.json @@ -29,5 +29,15 @@ "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 $*