Skip to content

Instantly share code, notes, and snippets.

@jzerbe
Created March 22, 2015 17:03
Show Gist options
  • Save jzerbe/083994efc0bcdb043660 to your computer and use it in GitHub Desktop.
Save jzerbe/083994efc0bcdb043660 to your computer and use it in GitHub Desktop.
karma and mocked backend server configurations
module.exports = function(config) {
config.set({
browsers: ["PhantomJS"],
coverageReporter: {
dir: 'report/coverage/',
reporters: [
{type: 'html', subdir: 'html'},
{type: 'text'}
]
},
exclude: ['build/src/annotation_upload_*.js'],
files: [
'build/src/SupportedMethods.js',
'build/src/Interfaces/*.js',
'build/src/Bundle/*.js',
'build/src/Task/Base.js',
'build/src/**/*.js',
'build/test/**/*.js'
],
frameworks: ['jasmine'],
junitReporter: {
outputFile: './test/results.xml'
},
logLevel: config.LOG_DEBUG,
preprocessors: {
'build/src/**/*.js': ['coverage']
},
proxies: {
'/api': 'http://localhost:3000/api'
},
reporters: ['coverage', 'junit', 'progress'],
singleRun: true
});
};
var type_key = 'Content-Type';
var type_json = 'application/json';
var prefix_request_in = '[test backend]: request received for';
var prefix_response_out = '[test backend]: response sent for';
var express = require('express');
var app = express();
// test/Task/CooThing.spec.ts
app.get('/api/v1.0/namespace/service/model/*resource_id*', function (req, res) {
console.log('%s namespace bundle', prefix_request_in);
res.set(type_key, type_json).send(
{
"status": 200,
"reason": "OK",
"messages": [],
"result": 'string'
}
);
console.log('%s namespace bundle', prefix_response_out);
});
// start the server
var server = app.listen(3000, function () {
var host = server.address().address;
var port = server.address().port;
console.log('[test backend]: listening at http://%s:%s', host, port);
});
// server KILL handler for graceful shutdown
process.on('SIGTERM', function () {
console.log('[test backend]: stopping');
server.close();
console.log('[test backend]: stopped');
process.exit();
});
#!/bin/bash
ps aux | grep 'server.js' | grep 'node' | awk '{ print $2 }' | xargs kill
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment