From 0eadd2cd1f97b389229c9f05668c5103cf4eb357 Mon Sep 17 00:00:00 2001 From: Thorarinn Sigurdsson Date: Thu, 17 May 2018 14:25:16 +0200 Subject: [PATCH] fix: Move tests around This commit will be squashed out, pending approval. Moved the tests this branch introduced to the scanModules section. --- test/src/garden.ts | 39 ++++++++++++++++++++++++++++++++++++++- test/src/util.ts | 37 ------------------------------------- 2 files changed, 38 insertions(+), 38 deletions(-) diff --git a/test/src/garden.ts b/test/src/garden.ts index 5249d3f3c49..fd4a84524ec 100644 --- a/test/src/garden.ts +++ b/test/src/garden.ts @@ -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, @@ -227,6 +228,42 @@ 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", () => { diff --git a/test/src/util.ts b/test/src/util.ts index b6d58103ca9..7f356b2564a 100644 --- a/test/src/util.ts +++ b/test/src/util.ts @@ -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", () => { @@ -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"]]) - }) - - }) })