-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplanner_test.go
More file actions
70 lines (57 loc) · 2.08 KB
/
Copy pathplanner_test.go
File metadata and controls
70 lines (57 loc) · 2.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package main
import (
"slices"
"testing"
)
func TestApplyServerFrameworkOverrides_TanstackStart(t *testing.T) {
dir := writePackageJSON(t, `{
"scripts": {"build": "vite build"},
"dependencies": {"@tanstack/react-start": "^1.0.0"}
}`)
opts := PlannerOptions{SourceDir: dir}
applyServerFrameworkOverrides(&opts)
if opts.StartCmd != "node .output/server/index.mjs" {
t.Errorf("startCmd = %q, want injected server command", opts.StartCmd)
}
// railpack turns plan-time envs into build secrets, so we must not inject
// RAILPACK_NO_SPA — the start command alone forces the server path.
if len(opts.Envs) != 0 {
t.Errorf("envs = %v, want none injected", opts.Envs)
}
}
func TestApplyServerFrameworkOverrides_ExplicitStartCmdWins(t *testing.T) {
dir := writePackageJSON(t, `{
"scripts": {"build": "vite build"},
"dependencies": {"@tanstack/react-start": "^1.0.0"}
}`)
opts := PlannerOptions{SourceDir: dir, StartCmd: "node custom.js"}
applyServerFrameworkOverrides(&opts)
if opts.StartCmd != "node custom.js" {
t.Errorf("startCmd = %q, want it left untouched", opts.StartCmd)
}
if slices.Contains(opts.Envs, "RAILPACK_NO_SPA=1") {
t.Errorf("did not expect RAILPACK_NO_SPA to be injected over an explicit start command")
}
}
func TestApplyServerFrameworkOverrides_SPAOptInWins(t *testing.T) {
dir := writePackageJSON(t, `{
"scripts": {"build": "vite build"},
"dependencies": {"@tanstack/react-start": "^1.0.0"}
}`)
opts := PlannerOptions{SourceDir: dir, Envs: []string{"RAILPACK_SPA_OUTPUT_DIR=dist"}}
applyServerFrameworkOverrides(&opts)
if opts.StartCmd != "" {
t.Errorf("startCmd = %q, want empty when user opted into an SPA build", opts.StartCmd)
}
}
func TestApplyServerFrameworkOverrides_PlainViteUntouched(t *testing.T) {
dir := writePackageJSON(t, `{
"scripts": {"build": "vite build"},
"dependencies": {"vite": "^6.0.0"}
}`)
opts := PlannerOptions{SourceDir: dir}
applyServerFrameworkOverrides(&opts)
if opts.StartCmd != "" || len(opts.Envs) != 0 {
t.Errorf("plain Vite SPA should be left untouched, got startCmd=%q envs=%v", opts.StartCmd, opts.Envs)
}
}