Skip to content

Commit

Permalink
Update dev server to include Karma tests
Browse files Browse the repository at this point in the history
  • Loading branch information
astralarya committed Aug 19, 2016
1 parent 46cdb6d commit d2a3ec2
Showing 1 changed file with 46 additions and 27 deletions.
73 changes: 46 additions & 27 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,31 @@

const PORT=8080;

const webpack = require('webpack');
const karma = require('karma');
const express = require('express');
const colors = require('colors');
const os = require('os');

// Webpack build server
var webpack = require('webpack');
var config = require('./webpack.config.js');
var compiler = webpack(config);
var colors = require('colors');
// Status logging
function serverStatus() {
console.log("Server listening on:")
console.log(colors.cyan(`http://localhost:${PORT}`));

var logSemaphore = 0;
compiler.watch({},function(err,stats) {
console.log(stats.toString({colors:true,chunks:false,children:false}));
let ifaces = os.networkInterfaces();
Object.keys(ifaces).forEach(function (ifname) {
ifaces[ifname].forEach(function (iface) {
if ('IPv4' === iface.family && iface.internal === false) {
console.log(colors.cyan(`http://${iface.address}:${PORT}`));
}
});
});
}
let logSemaphore = 0;
function logStart() {
logSemaphore++;
}
function logEnd() {
setTimeout(function() {
logSemaphore--;
if(logSemaphore == 0) {
Expand All @@ -23,32 +37,37 @@ compiler.watch({},function(err,stats) {
console.log();
}
},100);
}

// Webpack build server
let compiler = webpack(require('./webpack.config.js'));
compiler.watch({},function(err,stats) {
console.log(stats.toString({colors:true,chunks:false,children:false}));
logStart();
logEnd();
});

// Karma test server
let karmaServer = new karma.Server({
configFile: `${__dirname}/karma.conf.js`,
singleRun: false,
});
karmaServer.on('run_start', function() {
logStart();
});
karmaServer.on('run_complete', function() {
logEnd();
});
karmaServer.start();

// Express web server
var express = require('express');
var app = express();
var os = require('os');
var ifaces = os.networkInterfaces();
let app = express();

app.use('/dist', express.static(__dirname + '/dev/dist'));
app.use('/dist', express.static(`${__dirname}/dev/dist`));
app.get('/', function(req, res) {
res.sendFile(__dirname + '/dev/index.html');
res.sendFile(`${dirname}/dev/index.html`);
});

app.listen(PORT, function() {
serverStatus();
});

function serverStatus() {
console.log("Server listening on:")
console.log(colors.cyan("http://localhost:%s"), PORT);

Object.keys(ifaces).forEach(function (ifname) {
ifaces[ifname].forEach(function (iface) {
if ('IPv4' === iface.family && iface.internal === false) {
console.log(colors.cyan("http://%s:%s"), iface.address, PORT);
}
});
});
}

0 comments on commit d2a3ec2

Please sign in to comment.