mirror of
https://github.com/priyanshujain/sanderling.git
synced 2026-10-02 19:17:10 +00:00
test(verifier): one spec bundler instead of four
The four differed only in which rows of the alias map they omitted, and esbuild applies an alias only on an actual import, so the omissions were not a difference. One bundleSpec carries what genuinely varied: an inline spec or a path on disk, and an optional runtime entry to swap for the shipped one.
This commit is contained in:
1 parent
22296c5316
commit
5a0439d394
4 files changed
+70
-120
No files matched your search
@@ -3,54 +3,19 @@ package verifier
|
||||
import (
|
||||
"errors"
|
||||
"maps"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"slices"
|
||||
"testing"
|
||||
|
||||
"github.com/priyanshujain/sanderling/internal/bundler"
|
||||
"github.com/priyanshujain/sanderling/internal/hierarchy"
|
||||
)
|
||||
|
||||
// bundleInlineSpec bundles an inline spec through the real @sanderling/spec API
|
||||
// and goja runtime entry, so the bundle installs __sanderlingSetupAction__ the
|
||||
// way the CLI does.
|
||||
func bundleInlineSpec(t *testing.T, source string) string {
|
||||
t.Helper()
|
||||
dir := t.TempDir()
|
||||
specPath := filepath.Join(dir, "spec.ts")
|
||||
if err := os.WriteFile(specPath, []byte(source), 0o600); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
abs := func(rel string) string {
|
||||
path, err := filepath.Abs(rel)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
return path
|
||||
}
|
||||
bundle, err := bundler.Bundle(bundler.Options{
|
||||
EntryFile: specPath,
|
||||
RuntimeFile: abs("../../pkg/spec/src/goja-runtime.ts"),
|
||||
Aliases: map[string]string{
|
||||
"@sanderling/spec": abs("../../pkg/spec/src/index.ts"),
|
||||
"@sanderling/spec/defaults": abs("../../pkg/spec/src/defaults/index.ts"),
|
||||
"@sanderling/spec/defaults/properties": abs("../../pkg/spec/src/defaults/properties.ts"),
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("bundle: %v", err)
|
||||
}
|
||||
return string(bundle.JavaScript)
|
||||
}
|
||||
|
||||
func loadBundled(t *testing.T, source, treeJSON string) *Verifier {
|
||||
t.Helper()
|
||||
v, err := New()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := v.Load(bundleInlineSpec(t, source)); err != nil {
|
||||
if err := v.Load(bundleSpec(t, bundleOptions{SpecSource: source})); err != nil {
|
||||
t.Fatalf("load: %v", err)
|
||||
}
|
||||
tree, err := hierarchy.Parse(treeJSON)
|
||||
|
||||
Reference in new issue
Block a user