elm-test
Version:
Run elm-test suites.
30 lines (24 loc) • 952 B
JavaScript
var net = require('net'),
client = net.createConnection(pipeFilename);
client.on('error', function (error) {
console.error(error);
client.end();
process.exit(1);
});
client.setEncoding('utf8');
client.setNoDelay(true);
// Run the Elm app.
var app = Elm.Test.Generated.Main.init({ flags: Date.now() });
client.on('data', function (msg) {
app.ports.elmTestPort__receive.send(JSON.parse(msg));
});
// Use ports for inter-process communication.
app.ports.elmTestPort__send.subscribe(function (msg) {
// We split incoming messages on the socket on newlines. The gist is that node
// is rather unpredictable in whether or not a single `write` will result in a
// single `on('data')` callback. Sometimes it does, sometimes multiple writes
// result in a single callback and - worst of all - sometimes a single read
// results in multiple callbacks, each receiving a piece of the data. The
// horror.
client.write(msg + '\n');
});