Use `startIteration` in the tracing test
Opened this issue · 0 comments
inancgumus commented
Why don't we use the startIteration
helper and run tests in parallel as in here:
xk6-browser/tests/page_test.go
Lines 185 to 244 in b8d6418
func TestPageEvaluateMapping(t *testing.T) { | |
t.Parallel() | |
tests := []struct { | |
name string | |
script string | |
want any | |
}{ | |
{ | |
name: "arrow", | |
script: "() => 0", | |
want: 0, | |
}, | |
{ | |
name: "full_func", | |
script: "function() {return 1}", | |
want: 1, | |
}, | |
{ | |
name: "arrow_func_no_return", | |
script: "() => {2}", | |
want: sobek.Null(), | |
}, | |
{ | |
name: "full_func_no_return", | |
script: "function() {3}", | |
want: sobek.Null(), | |
}, | |
{ | |
name: "async_func", | |
script: "async function() {return 4}", | |
want: 4, | |
}, | |
} | |
for _, tt := range tests { | |
tt := tt | |
t.Run(tt.name, func(t *testing.T) { | |
t.Parallel() | |
vu, _, _, cleanUp := startIteration(t) | |
defer cleanUp() | |
// Test script as non string input | |
vu.SetVar(t, "p", &sobek.Object{}) | |
got := vu.RunPromise(t, ` | |
p = await browser.newPage() | |
return await p.evaluate(%s) | |
`, tt.script) | |
assert.Equal(t, vu.ToSobekValue(tt.want), got.Result()) | |
// Test script as string input | |
got = vu.RunPromise(t, | |
`return await p.evaluate("%s")`, | |
tt.script, | |
) | |
assert.Equal(t, vu.ToSobekValue(tt.want), got.Result()) | |
}) | |
} | |
} |
Originally posted by @inancgumus in #1421 (comment)