Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extract spawn logic into a wrapper and add tests #953

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

dennisameling
Copy link
Contributor

@dennisameling dennisameling commented Sep 10, 2024

Currently, it's a bit hard to ensure that the code in git.exe actually does what we expect it to do, especially considering that we're calling things like please.sh and assume that some executables are available on the PATH.

Let's ensure we add some tests for these code paths, which we can easily extend with more tests if needed.

src/git.ts Outdated Show resolved Hide resolved
// We don't want to _actually_ clone the repo, so we mock the function
jest.spyOn(git, 'clone').mockResolvedValue()

// The script removes the .tmp folder at the end, so let's create it
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we mock mkdirSync()/rmdirSync() instead and verify that they were called?

src/spawn.ts Outdated
* Simple wrapper around NodeJS's "child_process.spawn" function.
* Since we only use the exit code, we only expose that.
*/
export async function spawn(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we rename this to spawnAndWaitForExitCode()? I find it a bit confusing that spawn() shouldn't return immediately upon spawning the process without waiting for it to finish, as that would be the semantics I've come to expect of any function called spawn()...

src/spawn.ts Outdated
export async function spawn(
command: string,
args: readonly string[],
options: SpawnOptionsWithStdioTuple<StdioPipe, StdioNull, StdioNull>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have two callers that both pass in [undefined, 'inherit', 'inherit'] here. How about hard-coding it and dropping the options function parameter?

Copy link
Contributor Author

@dennisameling dennisameling Sep 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great suggestion, thanks! I couldn't drop options completely because the callers are still passing env objects, but I was able to change SpawnOptionsWithStdioTuple<StdioPipe, StdioNull, StdioNull> to simply SpawnOptions by hard-coding stdio 👍🏼

Currently, it's a bit hard to ensure that the code in git.exe actually does what we expect it to do, especially considering that we're calling things like please.sh and assume that some executables are available on the PATH.

Let's ensure we add some tests for these code paths, which we can easily extend with more tests if needed.

Signed-off-by: Dennis Ameling <[email protected]>
Signed-off-by: Dennis Ameling <[email protected]>
@dennisameling dennisameling force-pushed the spawn-logic-and-path-issue branch from c969170 to 9d4ed59 Compare September 12, 2024 12:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants