|
7 | 7 | "io/ioutil" |
8 | 8 | "os" |
9 | 9 | "path/filepath" |
| 10 | + "strings" |
10 | 11 | "testing" |
11 | 12 |
|
12 | 13 | "github.com/paketo-buildpacks/packit" |
@@ -99,6 +100,53 @@ func testBuild(t *testing.T, context spec.G, it spec.S) { |
99 | 100 | Expect(pathParser.GetCall.Receives.Path).To(Equal(workingDir)) |
100 | 101 | }) |
101 | 102 |
|
| 103 | + context("when BP_LIVE_RELOAD_ENABLED=true in the build environment", func() { |
| 104 | + it.Before(func() { |
| 105 | + os.Setenv("BP_LIVE_RELOAD_ENABLED", "true") |
| 106 | + }) |
| 107 | + |
| 108 | + it.After(func() { |
| 109 | + os.Unsetenv("BP_LIVE_RELOAD_ENABLED") |
| 110 | + }) |
| 111 | + |
| 112 | + it("adds a reloadable start command that ignores package manager files and makes it the default", func() { |
| 113 | + result, err := build(packit.BuildContext{ |
| 114 | + WorkingDir: workingDir, |
| 115 | + CNBPath: cnbDir, |
| 116 | + Stack: "some-stack", |
| 117 | + BuildpackInfo: packit.BuildpackInfo{ |
| 118 | + Name: "Some Buildpack", |
| 119 | + Version: "some-version", |
| 120 | + }, |
| 121 | + Plan: packit.BuildpackPlan{ |
| 122 | + Entries: []packit.BuildpackPlanEntry{}, |
| 123 | + }, |
| 124 | + Layers: packit.Layers{Path: layersDir}, |
| 125 | + }) |
| 126 | + Expect(err).NotTo(HaveOccurred()) |
| 127 | + |
| 128 | + Expect(result.Launch.Processes).To(Equal([]packit.Process{ |
| 129 | + { |
| 130 | + Type: "web", |
| 131 | + Command: strings.Join([]string{ |
| 132 | + "watchexec", |
| 133 | + "--restart", |
| 134 | + fmt.Sprintf("--watch %s/some-project-dir", workingDir), |
| 135 | + fmt.Sprintf("--ignore %s/some-project-dir/package.json", workingDir), |
| 136 | + fmt.Sprintf("--ignore %s/some-project-dir/yarn.lock", workingDir), |
| 137 | + fmt.Sprintf("--ignore %s/some-project-dir/node_modules", workingDir), |
| 138 | + `"cd some-project-dir && some-prestart-command && some-start-command && some-poststart-command"`, |
| 139 | + }, " "), |
| 140 | + }, |
| 141 | + { |
| 142 | + Type: "no-reload", |
| 143 | + Command: "cd some-project-dir && some-prestart-command && some-start-command && some-poststart-command", |
| 144 | + }, |
| 145 | + })) |
| 146 | + Expect(pathParser.GetCall.Receives.Path).To(Equal(workingDir)) |
| 147 | + }) |
| 148 | + }) |
| 149 | + |
102 | 150 | context("when the package.json does not include a prestart command", func() { |
103 | 151 | it.Before(func() { |
104 | 152 | err := ioutil.WriteFile(filepath.Join(workingDir, "some-project-dir", "package.json"), []byte(`{ |
@@ -343,5 +391,32 @@ func testBuild(t *testing.T, context spec.G, it spec.S) { |
343 | 391 | Expect(err).To(MatchError("path-parser-error")) |
344 | 392 | }) |
345 | 393 | }) |
| 394 | + |
| 395 | + context("when BP_LIVE_RELOAD_ENABLED is set to an invalid value", func() { |
| 396 | + it.Before(func() { |
| 397 | + os.Setenv("BP_LIVE_RELOAD_ENABLED", "not-a-bool") |
| 398 | + }) |
| 399 | + |
| 400 | + it.After(func() { |
| 401 | + os.Unsetenv("BP_LIVE_RELOAD_ENABLED") |
| 402 | + }) |
| 403 | + |
| 404 | + it("returns an error", func() { |
| 405 | + _, err := build(packit.BuildContext{ |
| 406 | + WorkingDir: workingDir, |
| 407 | + CNBPath: cnbDir, |
| 408 | + Stack: "some-stack", |
| 409 | + BuildpackInfo: packit.BuildpackInfo{ |
| 410 | + Name: "Some Buildpack", |
| 411 | + Version: "some-version", |
| 412 | + }, |
| 413 | + Plan: packit.BuildpackPlan{ |
| 414 | + Entries: []packit.BuildpackPlanEntry{}, |
| 415 | + }, |
| 416 | + Layers: packit.Layers{Path: layersDir}, |
| 417 | + }) |
| 418 | + Expect(err).To(MatchError(ContainSubstring("failed to parse BP_LIVE_RELOAD_ENABLED value not-a-bool"))) |
| 419 | + }) |
| 420 | + }) |
346 | 421 | }) |
347 | 422 | } |
0 commit comments