-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
62 lines (41 loc) · 1.18 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
'use strict';
const fs = require('fs');
const koa = require('koa');
const ipv4 = require('ipv4');
const path = require('path');
const detectPort = require('detect-port');
var server = require('http').createServer();
var io = require('socket.io')(server);
const app = koa();
const macacaReporterRender = require('macaca-reporter/lib/render');
var socketed = false;
app.use(function * () {
const mockData = require('macaca-reporter/test/mock');
console.log(JSON.stringify(mockData));
var port = yield detectPort(56788);
macacaReporterRender(mockData, {
socket: {
server: `http://localhost:${port}`
}
});
this.body = fs.readFileSync(path.join(__dirname, 'reports', 'index.html'), 'utf8');
if (socketed) {
return;
}
socketed = true;
server.listen(port);
io.on('connection', function(socket) {
console.log('socket connection');
setInterval(() => {
console.log('broadcast');
mockData.stats.passes++;
io.sockets.emit('update reporter', mockData);
}, 1000);
socket.on('disconnect', function() {
});
});
});
const port = 9001;
app.listen(port, () => {
console.log(`server start at: http://${ipv4}:${port}`);
});