Skip to content

Commit

Permalink
fix: regression - .bytes() signature should support no argument (#265)
Browse files Browse the repository at this point in the history
  • Loading branch information
dsherret authored Apr 19, 2024
1 parent 81f2ca1 commit f3d128a
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 3 deletions.
16 changes: 16 additions & 0 deletions mod.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,22 @@ Deno.test("should error setting stdout after getting combined output", () => {
}
});

Deno.test("should get output as bytes", async () => {
{
const output = await $`echo 5 && deno eval 'console.error(1);'`.bytes();
assertEquals(new TextDecoder().decode(output), "5\n");
}
{
const output = await $`echo 5 && deno eval 'console.error(1);'`.bytes("combined");
assertEquals(new TextDecoder().decode(output), "5\n1\n");
}
{
const output = await $`echo 5 && deno eval 'console.error(1);'`.env("NOCOLOR", "1")
.bytes("stderr");
assertEquals(new TextDecoder().decode(output), "1\n");
}
});

Deno.test("should throw when exit code is non-zero", async () => {
await assertRejects(
async () => {
Expand Down
1 change: 0 additions & 1 deletion mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ export { FsFileWrapper, Path } from "./src/path.ts";
/** @deprecated Import `Path` instead. */
const PathRef = Path;
// bug in deno: https://github.com/denoland/deno_lint/pull/1262
// deno-lint-ignore verbatim-module-syntax
export { PathRef };
export {
CommandBuilder,
Expand Down
2 changes: 1 addition & 1 deletion src/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,7 @@ export class CommandBuilder implements PromiseLike<CommandResult> {
* const data = (await $`command`.quiet("stdout")).stdoutBytes;
* ```
*/
async bytes(kind: StreamKind): Promise<Uint8Array> {
async bytes(kind: StreamKind = "stdout"): Promise<Uint8Array> {
const command = kind === "combined" ? this.quiet(kind).captureCombined() : this.quiet(kind);
return (await command)[`${kind}Bytes`];
}
Expand Down
1 change: 0 additions & 1 deletion src/console/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,4 @@ const logger = {
logAboveStaticText,
};

// deno-lint-ignore verbatim-module-syntax -- Bug https://github.com/denoland/deno_lint/pull/1262
export { logger };

0 comments on commit f3d128a

Please sign in to comment.