diff --git a/js/modules/k6/experimental/streams/readable_streams_test.go b/js/modules/k6/experimental/streams/readable_streams_test.go index b16b279298f..2dac34889e5 100644 --- a/js/modules/k6/experimental/streams/readable_streams_test.go +++ b/js/modules/k6/experimental/streams/readable_streams_test.go @@ -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) }) @@ -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 diff --git a/js/modules/k6/experimental/streams/tests/testharness.js.patch b/js/modules/k6/experimental/streams/tests/testharness.js.patch index 2a2ac0522e5..d2f84a6db76 100644 --- a/js/modules/k6/experimental/streams/tests/testharness.js.patch +++ b/js/modules/k6/experimental/streams/tests/testharness.js.patch @@ -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. + // @@ -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) {