Amp-Thread-ID: https://ampcode.com/threads/T-01a02485-5574-707c-bff4-5668d83bee8a Co-authored-by: Heaust Azure <heaust.azure@gmail.com>
39 lines
829 B
Go
39 lines
829 B
Go
package main
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
)
|
|
|
|
func TestLoadPackages(t *testing.T) {
|
|
directory := t.TempDir()
|
|
for _, name := range []string{
|
|
"core.js",
|
|
"handles.js",
|
|
"worker.js",
|
|
"importer-worker.js",
|
|
"bvh-worker.js",
|
|
filepath.Join("pkg", "yawn_core_bg.wasm"),
|
|
} {
|
|
path := filepath.Join(directory, name)
|
|
if err := os.MkdirAll(filepath.Dir(path), 0o755); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err := os.WriteFile(path, []byte(name), 0o644); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
|
|
packages, err := loadPackages(directory)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if len(packages) != 6 {
|
|
t.Fatalf("package count = %d", len(packages))
|
|
}
|
|
if content := string(packages["pkg/yawn_core_bg.wasm"].content); content != filepath.Join("pkg", "yawn_core_bg.wasm") {
|
|
t.Fatalf("WASM content = %q", content)
|
|
}
|
|
}
|