Skip to content

Commit d2a3ec2

Browse files
committed
Update dev server to include Karma tests
1 parent 46cdb6d commit d2a3ec2

File tree

1 file changed

+46
-27
lines changed

1 file changed

+46
-27
lines changed

server.js

Lines changed: 46 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,31 @@
44

55
const PORT=8080;
66

7+
const webpack = require('webpack');
8+
const karma = require('karma');
9+
const express = require('express');
10+
const colors = require('colors');
11+
const os = require('os');
712

8-
// Webpack build server
9-
var webpack = require('webpack');
10-
var config = require('./webpack.config.js');
11-
var compiler = webpack(config);
12-
var colors = require('colors');
13+
// Status logging
14+
function serverStatus() {
15+
console.log("Server listening on:")
16+
console.log(colors.cyan(`http://localhost:${PORT}`));
1317

14-
var logSemaphore = 0;
15-
compiler.watch({},function(err,stats) {
16-
console.log(stats.toString({colors:true,chunks:false,children:false}));
18+
let ifaces = os.networkInterfaces();
19+
Object.keys(ifaces).forEach(function (ifname) {
20+
ifaces[ifname].forEach(function (iface) {
21+
if ('IPv4' === iface.family && iface.internal === false) {
22+
console.log(colors.cyan(`http://${iface.address}:${PORT}`));
23+
}
24+
});
25+
});
26+
}
27+
let logSemaphore = 0;
28+
function logStart() {
1729
logSemaphore++;
30+
}
31+
function logEnd() {
1832
setTimeout(function() {
1933
logSemaphore--;
2034
if(logSemaphore == 0) {
@@ -23,32 +37,37 @@ compiler.watch({},function(err,stats) {
2337
console.log();
2438
}
2539
},100);
40+
}
41+
42+
// Webpack build server
43+
let compiler = webpack(require('./webpack.config.js'));
44+
compiler.watch({},function(err,stats) {
45+
console.log(stats.toString({colors:true,chunks:false,children:false}));
46+
logStart();
47+
logEnd();
48+
});
49+
50+
// Karma test server
51+
let karmaServer = new karma.Server({
52+
configFile: `${__dirname}/karma.conf.js`,
53+
singleRun: false,
54+
});
55+
karmaServer.on('run_start', function() {
56+
logStart();
2657
});
58+
karmaServer.on('run_complete', function() {
59+
logEnd();
60+
});
61+
karmaServer.start();
2762

2863
// Express web server
29-
var express = require('express');
30-
var app = express();
31-
var os = require('os');
32-
var ifaces = os.networkInterfaces();
64+
let app = express();
3365

34-
app.use('/dist', express.static(__dirname + '/dev/dist'));
66+
app.use('/dist', express.static(`${__dirname}/dev/dist`));
3567
app.get('/', function(req, res) {
36-
res.sendFile(__dirname + '/dev/index.html');
68+
res.sendFile(`${dirname}/dev/index.html`);
3769
});
3870

3971
app.listen(PORT, function() {
4072
serverStatus();
4173
});
42-
43-
function serverStatus() {
44-
console.log("Server listening on:")
45-
console.log(colors.cyan("http://localhost:%s"), PORT);
46-
47-
Object.keys(ifaces).forEach(function (ifname) {
48-
ifaces[ifname].forEach(function (iface) {
49-
if ('IPv4' === iface.family && iface.internal === false) {
50-
console.log(colors.cyan("http://%s:%s"), iface.address, PORT);
51-
}
52-
});
53-
});
54-
}

0 commit comments

Comments
 (0)