diff options
Diffstat (limited to 'cli/tests/unit/test_util.ts')
-rw-r--r-- | cli/tests/unit/test_util.ts | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/cli/tests/unit/test_util.ts b/cli/tests/unit/test_util.ts index 3591864d4..b18ad9550 100644 --- a/cli/tests/unit/test_util.ts +++ b/cli/tests/unit/test_util.ts @@ -27,3 +27,21 @@ export function pathToAbsoluteFileUrl(path: string): URL { return new URL(`file://${Deno.build.os === "windows" ? "/" : ""}${path}`); } + +const decoder = new TextDecoder(); + +export async function execCode(code: string) { + const p = Deno.run({ + cmd: [ + Deno.execPath(), + "eval", + "--unstable", + "--no-check", + code, + ], + stdout: "piped", + }); + const [status, output] = await Promise.all([p.status(), p.output()]); + p.close(); + return [status.code, decoder.decode(output)]; +} |