diff --git a/cmd/run_test.go b/cmd/run_test.go index e0ea78c72d08..95b02e1d044b 100644 --- a/cmd/run_test.go +++ b/cmd/run_test.go @@ -155,7 +155,7 @@ func TestAbortTest(t *testing.T) { //nolint: tparallel t.Run("Check that teardown is called", func(t *testing.T) { //nolint: paralleltest ctx, cancel := context.WithCancel(context.Background()) defer cancel() - msg := "Calling teardown function after abortTest()" + msg := "Calling teardown function after test.abort()" var buf bytes.Buffer logger := logrus.New() logger.SetOutput(&buf) diff --git a/cmd/testdata/abort.js b/cmd/testdata/abort.js index a451ed512b5a..b4b4a793ae15 100644 --- a/cmd/testdata/abort.js +++ b/cmd/testdata/abort.js @@ -1,5 +1,5 @@ -import { abortTest } from 'k6'; +import exec from 'k6/execution'; export default function () { - abortTest(); + exec.test.abort(); } diff --git a/cmd/testdata/teardown.js b/cmd/testdata/teardown.js index aa870819b0d0..3403c16ce385 100644 --- a/cmd/testdata/teardown.js +++ b/cmd/testdata/teardown.js @@ -1,9 +1,9 @@ -import { abortTest } from 'k6'; +import exec from 'k6/execution'; export default function () { - abortTest(); + exec.test.abort(); } export function teardown() { - console.log('Calling teardown function after abortTest()'); -} \ No newline at end of file + console.log('Calling teardown function after test.abort()'); +} diff --git a/js/modules/k6/k6.go b/js/modules/k6/k6.go index 094315a58fde..3e94cdb54f9a 100644 --- a/js/modules/k6/k6.go +++ b/js/modules/k6/k6.go @@ -22,7 +22,6 @@ package k6 import ( - "context" "errors" "math/rand" "sync/atomic" @@ -152,17 +151,6 @@ func (mi *K6) Group(name string, fn goja.Callable) (goja.Value, error) { return ret, err } -// AbortTest exposes abortTest function in the k6 module. When called it will -// interrupt the active goja runtime passed with ctx. -func (*K6) AbortTest(ctx context.Context, msg goja.Value) { - rt := common.GetRuntime(ctx) - reason := common.AbortTest - if !goja.IsUndefined(msg) { - reason = msg.String() - } - rt.Interrupt(&common.InterruptError{Reason: reason}) -} - // Check will emit check metrics for the provided checks. //nolint:cyclop func (mi *K6) Check(arg0, checks goja.Value, extras ...goja.Value) (bool, error) { diff --git a/js/modules/k6/k6_test.go b/js/modules/k6/k6_test.go index f1a2d285c57a..6e541d9033f8 100644 --- a/js/modules/k6/k6_test.go +++ b/js/modules/k6/k6_test.go @@ -474,35 +474,3 @@ func TestCheckTags(t *testing.T) { }, sample.Tags.CloneTags()) } } - -func TestAbortTest(t *testing.T) { //nolint: tparallel - t.Parallel() - - rt := goja.New() - baseCtx := common.WithRuntime(context.Background(), rt) - - ctx := new(context.Context) - *ctx = baseCtx - err := rt.Set("k6", common.Bind(rt, New(), ctx)) - require.Nil(t, err) - prove := func(t *testing.T, script, reason string) { - _, err := rt.RunString(script) - require.NotNil(t, err) - var x *goja.InterruptedError - assert.ErrorAs(t, err, &x) - v, ok := x.Value().(*common.InterruptError) - require.True(t, ok) - require.Equal(t, v.Reason, reason) - } - t.Run("Without state", func(t *testing.T) { //nolint: paralleltest - prove(t, "k6.abortTest()", common.AbortTest) - }) - t.Run("With state and default reason", func(t *testing.T) { //nolint: paralleltest - *ctx = lib.WithState(baseCtx, &lib.State{}) - prove(t, "k6.abortTest()", common.AbortTest) - }) - t.Run("With state and custom reason", func(t *testing.T) { //nolint: paralleltest - *ctx = lib.WithState(baseCtx, &lib.State{}) - prove(t, `k6.abortTest("mayday")`, "mayday") - }) -} diff --git a/js/runner_test.go b/js/runner_test.go index d9e76f6494d5..34abe6a8b60f 100644 --- a/js/runner_test.go +++ b/js/runner_test.go @@ -1507,8 +1507,8 @@ func TestInitContextForbidden(t *testing.T) { }, { "abortTest", - `var abortTest = require("k6").abortTest; - abortTest(); + `var test = require("k6/execution").test; + test.abort(); exports.default = function() { console.log("p"); }`, common.AbortTest, },