• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

supabase / cli / 15585238734

11 Jun 2025 12:45PM UTC coverage: 55.877%. First build
15585238734

Pull #3675

github

web-flow
Merge e33c2bc18 into b3bee3dd5
Pull Request #3675: feat: hot reload eszip bundle when function source changes

414 of 536 new or added lines in 8 files covered. (77.24%)

6280 of 11239 relevant lines covered (55.88%)

7.18 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

95.29
/internal/functions/serve/test_helpers.go
1
package serve
2

3
import (
4
        "context"
5
        "path/filepath"
6
        "testing"
7

8
        "github.com/fsnotify/fsnotify"
9
        "github.com/h2non/gock"
10
        "github.com/spf13/afero"
11
        "github.com/stretchr/testify/require"
12
        "github.com/supabase/cli/internal/utils"
13
)
14

15
type TestSetup struct {
16
        T         *testing.T
17
        Fsys      afero.Fs
18
        Context   context.Context
19
        Cancel    context.CancelFunc
20
        ProjectId string
21
        RootPath  string
22
}
23

24
func NewTestSetup(t *testing.T) *TestSetup {
19✔
25
        fsys := afero.NewMemMapFs()
19✔
26
        ctx, cancel := context.WithCancel(context.Background())
19✔
27

19✔
28
        setup := &TestSetup{
19✔
29
                T:         t,
19✔
30
                Fsys:      fsys,
19✔
31
                Context:   ctx,
19✔
32
                Cancel:    cancel,
19✔
33
                ProjectId: "test",
19✔
34
                RootPath:  "/project",
19✔
35
        }
19✔
36

19✔
37
        // Initialize basic config
19✔
38
        require.NoError(t, utils.InitConfig(utils.InitParams{ProjectId: setup.ProjectId}, fsys))
19✔
39

19✔
40
        return setup
19✔
41
}
19✔
42

43
func (s *TestSetup) Cleanup() {
19✔
44
        s.Cancel()
19✔
45
        gock.OffAll()
19✔
46
}
19✔
47

48
// SetupFunction creates a test function with given name and content
49
func (s *TestSetup) SetupFunction(name, content string) {
3✔
50
        funcDir := filepath.Join(utils.FunctionsDir, name)
3✔
51
        require.NoError(s.T, s.Fsys.MkdirAll(funcDir, 0755))
3✔
52
        require.NoError(s.T, afero.WriteFile(s.Fsys, filepath.Join(funcDir, "index.ts"), []byte(content), 0644))
3✔
53
}
3✔
54

55
// SetupEnvFile creates an environment file with given content
56
func (s *TestSetup) SetupEnvFile(path, content string) {
2✔
57
        if path == "" {
3✔
58
                path = utils.FallbackEnvFilePath
1✔
59
        }
1✔
60
        require.NoError(s.T, afero.WriteFile(s.Fsys, path, []byte(content), 0644))
2✔
61
}
62

63
// SetupImportMap creates an import map file with given content
64
func (s *TestSetup) SetupImportMap(path, content string) {
1✔
65
        if path == "" {
1✔
NEW
66
                path = utils.FallbackImportMapPath
×
NEW
67
        }
×
68
        require.NoError(s.T, afero.WriteFile(s.Fsys, path, []byte(content), 0644))
1✔
69
}
70

71
// CreateFileWatcher creates a test file watcher with a temporary directory structure
72
func (s *TestSetup) CreateFileWatcher(watchPath string) (*fsnotify.Watcher, error) {
1✔
73
        // Create the watch directory in virtual filesystem only
1✔
74
        require.NoError(s.T, s.Fsys.MkdirAll(watchPath, 0755))
1✔
75

1✔
76
        // For tests that actually need a watcher, create one but don't try to watch virtual filesystem
1✔
77
        watcher, err := fsnotify.NewWatcher()
1✔
78
        if err != nil {
1✔
NEW
79
                return nil, err
×
NEW
80
        }
×
81

82
        return watcher, nil
1✔
83
}
84

85
// SetupConfigWithFunctions creates a supabase config.toml with function configurations
86
func (s *TestSetup) SetupConfigWithFunctions() {
1✔
87
        configContent := `[functions.hello]
1✔
88
enabled = true
1✔
89
verify_jwt = false
1✔
90

1✔
91
[functions.protected]
1✔
92
enabled = true
1✔
93
verify_jwt = true
1✔
94

1✔
95
[functions.goodbye]
1✔
96
enabled = false
1✔
97
verify_jwt = false`
1✔
98

1✔
99
        require.NoError(s.T, afero.WriteFile(s.Fsys, "supabase/config.toml", []byte(configContent), 0644))
1✔
100
}
1✔
101

102
// FileEventTestCase represents a test case for file event handling
103
type FileEventTestCase struct {
104
        Name         string
105
        Filename     string
106
        Op           fsnotify.Op
107
        ShouldIgnore bool
108
}
109

110
func GetFileEventTestCases() []FileEventTestCase {
1✔
111
        return []FileEventTestCase{
1✔
112
                // Regular files that should not be ignored
1✔
113
                {"TypeScript file", "index.ts", fsnotify.Write, false},
1✔
114
                {"JavaScript file", "function.js", fsnotify.Create, false},
1✔
115
                {"JSON config", "config.json", fsnotify.Write, false},
1✔
116
                {"Markdown doc", "README.md", fsnotify.Write, false},
1✔
117

1✔
118
                // Editor files that should be ignored
1✔
119
                {"Vim backup", "file.txt~", fsnotify.Write, true},
1✔
120
                {"Vim swap", ".file.swp", fsnotify.Create, true},
1✔
121
                {"Emacs lock", ".#file.txt", fsnotify.Create, true},
1✔
122
                {"Temp file", "file.tmp", fsnotify.Write, true},
1✔
123

1✔
124
                // Deno temporary files
1✔
125
                {"Deno bundle", "___deno_bundle_123___", fsnotify.Create, true},
1✔
126
                {"Deno temp", "___temp_file___", fsnotify.Write, true},
1✔
127

1✔
128
                // Special operation cases
1✔
129
                {"CHMOD on underscore file", "file___", fsnotify.Chmod, true},
1✔
130
                {"Write on underscore file", "file___", fsnotify.Write, false},
1✔
131
        }
1✔
132
}
1✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc