-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjavascripts_test.go
More file actions
105 lines (87 loc) · 3.12 KB
/
javascripts_test.go
File metadata and controls
105 lines (87 loc) · 3.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
package client
import (
"strings"
"testing"
)
func countSignatures(content string, sigs []string) int {
c := 0
for _, s := range sigs {
if strings.Contains(content, s) {
c++
}
}
return c
}
func matchedSignatures(content string, sigs []string) []string {
var out []string
for _, s := range sigs {
if strings.Contains(content, s) {
out = append(out, s)
}
}
return out
}
// TestGetSSRClientInitJSSignatures verifies that GetSSRClientInitJS()
// returns distinct JS content for Go vs TinyGo (at least one signature found each)
// and that the TinyGo usage flag changes between modes. The test is skipped
// if tinygo is not available in PATH per VerifyTinyGoInstallation requirement.
func TestGetSSRClientInitJSSignatures(t *testing.T) {
tmpDir := t.TempDir()
config := &Config{}
// Create WasmClient instance with temp directory
w := New(config)
w.SetAppRootDir(tmpDir)
// Skip only if tinygo not present
if err := w.VerifyTinyGoInstallation(); err != nil {
t.Skipf("skipping test: tinygo not available: %v", err)
}
// --- TinyGo case ---
// Set mode to debug (requires TinyGo)
w.currenSizeMode = "M"
// ensure installer flag
w.tinyGoInstalled = true
// Check that WasmProjectTinyGoJsUse reports TinyGo usage
_, tinyUsedBefore := w.WasmProjectTinyGoJsUse()
if !tinyUsedBefore {
t.Fatalf("expected TinyGo usage in debug mode, WasmProjectTinyGoJsUse returned false")
}
tinyJs, err := w.GetSSRClientInitJS()
if err != nil {
t.Fatalf("GetSSRClientInitJS() failed for TinyGo case: %v", err)
}
tinyGoFound := countSignatures(tinyJs, wasm_execTinyGoSignatures())
goFoundInTiny := countSignatures(tinyJs, wasm_execGoSignatures())
t.Logf("TinyGo JS matched TinyGo sigs: %v", matchedSignatures(tinyJs, wasm_execTinyGoSignatures()))
t.Logf("TinyGo JS matched Go sigs: %v", matchedSignatures(tinyJs, wasm_execGoSignatures()))
if tinyGoFound == 0 {
t.Fatalf("expected at least one TinyGo signature in TinyGo JS, found none")
}
if goFoundInTiny != 0 {
t.Fatalf("expected no Go signatures in TinyGo JS, but found %d", goFoundInTiny)
}
// --- Go case ---
// Set mode to coding (Go standard)
w.currenSizeMode = "L"
_, tinyUsedAfter := w.WasmProjectTinyGoJsUse()
if tinyUsedAfter {
t.Fatalf("expected TinyGo usage to be false in coding mode, but WasmProjectTinyGoJsUse returned true")
}
goJs, err := w.GetSSRClientInitJS()
if err != nil {
t.Fatalf("GetSSRClientInitJS() failed for Go case: %v", err)
}
goFound := countSignatures(goJs, wasm_execGoSignatures())
tinyFoundInGo := countSignatures(goJs, wasm_execTinyGoSignatures())
t.Logf("Go JS matched Go sigs: %v", matchedSignatures(goJs, wasm_execGoSignatures()))
t.Logf("Go JS matched TinyGo sigs: %v", matchedSignatures(goJs, wasm_execTinyGoSignatures()))
if goFound == 0 {
t.Fatalf("expected at least one Go signature in Go JS, found none")
}
if tinyFoundInGo != 0 {
t.Fatalf("expected no TinyGo signatures in Go JS, but found %d", tinyFoundInGo)
}
// Verify the TinyGo usage flag changes between the two calls
if tinyUsedBefore == tinyUsedAfter {
t.Fatalf("expected TinyGo usage flag to change between debug and coding modes, but it did not")
}
}