Skip to content

Commit

Permalink
feat(progess): emit progress-update (#2498)
Browse files Browse the repository at this point in the history
closes: #1666
  • Loading branch information
hiroppy committed Apr 3, 2020
1 parent adeb92e commit 4808abd
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
4 changes: 4 additions & 0 deletions lib/Server.js
Expand Up @@ -155,6 +155,10 @@ class Server {
}

this.sockWrite(this.sockets, 'progress-update', { percent, msg });

if (this.listeningApp) {
this.listeningApp.emit('progress-update', { percent, msg });
}
}).apply(this.compiler);
}

Expand Down
10 changes: 6 additions & 4 deletions lib/servers/WebsocketServer.js
Expand Up @@ -31,11 +31,13 @@ module.exports = class WebsocketServer extends BaseServer {
const noop = () => {};

setInterval(() => {
this.wsServer.clients.forEach((ws) => {
if (ws.isAlive === false) return ws.terminate();
this.wsServer.clients.forEach((socket) => {
if (socket.isAlive === false) {
return socket.terminate();
}

ws.isAlive = false;
ws.ping(noop);
socket.isAlive = false;
socket.ping(noop);
});
}, this.server.heartbeatInterval);
}
Expand Down
8 changes: 7 additions & 1 deletion test/server/progress-option.test.js
Expand Up @@ -46,7 +46,13 @@ describe('progress', () => {
});

compiler.run(() => {});
server.listen(port, 'localhost');
const app = server.listen(port, 'localhost');

app.on('progress-update', ({ percent, msg }) => {
expect(percent).toBeGreaterThanOrEqual(0);
expect(percent).toBeLessThanOrEqual(100);
expect(typeof msg).toEqual('string');
});
});
});
});

0 comments on commit 4808abd

Please sign in to comment.