mirror of
https://github.com/priyanshujain/sanderling.git
synced 2026-10-04 03:57:09 +00:00
test(cmd): smoke-test bundle-check resolves spec aliases
This commit is contained in:
1 parent
da9455cd5a
commit
3197e64562
2 files changed
+69
No files matched your search
@@ -0,0 +1,57 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
)
|
||||
|
||||
// repoSpecSrc walks up from the test's working directory to the repo root and
|
||||
// returns pkg/spec/src. The bundle-check aliases once pointed at the
|
||||
// non-existent pkg/spec-api/src, so esbuild resolved nothing and the tool
|
||||
// silently emitted an empty bundle.
|
||||
func repoSpecSrc(t *testing.T) string {
|
||||
t.Helper()
|
||||
dir, err := os.Getwd()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for {
|
||||
candidate := filepath.Join(dir, "pkg/spec/src")
|
||||
if _, err := os.Stat(filepath.Join(candidate, "index.ts")); err == nil {
|
||||
return candidate
|
||||
}
|
||||
parent := filepath.Dir(dir)
|
||||
if parent == dir {
|
||||
t.Fatal("pkg/spec/src/index.ts not found above test dir")
|
||||
}
|
||||
dir = parent
|
||||
}
|
||||
}
|
||||
|
||||
func TestBundleSpec_ResolvesSpecAliases(t *testing.T) {
|
||||
specSrc := repoSpecSrc(t)
|
||||
entry, err := filepath.Abs(filepath.Join("testdata", "spec.ts"))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
result, err := bundleSpec(specSrc, entry)
|
||||
if err != nil {
|
||||
t.Fatalf("bundle: %v", err)
|
||||
}
|
||||
if len(result.JavaScript) == 0 {
|
||||
t.Fatal("empty bundle: aliases resolved to nothing")
|
||||
}
|
||||
if result.SHA256 == "" {
|
||||
t.Fatal("missing bundle hash")
|
||||
}
|
||||
|
||||
second, err := bundleSpec(specSrc, entry)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if result.SHA256 != second.SHA256 {
|
||||
t.Errorf("unstable bundle hash: %s vs %s", result.SHA256, second.SHA256)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user