From 9faab30cbe69ef039f29e692ba65af83fe834aab Mon Sep 17 00:00:00 2001 From: Kelly Joseph Price Date: Wed, 14 Feb 2024 16:38:20 -0800 Subject: [PATCH] test: mock out git (#972) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## 🧰 Changes Speeds up a few tests by mocking out `git` commands. I was poking around to investigate a bug (https://linear.app/readme-io/issue/RM-8336/childdocs-are-createdsyncd-before-parentdocs-in-rdme-cli) and noticed some test timeouts when running them locally. It looks like for a number of tests, we were making actual requests like `git remote`. I don't understand why those can be so slow, they're nearly instant when running them in a shell? **my machine before** ![image](https://github.com/readmeio/rdme/assets/451488/a8390e49-0125-4183-b69b-d36dc4081332) **my machine after** ![image](https://github.com/readmeio/rdme/assets/451488/9db59ee3-46e9-48b9-8589-90a128df8211) With all the parallelization, and the fact that the slowest part seems to be the e2e tests, the actual speed up on CI is negligible. But for running individual test files, they go from 5+ seconds to <1 second. ## 🧬 QA & Testing Tests should pass??? --- src/lib/createGHA/index.ts | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/lib/createGHA/index.ts b/src/lib/createGHA/index.ts index f89e57cb5..1fcfe1218 100644 --- a/src/lib/createGHA/index.ts +++ b/src/lib/createGHA/index.ts @@ -156,8 +156,8 @@ export default async function createGHA( // if in a CI environment, // don't even bother running the git commands - if (!opts.github && (isCI() || isNpmScript())) { - debug('not running GHA onboarding workflow in CI and/or npm script, exiting'); + if (!opts.github && (isCI() || isNpmScript() || (isTest() && !process.env.TEST_RDME_CREATEGHA))) { + debug('not running GHA onboarding workflow in CI, npm script, or default test env, exiting 👋'); return msg; } @@ -176,9 +176,7 @@ export default async function createGHA( // user has previously declined to set up GHA for current repo and `rdme` package version configVal === majorPkgVersion || // is a repo, but does not contain a GitHub remote - (isRepo && !containsGitHubRemote) || - // not testing this function - (isTest() && !process.env.TEST_RDME_CREATEGHA) + (isRepo && !containsGitHubRemote) ) { debug('not running GHA onboarding workflow, exiting'); // We return the original command message and pretend this command flow never happened.