Repository navigation
Expand file tree
/
Copy pathbundle_test.go
More file actions
93 lines (87 loc) · 2.34 KB
/
Copy pathbundle_test.go
File metadata and controls
93 lines (87 loc) · 2.34 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
package function
import (
"bytes"
"context"
"fmt"
"os"
"path/filepath"
"testing"
fs "testing/fstest"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/supabase/cli/pkg/cast"
)
func TestMain(m *testing.M) {
// Setup mock edge runtime binary
if len(os.Args) > 1 && os.Args[1] == "bundle" {
if msg := os.Getenv("TEST_BUNDLE_ERROR"); len(msg) > 0 {
fmt.Fprintln(os.Stderr, msg)
os.Exit(1)
}
os.Exit(0)
}
// Run test suite
os.Exit(m.Run())
}
func TestBundleFunction(t *testing.T) {
cwd, err := os.Getwd()
require.NoError(t, err)
edgeRuntimeBin, err = os.Executable()
require.NoError(t, err)
t.Run("creates eszip bundle", func(t *testing.T) {
var body bytes.Buffer
// Setup in-memory fs
fsys := fs.MapFS{
"hello.eszip": &fs.MapFile{},
}
// Setup mock bundler
bundler := nativeBundler{fsys: fsys}
// Run test
meta, err := bundler.Bundle(
context.Background(),
"hello",
"hello/index.ts",
"hello/deno.json",
[]string{"hello/data.pdf"},
&body,
)
// Check error
assert.NoError(t, err)
assert.Equal(t, compressedEszipMagicID+";", body.String())
assert.Equal(t, cast.Ptr("hello"), meta.Name)
entrypoint := fmt.Sprintf("file://%s/hello/index.ts", filepath.ToSlash(cwd))
assert.Equal(t, entrypoint, meta.EntrypointPath)
importMap := fmt.Sprintf("file://%s/hello/deno.json", filepath.ToSlash(cwd))
assert.Equal(t, &importMap, meta.ImportMapPath)
staticFile := fmt.Sprintf("file://%s/hello/data.pdf", filepath.ToSlash(cwd))
assert.Equal(t, cast.Ptr([]string{staticFile}), meta.StaticPatterns)
assert.Nil(t, meta.VerifyJwt)
})
t.Run("ignores empty value", func(t *testing.T) {
var body bytes.Buffer
// Setup in-memory fs
fsys := fs.MapFS{
"hello.eszip": &fs.MapFile{},
}
// Setup mock bundler
bundler := nativeBundler{fsys: fsys}
// Run test
meta, err := bundler.Bundle(
context.Background(),
"hello",
"hello/index.ts",
"",
nil,
&body,
)
// Check error
assert.NoError(t, err)
assert.Equal(t, compressedEszipMagicID+";", body.String())
assert.Equal(t, cast.Ptr("hello"), meta.Name)
entrypoint := fmt.Sprintf("file://%s/hello/index.ts", filepath.ToSlash(cwd))
assert.Equal(t, entrypoint, meta.EntrypointPath)
assert.Nil(t, meta.ImportMapPath)
assert.NotNil(t, meta.StaticPatterns)
assert.Nil(t, meta.VerifyJwt)
})
}