Skip to content

Commit 178f64e

Browse files
committed
fix: Fix weird issue with parallel tests
For some reason, when running parallel tests, if the polyfills are installed after retrieving the global window proxy, and setting the internal field referencing the Go window object, the field value is lost in parallel tests.
1 parent 921c8f1 commit 178f64e

File tree

3 files changed

+10
-3
lines changed

3 files changed

+10
-3
lines changed

internal/test/scripttests/suites.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@ import (
88
)
99

1010
func runSuite(s suite.TestingSuite) func(t *testing.T) {
11-
return func(t *testing.T) { suite.Run(t, s) }
11+
return func(t *testing.T) {
12+
t.Parallel()
13+
suite.Run(t, s)
14+
}
1215
}
1316

1417
func RunSuites(t *testing.T, h html.ScriptHost) {

scripting/v8host/event_target_test.go

+5
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,16 @@ import (
44
"testing"
55

66
"github.com/gost-dom/browser/html"
7+
"github.com/gost-dom/browser/scripting/v8host"
78
"github.com/onsi/gomega"
89
. "github.com/onsi/gomega"
910
)
1011

1112
func TestV8EventTargetAddRemoveListeners(t *testing.T) {
13+
t.Parallel()
14+
host := v8host.New()
15+
t.Cleanup(func() { host.Close() })
16+
1217
g := gomega.NewWithT(t)
1318
win := html.NewWindow(html.WindowOptionHost(host))
1419
t.Cleanup(win.Close)

scripting/v8host/script_host.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,6 @@ func (host *V8ScriptHost) NewContext(w html.Window) html.ScriptContext {
357357
errorCallback := func(err error) {
358358
w.DispatchEvent(event.NewErrorEvent(err))
359359
}
360-
global = context.v8ctx.Global()
361360
context.eventLoop = newEventLoop(context, errorCallback)
362361
host.inspector.ContextCreated(context.v8ctx)
363362
err := installPolyfills(context)
@@ -371,7 +370,7 @@ func (host *V8ScriptHost) NewContext(w html.Window) html.ScriptContext {
371370
),
372371
)
373372
}
374-
context.cacheNode(global, w)
373+
context.cacheNode(context.v8ctx.Global(), w)
375374
host.addContext(context)
376375

377376
return context

0 commit comments

Comments
 (0)