-
Notifications
You must be signed in to change notification settings - Fork 10
/
test-utils.go
54 lines (45 loc) · 1001 Bytes
/
test-utils.go
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
package vueglue
import (
"errors"
"net/http"
"net/http/httptest"
"os"
)
func initializeVueGlue(config *ViteConfig) (*VueGlue, error) {
if config == nil {
config = &ViteConfig{
Environment: "development",
JSProjectPath: "testdata",
URLPrefix: "/",
FS: os.DirFS("testdata"),
EntryPoint: "main.js",
ViteVersion: "2",
}
}
glue, err := NewVueGlue(config)
return glue, err
}
func startTestServer(glue *VueGlue) (*httptest.Server, error) {
handler, err := glue.FileServer()
if err != nil {
return nil, err
}
mux := http.NewServeMux()
mux.Handle("/", handler)
server := httptest.NewServer(mux)
if server == nil {
return nil, errors.New("did not get server instance")
}
return server, nil
}
func bootStrapServer(config *ViteConfig) (*httptest.Server, error) {
glue, err := initializeVueGlue(config)
if err != nil {
return nil, err
}
server, err := startTestServer(glue)
if err != nil {
return nil, err
}
return server, nil
}