Skip to content

Commit

Permalink
Apply pull request review suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
oleiade committed Apr 29, 2024
1 parent c028e12 commit a35dad0
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 38 deletions.
60 changes: 29 additions & 31 deletions js/modules/k6/experimental/streams/readable_streams_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ func TestReadableStream(t *testing.T) {
"templated.any.js",
}

for _, s := range suites {
s := s
t.Run(s, func(t *testing.T) {
for _, suite := range suites {
suite := suite
t.Run(suite, func(t *testing.T) {
t.Parallel()
ts := newConfiguredRuntime(t)
gotErr := ts.EventLoop.Start(func() error {
return executeTestScripts(ts.VU, "tests/wpt/streams/readable-streams", s)
return executeTestScript(ts.VU, "tests/wpt/streams/readable-streams", suite)
})
assert.NoError(t, gotErr)
})
Expand Down Expand Up @@ -84,39 +84,37 @@ func compileAndRun(t testing.TB, runtime *modulestest.Runtime, base, file string
require.NoError(t, err)
}

func executeTestScripts(vu modules.VU, base string, scripts ...string) error {
for _, script := range scripts {
program, err := modulestest.CompileFile(base, script)
if err != nil {
return err
}

if _, err = vu.Runtime().RunProgram(program); err != nil {
return err
}

// After having executed the tests suite file,
// we use a callback to make sure we wait until all
// the promise-based tests have finished.
// Also, as a mechanism to capture deadlocks caused
// by those promises not resolved during normal execution.
callback := vu.RegisterCallback()
if err := vu.Runtime().Set("wait", func() {
callback(func() error { return nil })
}); err != nil {
return err
}

waitForPromiseTests := `
func executeTestScript(vu modules.VU, base string, script string) error {
program, err := modulestest.CompileFile(base, script)
if err != nil {
return err
}

if _, err = vu.Runtime().RunProgram(program); err != nil {
return err
}

// After having executed the tests suite file,
// we use a callback to make sure we wait until all
// the promise-based tests have finished.
// Also, as a mechanism to capture deadlocks caused
// by those promises not resolved during normal execution.
callback := vu.RegisterCallback()
if err := vu.Runtime().Set("wait", func() {
callback(func() error { return nil })
}); err != nil {
return err
}

waitForPromiseTests := `
if (this.tests && this.tests.promise_tests && typeof this.tests.promise_tests.then === 'function') {
this.tests.promise_tests.then(() => wait());
} else {
wait();
}
`
if _, err = vu.Runtime().RunString(waitForPromiseTests); err != nil {
return err
}
if _, err = vu.Runtime().RunString(waitForPromiseTests); err != nil {
return err
}

return nil
Expand Down
14 changes: 7 additions & 7 deletions js/modules/k6/experimental/streams/tests/testharness.js.patch
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ index c5c375e17..57d201b57 100644
this.phase = this.phases.HAS_RESULT;
this.done();
+
+ // We don't want to rely on the DOM and other browser-based
+ // We don't want to rely on the DOM and other browser-based
+ // mechanisms for reporting test failures. Instead, we just
+ // throw the error and make it fail fast, to be aware of it.
+ //
Expand All @@ -34,13 +34,13 @@ index c5c375e17..57d201b57 100644
}
@@ -4784,6 +4798,11 @@
*/

var tests = new Tests();
+ // We expose the [tests] global variable through
+ // the [global_scope], so we can access it from
+ // Go code, in order to make sure that all test
+ // have finished from Go code.
+ // We expose the [tests] global variable through
+ // the [global_scope], so we can access it from
+ // Go code, in order to make sure that all test
+ // have finished from Go code.
+ global_scope.tests = tests;

if (global_scope.addEventListener) {
var error_handler = function(error, message, stack) {

0 comments on commit a35dad0

Please sign in to comment.