From d72f5d573a59fc20ba465dffd1698984c7dde024 Mon Sep 17 00:00:00 2001 From: Shreyas Date: Mon, 18 Sep 2023 23:18:54 +0530 Subject: fix: `Deno.Command` - improve error message when `cwd` is not a directory (#20460) --- cli/tests/unit/command_test.ts | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) (limited to 'cli/tests/unit/command_test.ts') diff --git a/cli/tests/unit/command_test.ts b/cli/tests/unit/command_test.ts index ce3af08fb..5f56a0c22 100644 --- a/cli/tests/unit/command_test.ts +++ b/cli/tests/unit/command_test.ts @@ -424,6 +424,31 @@ Deno.test({ permissions: { run: true } }, function commandSyncNotFound() { ); }); +Deno.test({ permissions: { run: true, read: true } }, function cwdNotFound() { + assertThrows( + () => + new Deno.Command(Deno.execPath(), { + cwd: Deno.cwd() + "/non-existent-directory", + }).output(), + Deno.errors.NotFound, + "No such cwd", + ); +}); + +Deno.test( + { permissions: { run: true, read: true } }, + function cwdNotDirectory() { + assertThrows( + () => + new Deno.Command(Deno.execPath(), { + cwd: Deno.execPath(), + }).output(), + Deno.errors.NotFound, + "cwd is not a directory", + ); + }, +); + Deno.test( { permissions: { run: true, read: true } }, async function commandFailedWithCode() { @@ -892,12 +917,12 @@ Deno.test( assertThrows( () => new Deno.Command("doesntexist").outputSync(), Error, - "Failed to spawn: doesntexist", + "Failed to spawn 'doesntexist'", ); await assertRejects( async () => await new Deno.Command("doesntexist").output(), Error, - "Failed to spawn: doesntexist", + "Failed to spawn 'doesntexist'", ); }, ); -- cgit v1.2.3