Skip to content

Commit

Permalink
test: mock out git (#972)
Browse files Browse the repository at this point in the history
## 🧰 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???
  • Loading branch information
kellyjosephprice authored Feb 15, 2024
1 parent 58bcc48 commit 9faab30
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions src/lib/createGHA/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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.
Expand Down

0 comments on commit 9faab30

Please sign in to comment.