take_promise
Async IO capture for Gleam tests on JavaScript.
Like take, but accepts callbacks that return Promise(a) and
awaits them before returning captured output.
import take_promise
import gleam/javascript/promise
pub fn async_greeting_test() {
use #(result, output) <- take_promise.with_stdout(fn() {
io.println("Hello!")
promise.resolve(42)
})
assert 42 == result
assert "Hello!\n" == output
}
Values
pub fn capture_stderr(
f: fn() -> promise.Promise(a),
) -> promise.Promise(String)
Runs f, awaits the returned promise, and returns captured stderr.
pub fn capture_stdio(
f: fn() -> promise.Promise(a),
) -> promise.Promise(#(String, String))
Runs f, awaits the returned promise, and returns both captured streams.
pub fn capture_stdout(
f: fn() -> promise.Promise(a),
) -> promise.Promise(String)
Runs f, awaits the returned promise, and returns captured stdout.
pub fn with_stderr(
f: fn() -> promise.Promise(a),
) -> promise.Promise(#(a, String))
Runs f, awaits the returned promise, and captures stderr.
Returns a promise of the result and captured output.
pub fn with_stdio(
f: fn() -> promise.Promise(a),
) -> promise.Promise(#(a, String, String))
Runs f, awaits the returned promise, and captures both stdout and stderr.
pub fn with_stdout(
f: fn() -> promise.Promise(a),
) -> promise.Promise(#(a, String))
Runs f, awaits the returned promise, and captures stdout.
Returns a promise of the result and captured output.