Skip to content

Commit

Permalink
fix: Move tests around
Browse files Browse the repository at this point in the history
This commit will be squashed out, pending approval.

Moved the tests this branch introduced to the scanModules section.
  • Loading branch information
thsig committed May 17, 2018
1 parent 9c83c1b commit 22c5a66
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 38 deletions.
41 changes: 40 additions & 1 deletion test/src/garden.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { expect } from "chai"
import { join } from "path"
import { Garden } from "../../src/garden"
import { expect } from "chai"
import { detectCycles } from "../../src/util/detectCycles"
import {
dataDir,
expectError,
Expand Down Expand Up @@ -227,6 +228,44 @@ describe("Garden", () => {
const modules = await garden.getModules(undefined, true)
expect(Object.keys(modules)).to.eql(["module-a", "module-b", "module-c"])
})

describe("detectCircularDependencies", () => {
it("should throw an exception when circular dependencies are present", async () => {
const circularProjectRoot = join(__dirname, "..", "data", "test-project-circular-deps")
const garden = await makeTestGarden(circularProjectRoot)
await expectError(
async () => await garden.scanModules(),
"configuration")
})

it("should not throw an exception when no circular dependencies are present", async () => {
const nonCircularProjectRoot = join(__dirname, "..", "data", "test-project-b")
const garden = await makeTestGarden(nonCircularProjectRoot)
expect(async () => { await garden.scanModules() }).to.not.throw()
})
})

describe("detectCycles", () => {

it("should detect self-to-self cycles", () => {
const cycles = detectCycles({
a: {a: {distance: 1, next: "a"}},
}, ["a"])

expect(cycles).to.deep.eq([["a"]])
})

it("should preserve dependency order when returning cycles", () => {
const cycles = detectCycles({
foo: {bar: {distance: 1, next: "bar"}},
bar: {baz: {distance: 1, next: "baz"}},
baz: {foo: {distance: 1, next: "foo"}},
}, ["foo", "bar", "baz"])

expect(cycles).to.deep.eq([["foo", "bar", "baz"]])
})

})
})

describe("addModule", () => {
Expand Down
37 changes: 0 additions & 37 deletions test/src/util.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { expect } from "chai"
import { join } from "path"
import { expectError, makeTestGarden } from "../helpers"
import { scanDirectory } from "../../src/util"
import { detectCycles } from "../../src/util/detectCycles"

describe("util", () => {
describe("scanDirectory", () => {
Expand Down Expand Up @@ -34,41 +32,6 @@ describe("util", () => {

expect(count).to.eq(3)
})

it("should throw an exception when circular dependencies are present", async () => {
const circularProjectRoot = join(__dirname, "..", "data", "test-project-circular-deps")
const garden = await makeTestGarden(circularProjectRoot)
await expectError(
async () => await garden.scanModules(),
"configuration")
})

it("should not throw an exception when no circular dependencies are present", async () => {
const nonCircularProjectRoot = join(__dirname, "..", "data", "test-project-b")
const garden = await makeTestGarden(nonCircularProjectRoot)
expect(async () => { await garden.scanModules() }).to.not.throw()
})
})

describe("detectCycles", () => {

it("should detect self-to-self cycles", () => {
const cycles = detectCycles({
a: {a: {distance: 1, next: "a"}},
}, ["a"])

expect(cycles).to.deep.eq([["a"]])
})

it("should preserve dependency order when returning cycles", () => {
const cycles = detectCycles({
foo: {bar: {distance: 1, next: "bar"}},
bar: {baz: {distance: 1, next: "baz"}},
baz: {foo: {distance: 1, next: "foo"}},
}, ["foo", "bar", "baz"])

expect(cycles).to.deep.eq([["foo", "bar", "baz"]])
})

})
})

0 comments on commit 22c5a66

Please sign in to comment.