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

feat: Detect circular dependencies. #95

Merged
merged 1 commit into from
May 22, 2018
Merged

Conversation

thsig
Copy link
Collaborator

@thsig thsig commented May 16, 2018

Added a check for circular build or service dependencies to the
scanModules method of the Garden class.

test/src/algo.ts Outdated
const circularProjectRoot = join(__dirname, "..", "data", "test-project-circular-deps")
const nonCircularProjectRoot = join(__dirname, "..", "data", "test-project-b")

describe("Algo", () => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Algo is not a good name for this :) I dunno, maybe we should rename util.ts to util/index.ts and add another file under util/ with a more descriptive name.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Haha. Agreed. I'll do that, and rename this file to util/detectCycles.ts.

test/src/algo.ts Outdated
it("should throw an exception when circular dependencies are present", async () => {
const garden = await makeTestGarden(circularProjectRoot)
await expectError(
async () => await garden.scanModules(),
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think it's better to put these tests under the Garden.scanModules tests, and in turn write a couple of basic unit tests for the detectCycles function.

test/helpers.ts Outdated
@@ -201,6 +201,15 @@ export async function expectError(fn: Function, typeOrCallback: string | ((err:
}
}

export async function expectNoError(fn: Function) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Isn't this redundant? Also, can't see it used anywhere.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It is indeed, forgot to delete this one.

@edvald
Copy link
Collaborator

edvald commented May 16, 2018

A handful of small comments, otherwise looks good!

@thsig
Copy link
Collaborator Author

thsig commented May 17, 2018

Looks like I accidentally avoided the commit formatter for the latter commit (since I wrote it while squashing). Should I replace the commit or just leave it?

@edvald
Copy link
Collaborator

edvald commented May 17, 2018

I'd let it slide, but it also has a typo in it and it tickles my OCD :) so yeah, best replace it

@edvald
Copy link
Collaborator

edvald commented May 17, 2018

Or, actually, you can just squash the whole thing. No reason to have a commit and then a fix for that commit in succession (I personally use git rebase -i master and use fixup to merge fixes into related commits)

@thsig thsig force-pushed the detect-circular-dependencies branch from d98fda5 to 9c83c1b Compare May 17, 2018 11:20
@thsig
Copy link
Collaborator Author

thsig commented May 17, 2018

'Tis been squashed.

test/src/util.ts Outdated
const circularProjectRoot = join(__dirname, "..", "data", "test-project-circular-deps")
const garden = await makeTestGarden(circularProjectRoot)
await expectError(
async () => await garden.scanModules(),
Copy link
Collaborator

Choose a reason for hiding this comment

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

This test seems to be in the wrong place - it's not directly testing this function, nor does that function have any knowledge of Module specs.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Good point - these two probably belong under describe("util") -> describe("detectCircularDependencies") in this file. Or did you have another placement in mind?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Since this actually tests the scanModules method on Garden, it should be with those tests in tests/src/garden.ts (along with the other scanModules tests)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Fixed here: 0eadd2c

@thsig thsig force-pushed the detect-circular-dependencies branch 3 times, most recently from 22c5a66 to 0eadd2c Compare May 17, 2018 14:52
Added a check for circular build or service dependencies to the
scanModules method of the Garden class.
@thsig thsig force-pushed the detect-circular-dependencies branch from 0eadd2c to 4a35276 Compare May 21, 2018 20:38
@edvald edvald merged commit 307e21b into master May 22, 2018
@edvald edvald deleted the detect-circular-dependencies branch May 22, 2018 11:34
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