ByteArrayOutputStream out = new ByteArrayOutputStream();
NodeEnvironment env = new NodeEnvironment();
env.setSandbox(new Sandbox().setStdout(out));
String msg = "Hello, World!";
NodeScript ns =
env.createScript("consolelogtest.js", new File("./target/test-classes/tests/consolelogtest.js"),
new String[] { "stdout", msg });
try {
ScriptFuture f = ns.execute();
ScriptStatus result = f.get(SCRIPT_TIMEOUT_SECS, TimeUnit.SECONDS);
assertEquals(0, result.getExitCode());
String stream = new String(out.toByteArray(), UTF8);
assertEquals(msg + '\n', stream);
} finally {
ns.close();
env.close();
}
}