2026-05-30 14:21:43 +08:00
|
|
|
package js
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"context"
|
|
|
|
|
"strings"
|
|
|
|
|
"testing"
|
2026-06-28 01:39:41 +08:00
|
|
|
"time"
|
2026-05-30 14:21:43 +08:00
|
|
|
|
|
|
|
|
"apigo.cc/go/jsmod"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func TestDocGeneration(t *testing.T) {
|
|
|
|
|
jsmod.Register("db", map[string]any{
|
|
|
|
|
"query": func(ctx context.Context, sql string, args []any) ([]map[string]any, error) {
|
|
|
|
|
return nil, nil
|
|
|
|
|
},
|
2026-06-28 01:39:41 +08:00
|
|
|
"now": func() time.Time { return time.Time{} },
|
2026-06-08 20:47:30 +08:00
|
|
|
"version": "1.0.0",
|
2026-06-05 19:05:20 +08:00
|
|
|
"__exportInternal": func() *struct{ Name string } { return nil },
|
2026-05-30 14:21:43 +08:00
|
|
|
})
|
|
|
|
|
|
|
|
|
|
doc := Doc()
|
2026-06-28 01:39:41 +08:00
|
|
|
if !strings.Contains(doc, "interface GoContext {") {
|
|
|
|
|
t.Error("doc should contain GoContext interface")
|
|
|
|
|
}
|
|
|
|
|
if !strings.Contains(doc, "interface Logger {") {
|
|
|
|
|
t.Error("doc should contain Logger interface")
|
|
|
|
|
}
|
|
|
|
|
if !strings.Contains(doc, "Info(message: string, ...extra: any[]): void;") {
|
|
|
|
|
t.Error("doc should contain Logger methods")
|
|
|
|
|
}
|
|
|
|
|
if strings.Contains(doc, "GetTraceId(): string;") || strings.Contains(doc, "New(traceId: string): Logger;") || strings.Contains(doc, "As<T = any>(value: T, err: any): T;") {
|
|
|
|
|
t.Error("doc should not contain Logger internal methods")
|
|
|
|
|
}
|
|
|
|
|
if !strings.Contains(doc, "interface GoTime {") {
|
2026-06-05 19:05:20 +08:00
|
|
|
t.Error("doc should contain GoTime interface")
|
2026-05-30 14:21:43 +08:00
|
|
|
}
|
2026-06-05 19:05:20 +08:00
|
|
|
if !strings.Contains(doc, "interface Db_Module") {
|
|
|
|
|
t.Error("doc should contain Db_Module interface")
|
2026-05-30 14:21:43 +08:00
|
|
|
}
|
2026-06-28 01:39:41 +08:00
|
|
|
if !strings.Contains(doc, "declare const db: Db_Module;") {
|
|
|
|
|
t.Error("doc should contain top-level module declaration")
|
|
|
|
|
}
|
|
|
|
|
if strings.Contains(doc, "declare const go:") {
|
|
|
|
|
t.Error("doc should not contain legacy go namespace declaration")
|
2026-06-05 19:05:20 +08:00
|
|
|
}
|
|
|
|
|
if strings.Contains(doc, "__exportInternal") {
|
|
|
|
|
t.Error("doc should NOT contain __exportInternal")
|
|
|
|
|
}
|
|
|
|
|
if !strings.Contains(doc, "interface Db_") {
|
|
|
|
|
t.Error("doc should contain supporting interface for internal struct")
|
2026-05-30 14:21:43 +08:00
|
|
|
}
|
|
|
|
|
}
|