Skip to content

Commit

Permalink
tests: Add nodejs child_process spawner
Browse files Browse the repository at this point in the history
  • Loading branch information
rvl committed Jun 11, 2019
1 parent 20b735e commit 5cdcab3
Showing 1 changed file with 57 additions and 0 deletions.
57 changes: 57 additions & 0 deletions lib/http-bridge/test/integration/js/mock-daedalus.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#!/usr/bin/env node

// This runs cardano-wallet-launcher in the same way that Daedalus would.
// It needs node, cardano-wallet, and cardano-wallet-launcher on the PATH to run.

const child_process = require("child_process");
const http = require('http');

function main() {
// const proc = child_process.spawn("cardano-wallet", ["server"], {
const proc = child_process.spawn("cardano-wallet-launcher", [], {
stdio: ["ignore", "inherit", "inherit", "ipc"]
});

proc.on("close", function(code, signal) {
console.log("JS: child_process stdio streams closed");
process.exit(1);
});

proc.on("disconnect", function() {
console.log("JS: child_process disconnected");
process.exit(2);
});

proc.on("error", function(err) {
console.log("JS: error child_process: " + err);
process.exit(3);
});

proc.on("exit", function(code, signal) {
console.log("JS: child_process exited with status " + code + " or signal " + signal);
process.exit(4);
});

proc.on("message", function(msg) {
console.log("JS: message received", msg);
if (msg.Started) {
proc.send("QueryPort");
} else if (msg.ReplyPort) {
http.get({
hostname: "localhost",
port: msg.ReplyPort,
path: "/v2/wallets",
agent: false
}, (res) => {
console.log("JS: response from wallet: " + res.statusCode);
res.resume();
res.on("end", () => {
console.log("JS: request response from wallet finished, exiting.");
process.exit(0);
});
});
}
});
}

main();

0 comments on commit 5cdcab3

Please sign in to comment.