Skip to content

Commit

Permalink
fix(core): task dependencies were not automatically run ahead of tests
Browse files Browse the repository at this point in the history
  • Loading branch information
edvald committed Jul 23, 2019
1 parent c43490c commit 46fb474
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 13 deletions.
39 changes: 28 additions & 11 deletions garden-service/src/tasks/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -205,6 +219,9 @@ async function getTestDependencies(graph: ConfigGraph, testConfig: TestConfig) {
export async function getTestVersion(
garden: Garden, graph: ConfigGraph, module: Module, testConfig: TestConfig,
): Promise<ModuleVersion> {
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)
}
Original file line number Diff line number Diff line change
Expand Up @@ -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]
23 changes: 21 additions & 2 deletions garden-service/test/unit/src/tasks/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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"])
})
})
})

0 comments on commit 46fb474

Please sign in to comment.