Skip to content

Commit

Permalink
feat(runtime): add .cwd() method (#95)
Browse files Browse the repository at this point in the history
  • Loading branch information
c4spar authored Jul 17, 2022
1 parent ca64927 commit 4b88438
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
7 changes: 7 additions & 0 deletions src/runtime/process.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export class Process extends Reader<ProcessOutput> {
#shouldRetry?: RetryCallback;
#stdoutReader: Reader<string>;
#stderrReader: Reader<string>;
#cwd?: string;

constructor(cmd: string, { errorContext }: ProcessOptions = {}) {
super({
Expand Down Expand Up @@ -71,6 +72,7 @@ export class Process extends Reader<ProcessOutput> {
stdin: this.#stdin,
stdout: this.#stdout,
stderr: this.#stderr,
cwd: this.#cwd,
});

if (this.#timeout) {
Expand Down Expand Up @@ -153,6 +155,11 @@ export class Process extends Reader<ProcessOutput> {
return this;
}

cwd(path: string): this {
this.#cwd = path;
return this;
}

env(
name: string,
value: string | number | boolean | Record<string, unknown>,
Expand Down
12 changes: 10 additions & 2 deletions test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,15 +199,23 @@ Deno.test({
});

Deno.test({
name: "$ should set env var",
name: "$ should set cwd for current process",
async fn() {
const stdout = await $`pwd`.cwd("examples").stdout;
assertEquals(stdout, `${Deno.cwd()}/examples\n`);
},
});

Deno.test({
name: "$ should set env var current process",
async fn() {
const stdout = await $`echo $FOO_BAR`.env("FOO_BAR", "baz").stdout;
assertEquals(stdout, "baz\n");
},
});

Deno.test({
name: "$ should set json as env var",
name: "$ should set json as env var current process",
async fn() {
const stdout = await $`echo $FOO_BAR`.env("FOO_BAR", { foo: "bar", baz: 1 })
.stdout;
Expand Down

0 comments on commit 4b88438

Please sign in to comment.