snapshot before legacy cleanup
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
package runtime
|
||||
|
||||
import (
|
||||
"archive/zip"
|
||||
"bytes"
|
||||
"io"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestBuildJSDeployZipExportsMainAndHandler(t *testing.T) {
|
||||
zipBytes, err := BuildJSDeployZip(`module.exports = async function () { return { status: 200, body: "ok" }; }`)
|
||||
if err != nil {
|
||||
t.Fatalf("BuildJSDeployZip() error = %v", err)
|
||||
}
|
||||
|
||||
zr, err := zip.NewReader(bytes.NewReader(zipBytes), int64(len(zipBytes)))
|
||||
if err != nil {
|
||||
t.Fatalf("zip.NewReader() error = %v", err)
|
||||
}
|
||||
|
||||
files := map[string]string{}
|
||||
for _, file := range zr.File {
|
||||
rc, openErr := file.Open()
|
||||
if openErr != nil {
|
||||
t.Fatalf("open %q: %v", file.Name, openErr)
|
||||
}
|
||||
content, readErr := io.ReadAll(rc)
|
||||
_ = rc.Close()
|
||||
if readErr != nil {
|
||||
t.Fatalf("read %q: %v", file.Name, readErr)
|
||||
}
|
||||
files[file.Name] = string(content)
|
||||
}
|
||||
|
||||
if files["package.json"] != `{"type":"module"}` {
|
||||
t.Fatalf("package.json = %q, want ESM marker", files["package.json"])
|
||||
}
|
||||
|
||||
mainJS := files["main.js"]
|
||||
if !strings.Contains(mainJS, `export { __invoke as main, __invoke as handler };`) {
|
||||
t.Fatalf("main.js does not export both main and handler: %s", mainJS)
|
||||
}
|
||||
if !strings.Contains(mainJS, `export default __invoke;`) {
|
||||
t.Fatalf("main.js does not export default invoke: %s", mainJS)
|
||||
}
|
||||
if !strings.Contains(mainJS, `_fn.default || _fn.handler || _fn.main`) {
|
||||
t.Fatalf("main.js lost user export resolution: %s", mainJS)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user