diff --git a/garden-service/src/tasks/test.ts b/garden-service/src/tasks/test.ts index f1e1fff98b..67a801c6ca 100644 --- a/garden-service/src/tasks/test.ts +++ b/garden-service/src/tasks/test.ts @@ -8,6 +8,9 @@ import * as Bluebird from "bluebird" import chalk from "chalk" +import { find } from "lodash" +import minimatch = require("minimatch") + import { Module } from "../types/module" import { TestConfig } from "../config/test" import { ModuleVersion } from "../vcs/vcs" @@ -20,8 +23,8 @@ import { LogEntry } from "../logger/log-entry" import { ConfigGraph } from "../config-graph" import { makeTestTaskName } from "./helpers" import { BuildTask } from "./build" -import minimatch = require("minimatch") -import { find } from "lodash" +import { TaskTask } from "./task" + class TestError extends Error { toString() { return this.message @@ -69,27 +72,38 @@ export class TestTask extends BaseTask { } const dg = this.graph - const services = (await dg.getDependencies("test", this.getName(), false)).service + const deps = await dg.getDependencies("test", this.getName(), false) - const deps: BaseTask[] = [new BuildTask({ + const buildTask = new BuildTask({ garden: this.garden, log: this.log, module: this.module, force: this.forceBuild, - })] + }) + + const taskTasks = await Bluebird.map(deps.task, (task) => { + return TaskTask.factory({ + task, + garden: this.garden, + log: this.log, + graph: this.graph, + force: this.force, + forceBuild: this.forceBuild, + }) + }) - for (const service of services) { - deps.push(new DeployTask({ + const serviceTasks = deps.service.map(service => + new DeployTask({ garden: this.garden, graph: this.graph, log: this.log, service, force: false, forceBuild: this.forceBuild, - })) - } + }), + ) - return Bluebird.all(deps) + return [buildTask, ...serviceTasks, ...taskTasks] } getName() { @@ -205,6 +219,9 @@ async function getTestDependencies(graph: ConfigGraph, testConfig: TestConfig) { export async function getTestVersion( garden: Garden, graph: ConfigGraph, module: Module, testConfig: TestConfig, ): Promise { - const moduleDeps = await graph.resolveDependencyModules(module.build.dependencies, testConfig.dependencies) + const moduleDeps = (await graph.resolveDependencyModules(module.build.dependencies, testConfig.dependencies)) + // Don't include the module itself in the dependencies here + .filter(m => m.name !== module.name) + return garden.resolveVersion(module.name, moduleDeps) } diff --git a/garden-service/test/unit/data/test-project-test-deps/module-a/garden.yml b/garden-service/test/unit/data/test-project-test-deps/module-a/garden.yml index 0d83ed26c4..bfacb8c5d4 100644 --- a/garden-service/test/unit/data/test-project-test-deps/module-a/garden.yml +++ b/garden-service/test/unit/data/test-project-test-deps/module-a/garden.yml @@ -4,8 +4,12 @@ module: services: - name: service-a command: [echo, OK] + tasks: + - name: task-a + command: [echo, OK] tests: - name: integ dependencies: - service-b + - task-a command: [echo, OK] diff --git a/garden-service/test/unit/src/tasks/test.ts b/garden-service/test/unit/src/tasks/test.ts index 87771b7b2d..4a185de329 100644 --- a/garden-service/test/unit/src/tasks/test.ts +++ b/garden-service/test/unit/src/tasks/test.ts @@ -20,8 +20,6 @@ describe("TestTask", () => { }) it("should correctly resolve version for tests with dependencies", async () => { - process.env.TEST_VARIABLE = "banana" - const resolveVersion = td.replace(garden, "resolveVersion") const versionA: ModuleVersion = { @@ -64,4 +62,25 @@ describe("TestTask", () => { expect(task.version).to.eql(versionA) }) + + describe("getDependencies", () => { + it("should include task dependencies", async () => { + const moduleA = await graph.getModule("module-a") + const testConfig = moduleA.testConfigs[0] + + const task = await TestTask.factory({ + garden, + log, + graph, + module: moduleA, + testConfig, + force: true, + forceBuild: false, + }) + + const deps = await task.getDependencies() + + expect(deps.map(d => d.getKey())).to.eql(["build.module-a", "deploy.service-b", "task.task-a"]) + }) + }) })