Skip to content

Commit

Permalink
fix: garden can again be run from project subdirs
Browse files Browse the repository at this point in the history
Fixes a regression that resulted in Garden commands failing to find the
project-level config if run from a subdirectory of project root.

Also added a unit test to prevent this regression from being repeated.
  • Loading branch information
thsig authored and edvald committed Jul 9, 2019
1 parent 146cd1f commit 560604f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
4 changes: 2 additions & 2 deletions garden-service/src/config/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,9 +178,9 @@ export async function findProjectConfig(path: string, allowInvalid = false): Pro
} catch (err) {
if (!allowInvalid) {
throw err
} else {
path = resolve(path, "..")
}
} finally {
path = resolve(path, "..")
}
}

Expand Down
15 changes: 14 additions & 1 deletion garden-service/test/unit/src/config/base.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { expect } from "chai"
import { loadConfig } from "../../../../src/config/base"
import { loadConfig, findProjectConfig } from "../../../../src/config/base"
import { resolve } from "path"
import { dataDir, expectError, getDataDir } from "../../../helpers"

Expand Down Expand Up @@ -313,3 +313,16 @@ describe("loadConfig", () => {
})

})

describe("findProjectConfig", async () => {
it("should find the project config when path is projectRoot", async () => {
const project = await findProjectConfig(projectPathA)
expect(project && project.path).to.eq(projectPathA)
})

it("should find the project config when path is a subdir of projectRoot", async () => {
// modulePathA is a subdir of projectPathA
const project = await findProjectConfig(modulePathA)
expect(project && project.path).to.eq(projectPathA)
})
})

0 comments on commit 560604f

Please sign in to comment.