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

Simplify monorepo-workflow-operations #21

Merged
merged 7 commits into from
Aug 25, 2022
Merged

Conversation

mcmire
Copy link
Contributor

@mcmire mcmire commented Jul 22, 2022

The tests for monorepo-workflow-operations.ts are not as readable or
maintainable as I'd like them to be. This commit attempts to fix that.

  • While there isn't a whole lot we can do in terms of the scenarios
    we're testing because the function makes a lot of calls and the logic
    inside of it is somewhat complicated, we can at least move
    code that is responsible for parsing the TODAY environment variable,
    building a ReleasePlan object from the release spec, and applying the
    updates to the repos themselves out into separate files. This
    simplifies the test data and removes a few tests entirely.
  • We also simplify the structure of the tests so that we aren't using so
    many nested describe blocks. This ends up being very difficult to
    keep straight, so the flattened layout here makes it a little more
    palatable.
  • We also simplify the setup code for each test. Currently we are
    mocking all of the dependencies for followMonorepoWorkflow in one
    go, but we're doing so in a way that forces the reader to wade through
    a bunch of type definitions. That isn't really that helpful. The most
    complicated part of reading the tests for followMonorepoWorkflow
    isn't the dependencies — it's the logic. So we take all of the
    decision points we have to make in the implementation and represent
    those as options to our setup function in the tests so it's as clear
    as possible which exact scenario is being tested just by reading the
    test.
  • Finally while we're moving things around, we can also move the check
    we perform to ensure that the new version of a package is greater than
    its existing version so that it is earlier in the entire workflow,
    i.e. from building the release plan to the validating the release
    specification. This also reduces the number of tests we have to write.

@mcmire mcmire requested a review from a team as a code owner July 22, 2022 21:31
@mcmire mcmire force-pushed the simplify-monorepo-workflow-tests branch from f975b68 to a87fb54 Compare July 22, 2022 21:45
@mcmire mcmire self-assigned this Jul 25, 2022
@mcmire mcmire marked this pull request as draft July 29, 2022 17:16
@mcmire mcmire force-pushed the fix-written-manifests branch from e096a90 to e8ccf1a Compare August 17, 2022 16:44
Base automatically changed from fix-written-manifests to main August 22, 2022 19:21
@mcmire mcmire force-pushed the simplify-monorepo-workflow-tests branch 3 times, most recently from be53bb8 to 3db4897 Compare August 22, 2022 21:11
@mcmire mcmire changed the title Simplify monorepo-workflow-utils tests Simplify monorepo-workflow-operations Aug 22, 2022
if (versionSpecifier instanceof SemVer) {
const comparison = versionSpecifier.compare(currentVersion);

if (comparison === 0) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've moved these checks to when the release spec is validated, as it makes more sense there.

@@ -32,6 +36,11 @@ export async function determineInitialParameters(
project.rootPackage.validatedManifest.name.replace('/', '__'),
)
: path.resolve(cwd, inputs.tempDirectory);
const parsedTodayTimestamp =
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is moved from monorepo-workflow-operations, where it was done on the fly.

* @param args.today - The current date.
* @returns A promise for information about the new release.
*/
export async function planRelease({
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This whole file was moved from monorepo-workflow-operations.

const newVersion =
versionSpecifier instanceof SemVer
? versionSpecifier
: new SemVer(currentVersion.toString()).inc(versionSpecifier);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The checks that used to be here around the new version (formerly in monorepo-workflow-operations.ts) have been moved to validateReleaseSpecification in release-specification.ts.

Copy link
Member

Choose a reason for hiding this comment

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

Good idea, that makes much more sense

* @param releaseName - The name of the release, which will be used to name the
* commit and the branch.
*/
export async function captureChangesInReleaseBranch(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This got moved from workflow-operations.ts, as it really pertains to a repo.

* (optional) and the properties that will go into the object (optional).
* @returns The mock Package object.
*/
export function buildMockMonorepoRootPackage(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is now no longer used entirely.

@mcmire mcmire marked this pull request as ready for review August 22, 2022 21:19
The tests for `monorepo-workflow-operations.ts` are not as readable or
maintainable as I'd like them to be. This commit attempts to fix that.

* While there isn't a whole lot we can do in terms of the scenarios
  we're testing because the function makes a lot of calls and the logic
  inside of it is somewhat complicated, we can at least move
  code that is responsible for parsing the TODAY environment variable,
  building a ReleasePlan object from the release spec, and applying the
  updates to the repos themselves out into separate files. This
  simplifies the test data and removes a few tests entirely.
* We also simplify the structure of the tests so that we aren't using so
  many nested `describe` blocks. This ends up being very difficult to
  keep straight, so the flattened layout here makes it a little more
  palatable.
* We also simplify the setup code for each test. Currently we are
  mocking all of the dependencies for `followMonorepoWorkflow` in one
  go, but we're doing so in a way that forces the reader to wade through
  a bunch of type definitions. That isn't really that helpful. The most
  complicated part of reading the tests for `followMonorepoWorkflow`
  isn't the dependencies — it's the logic. So we take all of the
  decision points we have to make in the implementation and represent
  those as options to our setup function in the tests so it's as clear
  as possible which exact scenario is being tested just by reading the
  test.
* Finally while we're moving things around, we can also move the check
  we perform to ensure that the new version of a package is greater than
  its existing version so that it is earlier in the entire workflow,
  i.e. from building the release plan to the validating the release
  specification. This also reduces the number of tests we have to write.
@mcmire mcmire force-pushed the simplify-monorepo-workflow-tests branch from 3db4897 to c30ce5c Compare August 22, 2022 21:19
Copy link
Member

@Gudahtt Gudahtt left a comment

Choose a reason for hiding this comment

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

These improvements look good! I see why you removed the nested describe blocks.

I had a few questions about the tests but aside from that I've finished reviewing it all.

Copy link
Member

@Gudahtt Gudahtt left a comment

Choose a reason for hiding this comment

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

LGTM!

@mcmire mcmire merged commit 5b63b9e into main Aug 25, 2022
@mcmire mcmire deleted the simplify-monorepo-workflow-tests branch August 25, 2022 21:42
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