| 1 | package main |
| 2 | |
| 3 | import ( |
| 4 | "os" |
| 5 | "path/filepath" |
| 6 | "slices" |
| 7 | "testing" |
| 8 | ) |
| 9 | |
| 10 | // wailsjs is gitignored and regenerated by a desktop build, so its size is |
| 11 | // neither anyone's debt nor stable across machines. Measuring it once reported |
| 12 | // 4812 lines of file-size debt and pushed the repo total past its ceiling, |
| 13 | // which made every unrelated run look dirty. |
| 14 | func TestGeneratedBindingsAreNotCollected(t *testing.T) { |
| 15 | root := t.TempDir() |
| 16 | write := func(rel, body string) { |
| 17 | t.Helper() |
| 18 | path := filepath.Join(root, filepath.FromSlash(rel)) |
| 19 | if err := os.MkdirAll(filepath.Dir(path), 0o755); err != nil { |
| 20 | t.Fatal(err) |
| 21 | } |
| 22 | if err := os.WriteFile(path, []byte(body), 0o644); err != nil { |
| 23 | t.Fatal(err) |
| 24 | } |
| 25 | } |
| 26 | write("desktop/frontend/wailsjs/go/models.ts", "export class X {}\n") |
| 27 | write("desktop/frontend/src/app.ts", "export const x = 1\n") |
| 28 | write("internal/agent/agent.go", "package agent\n") |
| 29 | |
| 30 | got, err := collect(root) |
| 31 | if err != nil { |
| 32 | t.Fatalf("collect: %v", err) |
| 33 | } |
| 34 | for _, rel := range got { |
| 35 | if filepath.ToSlash(rel) == "desktop/frontend/wailsjs/go/models.ts" { |
| 36 | t.Fatalf("generated Wails bindings were collected: %v", got) |
| 37 | } |
| 38 | } |
| 39 | for _, want := range []string{"desktop/frontend/src/app.ts", "internal/agent/agent.go"} { |
| 40 | if !slices.ContainsFunc(got, func(rel string) bool { return filepath.ToSlash(rel) == want }) { |
| 41 | t.Errorf("%s was skipped; only generated output should be", want) |
| 42 | } |
| 43 | } |
| 44 | } |
| 45 |