From a91ab70c7b304c328f382070e1cbb3d28544065e Mon Sep 17 00:00:00 2001 From: Markus Tacker Date: Thu, 4 Apr 2024 00:25:08 +0200 Subject: [PATCH] feat: allow to set current working directory --- src/run.spec.ts | 8 ++++++++ src/run.ts | 4 +++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/run.spec.ts b/src/run.spec.ts index ca26d6e..4303ba2 100644 --- a/src/run.spec.ts +++ b/src/run.spec.ts @@ -76,4 +76,12 @@ void describe('run()', () => { }) assert.equal(log.mock.calls[0]?.arguments[0].toString(), 'test') }) + + void it('can be launched in a different working directory', async () => { + await run({ + command: 'npx', + args: ['tsx', 'stderr.ts'], + cwd: 'src/test', + }) + }) }) diff --git a/src/run.ts b/src/run.ts index d5efdb0..1a470e6 100644 --- a/src/run.ts +++ b/src/run.ts @@ -6,10 +6,12 @@ const run = async ({ args, input, log, + cwd, }: { command: string args?: string[] input?: string + cwd?: string log?: { debug?: (...message: any[]) => void stdout?: (...message: any[]) => void @@ -19,7 +21,7 @@ const run = async ({ }): Promise => new Promise((resolve, reject) => { log?.debug?.(`${command} ${args?.join(' ')}`) - const p = spawn(command, args) + const p = spawn(command, args, { cwd }) const result = [] as string[] const errors = [] as string[] if (input !== undefined) {