-
Notifications
You must be signed in to change notification settings - Fork 213
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tests: Add nodejs child_process spawner
- Loading branch information
Showing
1 changed file
with
57 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); |