diff --git a/js/console_test.go b/js/console_test.go index aa8b938ab9f..2d65af9cbdf 100644 --- a/js/console_test.go +++ b/js/console_test.go @@ -73,7 +73,7 @@ func TestConsoleContext(t *testing.T) { func getSimpleRunner(filename, data string, opts ...interface{}) (*Runner, error) { var ( fs = afero.NewMemMapFs() - rtOpts = lib.RuntimeOptions{} + rtOpts = lib.RuntimeOptions{CompatibilityMode: null.NewString("base", true)} ) for _, o := range opts { switch opt := o.(type) { @@ -117,7 +117,7 @@ func TestConsole(t *testing.T) { args, result := args, result t.Run(args, func(t *testing.T) { r, err := getSimpleRunner("/script.js", fmt.Sprintf( - `export default function() { console.%s(%s); }`, + `exports.default = function() { console.%s(%s); }`, name, args, )) assert.NoError(t, err) @@ -209,7 +209,7 @@ func TestFileConsole(t *testing.T) { } r, err := getSimpleRunner("/script", fmt.Sprintf( - `export default function() { console.%s(%s); }`, + `exports.default = function() { console.%s(%s); }`, name, args, )) assert.NoError(t, err) diff --git a/js/module_loading_test.go b/js/module_loading_test.go index 6e64c62dc2c..57b0f5728c3 100644 --- a/js/module_loading_test.go +++ b/js/module_loading_test.go @@ -28,6 +28,7 @@ import ( "github.com/spf13/afero" "github.com/stretchr/testify/require" + null "gopkg.in/guregu/null.v3" "github.com/loadimpact/k6/lib" "github.com/loadimpact/k6/lib/testutils/httpmultibin" @@ -99,7 +100,7 @@ func TestLoadOnceGlobalVars(t *testing.T) { throw new Error("A() != B() (" + A() + ") != (" + B() + ")"); } } - `, fs) + `, fs, lib.RuntimeOptions{CompatibilityMode: null.StringFrom("extended")}) require.NoError(t, err) arc := r1.MakeArchive() @@ -148,7 +149,7 @@ func TestLoadExportsIsUsableInModule(t *testing.T) { throw new Error("wrong value of B() " + B()); } } - `, fs) + `, fs, lib.RuntimeOptions{CompatibilityMode: null.StringFrom("extended")}) require.NoError(t, err) arc := r1.MakeArchive() @@ -194,7 +195,7 @@ func TestLoadDoesntBreakHTTPGet(t *testing.T) { throw new Error("wrong status "+ resp.status); } } - `, fs) + `, fs, lib.RuntimeOptions{CompatibilityMode: null.StringFrom("extended")}) require.NoError(t, err) require.NoError(t, r1.SetOptions(lib.Options{Hosts: tb.Dialer.Hosts})) @@ -239,7 +240,7 @@ func TestLoadGlobalVarsAreNotSharedBetweenVUs(t *testing.T) { throw new Error("wrong value of a " + a); } } - `, fs) + `, fs, lib.RuntimeOptions{CompatibilityMode: null.StringFrom("extended")}) require.NoError(t, err) arc := r1.MakeArchive() @@ -302,7 +303,7 @@ func TestLoadCycle(t *testing.T) { `), os.ModePerm)) data, err := afero.ReadFile(fs, "/main.js") require.NoError(t, err) - r1, err := getSimpleRunner("/main.js", string(data), fs) + r1, err := getSimpleRunner("/main.js", string(data), fs, lib.RuntimeOptions{CompatibilityMode: null.StringFrom("extended")}) require.NoError(t, err) arc := r1.MakeArchive() @@ -364,7 +365,7 @@ func TestLoadCycleBinding(t *testing.T) { throw new Error("Wrong value of bar() "+ barMessage); } } - `, fs) + `, fs, lib.RuntimeOptions{CompatibilityMode: null.StringFrom("extended")}) require.NoError(t, err) arc := r1.MakeArchive() @@ -428,7 +429,7 @@ func TestBrowserified(t *testing.T) { throw new Error("bravo.B() != 'b' (" + bravo.B() + ") != 'b'"); } } - `, fs) + `, fs, lib.RuntimeOptions{CompatibilityMode: null.StringFrom("extended")}) require.NoError(t, err) arc := r1.MakeArchive() @@ -459,7 +460,7 @@ func TestLoadingUnexistingModuleDoesntPanic(t *testing.T) { } catch (err) { b = "correct"; } - export default function() { + exports.default = function() { if (b != "correct") { throw new Error("wrong b "+ JSON.stringify(b)); } diff --git a/js/runner_test.go b/js/runner_test.go index dbc3a15d58c..1b90bc8f770 100644 --- a/js/runner_test.go +++ b/js/runner_test.go @@ -63,8 +63,8 @@ import ( func TestRunnerNew(t *testing.T) { t.Run("Valid", func(t *testing.T) { r, err := getSimpleRunner("/script.js", ` - let counter = 0; - export default function() { counter++; } + var counter = 0; + exports.default = function() { counter++; } `) assert.NoError(t, err) @@ -93,7 +93,7 @@ func TestRunnerNew(t *testing.T) { } func TestRunnerGetDefaultGroup(t *testing.T) { - r1, err := getSimpleRunner("/script.js", `export default function() {};`) + r1, err := getSimpleRunner("/script.js", `exports.default = function() {};`) if assert.NoError(t, err) { assert.NotNil(t, r1.GetDefaultGroup()) } @@ -105,7 +105,7 @@ func TestRunnerGetDefaultGroup(t *testing.T) { } func TestRunnerOptions(t *testing.T) { - r1, err := getSimpleRunner("/script.js", `export default function() {};`) + r1, err := getSimpleRunner("/script.js", `exports.default = function() {};`) if !assert.NoError(t, err) { return } @@ -135,10 +135,10 @@ func TestOptionsSettingToScript(t *testing.T) { optionVariants := []string{ "", - "let options = null;", - "let options = undefined;", - "let options = {};", - "let options = {teardownTimeout: '1s'};", + "var options = null;", + "var options = undefined;", + "var options = {};", + "var options = {teardownTimeout: '1s'};", } for i, variant := range optionVariants { @@ -146,7 +146,7 @@ func TestOptionsSettingToScript(t *testing.T) { t.Run(fmt.Sprintf("Variant#%d", i), func(t *testing.T) { t.Parallel() data := variant + ` - export default function() { + exports.default = function() { if (!options) { throw new Error("Expected options to be defined!"); } @@ -178,8 +178,9 @@ func TestOptionsSettingToScript(t *testing.T) { func TestOptionsPropagationToScript(t *testing.T) { t.Parallel() data := ` - export let options = { setupTimeout: "1s", myOption: "test" }; - export default function() { + var options = { setupTimeout: "1s", myOption: "test" }; + exports.options = options; + exports.default = function() { if (options.external) { throw new Error("Unexpected property external!"); } @@ -203,7 +204,7 @@ func TestOptionsPropagationToScript(t *testing.T) { require.Equal(t, expScriptOptions, r2.GetOptions()) newOptions := lib.Options{SetupTimeout: types.NullDurationFrom(3 * time.Second)} - r2.SetOptions(newOptions) + require.NoError(t, r2.SetOptions(newOptions)) require.Equal(t, newOptions, r2.GetOptions()) testdata := map[string]*Runner{"Source": r1, "Archive": r2} @@ -229,11 +230,11 @@ func TestMetricName(t *testing.T) { defer tb.Cleanup() script := tb.Replacer.Replace(` - import { Counter } from "k6/metrics"; + var Counter = require("k6/metrics").Counter; - let myCounter = new Counter("not ok name @"); + var myCounter = new Counter("not ok name @"); - export default function(data) { + exports.default = function(data) { myCounter.add(1); } `) @@ -247,9 +248,9 @@ func TestSetupDataIsolation(t *testing.T) { defer tb.Cleanup() script := tb.Replacer.Replace(` - import { Counter } from "k6/metrics"; + var Counter = require("k6/metrics").Counter; - export let options = { + exports.options = { execution: { shared_iters: { type: "shared-iterations", @@ -260,13 +261,13 @@ func TestSetupDataIsolation(t *testing.T) { teardownTimeout: "5s", setupTimeout: "5s", }; - let myCounter = new Counter("mycounter"); + var myCounter = new Counter("mycounter"); - export function setup() { + exports.setup = function() { return { v: 0 }; } - export default function(data) { + exports.default = function(data) { if (data.v !== __ITER) { throw new Error("default: wrong data for iter " + __ITER + ": " + JSON.stringify(data)); } @@ -274,7 +275,7 @@ func TestSetupDataIsolation(t *testing.T) { myCounter.add(1); } - export function teardown(data) { + exports.teardown = function(data) { if (data.v !== 0) { throw new Error("teardown: wrong data: " + data.v); } @@ -355,17 +356,17 @@ func testSetupDataHelper(t *testing.T, data string) { func TestSetupDataReturnValue(t *testing.T) { testSetupDataHelper(t, ` - export let options = { setupTimeout: "1s", teardownTimeout: "1s" }; - export function setup() { + exports.options = { setupTimeout: "1s", teardownTimeout: "1s" }; + exports.setup = function() { return 42; } - export default function(data) { + exports.default = function(data) { if (data != 42) { throw new Error("default: wrong data: " + JSON.stringify(data)) } }; - export function teardown(data) { + exports.teardown = function(data) { if (data != 42) { throw new Error("teardown: wrong data: " + JSON.stringify(data)) } @@ -374,14 +375,14 @@ func TestSetupDataReturnValue(t *testing.T) { func TestSetupDataNoSetup(t *testing.T) { testSetupDataHelper(t, ` - export let options = { setupTimeout: "1s", teardownTimeout: "1s" }; - export default function(data) { + exports.options = { setupTimeout: "1s", teardownTimeout: "1s" }; + exports.default = function(data) { if (data !== undefined) { throw new Error("default: wrong data: " + JSON.stringify(data)) } }; - export function teardown(data) { + exports.teardown = function(data) { if (data !== undefined) { console.log(data); throw new Error("teardown: wrong data: " + JSON.stringify(data)) @@ -392,7 +393,7 @@ func TestSetupDataNoSetup(t *testing.T) { func TestConsoleInInitContext(t *testing.T) { r1, err := getSimpleRunner("/script.js", ` console.log("1"); - export default function(data) { + exports.default = function(data) { }; `) require.NoError(t, err) @@ -416,15 +417,15 @@ func TestConsoleInInitContext(t *testing.T) { func TestSetupDataNoReturn(t *testing.T) { testSetupDataHelper(t, ` - export let options = { setupTimeout: "1s", teardownTimeout: "1s" }; - export function setup() { } - export default function(data) { + exports.options = { setupTimeout: "1s", teardownTimeout: "1s" }; + exports.setup = function() { } + exports.default = function(data) { if (data !== undefined) { throw new Error("default: wrong data: " + JSON.stringify(data)) } }; - export function teardown(data) { + exports.teardown = function(data) { if (data !== undefined) { throw new Error("teardown: wrong data: " + JSON.stringify(data)) } @@ -439,11 +440,12 @@ func TestRunnerIntegrationImports(t *testing.T) { "k6/metrics", "k6/html", } + rtOpts := lib.RuntimeOptions{CompatibilityMode: null.StringFrom("extended")} for _, mod := range modules { mod := mod t.Run(mod, func(t *testing.T) { t.Run("Source", func(t *testing.T) { - _, err := getSimpleRunner("/script.js", fmt.Sprintf(`import "%s"; export default function() {}`, mod)) + _, err := getSimpleRunner("/script.js", fmt.Sprintf(`import "%s"; exports.default = function() {}`, mod), rtOpts) assert.NoError(t, err) }) }) @@ -453,7 +455,7 @@ func TestRunnerIntegrationImports(t *testing.T) { t.Run("Files", func(t *testing.T) { fs := afero.NewMemMapFs() require.NoError(t, fs.MkdirAll("/path/to", 0755)) - require.NoError(t, afero.WriteFile(fs, "/path/to/lib.js", []byte(`export default "hi!";`), 0644)) + require.NoError(t, afero.WriteFile(fs, "/path/to/lib.js", []byte(`exports.default = "hi!";`), 0644)) testdata := map[string]struct{ filename, path string }{ "Absolute": {"/path/script.js", "/path/to/lib.js"}, @@ -466,8 +468,8 @@ func TestRunnerIntegrationImports(t *testing.T) { name, data := name, data t.Run(name, func(t *testing.T) { r1, err := getSimpleRunner(data.filename, fmt.Sprintf(` - import hi from "%s"; - export default function() { + var hi = require("%s").default; + exports.default = function() { if (hi != "hi!") { throw new Error("incorrect value"); } }`, data.path), fs) require.NoError(t, err) @@ -495,8 +497,8 @@ func TestRunnerIntegrationImports(t *testing.T) { func TestVURunContext(t *testing.T) { r1, err := getSimpleRunner("/script.js", ` - export let options = { vus: 10 }; - export default function() { fn(); } + exports.options = { vus: 10 }; + exports.default = function() { fn(); } `) require.NoError(t, err) r1.SetOptions(r1.GetOptions().Apply(lib.Options{Throw: null.BoolFrom(true)})) @@ -547,7 +549,7 @@ func TestVURunInterrupt(t *testing.T) { } r1, err := getSimpleRunner("/script.js", ` - export default function() { while(true) {} } + exports.default = function() { while(true) {} } `) require.NoError(t, err) require.NoError(t, r1.SetOptions(lib.Options{Throw: null.BoolFrom(true)})) @@ -585,7 +587,7 @@ func TestVURunInterruptDoesntPanic(t *testing.T) { } r1, err := getSimpleRunner("/script.js", ` - export default function() { while(true) {} } + exports.default = function() { while(true) {} } `) require.NoError(t, err) require.NoError(t, r1.SetOptions(lib.Options{Throw: null.BoolFrom(true)})) @@ -632,8 +634,8 @@ func TestVURunInterruptDoesntPanic(t *testing.T) { func TestVUIntegrationGroups(t *testing.T) { r1, err := getSimpleRunner("/script.js", ` - import { group } from "k6"; - export default function() { + var group = require("k6").group; + exports.default = function() { fnOuter(); group("my group", function() { fnInner(); @@ -691,10 +693,10 @@ func TestVUIntegrationGroups(t *testing.T) { func TestVUIntegrationMetrics(t *testing.T) { r1, err := getSimpleRunner("/script.js", ` - import { group } from "k6"; - import { Trend } from "k6/metrics"; - let myMetric = new Trend("my_metric"); - export default function() { myMetric.add(5); } + var group = require("k6").group; + var Trend = require("k6/metrics").Trend; + var myMetric = new Trend("my_metric"); + exports.default = function() { myMetric.add(5); } `) require.NoError(t, err) @@ -766,8 +768,8 @@ func TestVUIntegrationInsecureRequests(t *testing.T) { data := data t.Run(name, func(t *testing.T) { r1, err := getSimpleRunner("/script.js", ` - import http from "k6/http"; - export default function() { http.get("https://expired.badssl.com/"); } + var http = require("k6/http");; + exports.default = function() { http.get("https://expired.badssl.com/"); } `) require.NoError(t, err) require.NoError(t, r1.SetOptions(lib.Options{Throw: null.BoolFrom(true)}.Apply(data.opts))) @@ -803,8 +805,8 @@ func TestVUIntegrationInsecureRequests(t *testing.T) { func TestVUIntegrationBlacklistOption(t *testing.T) { r1, err := getSimpleRunner("/script.js", ` - import http from "k6/http"; - export default function() { http.get("http://10.1.2.3/"); } + var http = require("k6/http");; + exports.default = function() { http.get("http://10.1.2.3/"); } `) require.NoError(t, err) @@ -843,14 +845,14 @@ func TestVUIntegrationBlacklistOption(t *testing.T) { func TestVUIntegrationBlacklistScript(t *testing.T) { r1, err := getSimpleRunner("/script.js", ` - import http from "k6/http"; + var http = require("k6/http");; - export let options = { + exports.options = { throw: true, blacklistIPs: ["10.0.0.0/8"], }; - export default function() { http.get("http://10.1.2.3/"); } + exports.default = function() { http.get("http://10.1.2.3/"); } `) if !assert.NoError(t, err) { return @@ -886,12 +888,14 @@ func TestVUIntegrationHosts(t *testing.T) { r1, err := getSimpleRunner("/script.js", tb.Replacer.Replace(` - import { check, fail } from "k6"; - import http from "k6/http"; - export default function() { - let res = http.get("http://test.loadimpact.com:HTTPBIN_PORT/"); + var k6 = require("k6"); + var check = k6.check; + var fail = k6.fail; + var http = require("k6/http");; + exports.default = function() { + var res = http.get("http://test.loadimpact.com:HTTPBIN_PORT/"); check(res, { - "is correct IP": (r) => r.remote_ip === "127.0.0.1" + "is correct IP": function(r) { return r.remote_ip === "127.0.0.1" } }) || fail("failed to override dns"); } `)) @@ -972,8 +976,8 @@ func TestVUIntegrationTLSConfig(t *testing.T) { data := data t.Run(name, func(t *testing.T) { r1, err := getSimpleRunner("/script.js", ` - import http from "k6/http"; - export default function() { http.get("https://sha256.badssl.com/"); } + var http = require("k6/http");; + exports.default = function() { http.get("https://sha256.badssl.com/"); } `) if !assert.NoError(t, err) { return @@ -1013,7 +1017,7 @@ func TestVUIntegrationTLSConfig(t *testing.T) { func TestVUIntegrationOpenFunctionError(t *testing.T) { r, err := getSimpleRunner("/script.js", ` - export default function() { open("/tmp/foo") } + exports.default = function() { open("/tmp/foo") } `) assert.NoError(t, err) @@ -1032,16 +1036,16 @@ func TestVUIntegrationCookiesReset(t *testing.T) { defer tb.Cleanup() r1, err := getSimpleRunner("/script.js", tb.Replacer.Replace(` - import http from "k6/http"; - export default function() { - let url = "HTTPBIN_URL"; - let preRes = http.get(url + "/cookies"); + var http = require("k6/http");; + exports.default = function() { + var url = "HTTPBIN_URL"; + var preRes = http.get(url + "/cookies"); if (preRes.status != 200) { throw new Error("wrong status (pre): " + preRes.status); } if (preRes.json().k1 || preRes.json().k2) { throw new Error("cookies persisted: " + preRes.body); } - let res = http.get(url + "/cookies/set?k2=v2&k1=v1"); + var res = http.get(url + "/cookies/set?k2=v2&k1=v1"); if (res.status != 200) { throw new Error("wrong status: " + res.status) } if (res.json().k1 != "v1" || res.json().k2 != "v2") { throw new Error("wrong cookies: " + res.body); @@ -1086,11 +1090,11 @@ func TestVUIntegrationCookiesNoReset(t *testing.T) { defer tb.Cleanup() r1, err := getSimpleRunner("/script.js", tb.Replacer.Replace(` - import http from "k6/http"; - export default function() { - let url = "HTTPBIN_URL"; + var http = require("k6/http");; + exports.default = function() { + var url = "HTTPBIN_URL"; if (__ITER == 0) { - let res = http.get(url + "/cookies/set?k2=v2&k1=v1"); + var res = http.get(url + "/cookies/set?k2=v2&k1=v1"); if (res.status != 200) { throw new Error("wrong status: " + res.status) } if (res.json().k1 != "v1" || res.json().k2 != "v2") { throw new Error("wrong cookies: " + res.body); @@ -1098,7 +1102,7 @@ func TestVUIntegrationCookiesNoReset(t *testing.T) { } if (__ITER == 1) { - let res = http.get(url + "/cookies"); + var res = http.get(url + "/cookies"); if (res.status != 200) { throw new Error("wrong status (pre): " + res.status); } if (res.json().k1 != "v1" || res.json().k2 != "v2") { throw new Error("wrong cookies: " + res.body); @@ -1144,7 +1148,7 @@ func TestVUIntegrationCookiesNoReset(t *testing.T) { func TestVUIntegrationVUID(t *testing.T) { r1, err := getSimpleRunner("/script.js", ` - export default function() { + exports.default = function() { if (__VU != 1234) { throw new Error("wrong __VU: " + __VU); } }`, ) @@ -1241,8 +1245,8 @@ func TestVUIntegrationClientCerts(t *testing.T) { go func() { _ = srv.Serve(listener) }() r1, err := getSimpleRunner("/script.js", fmt.Sprintf(` - import http from "k6/http"; - export default function() { http.get("https://%s")} + var http = require("k6/http");; + exports.default = function() { http.get("https://%s")} `, listener.Addr().String())) if !assert.NoError(t, err) { return @@ -1330,10 +1334,12 @@ func TestHTTPRequestInInitContext(t *testing.T) { defer tb.Cleanup() _, err := getSimpleRunner("/script.js", tb.Replacer.Replace(` - import { check, fail } from "k6"; - import http from "k6/http"; - let res = http.get("HTTPBIN_URL/"); - export default function() { + var k6 = require("k6"); + var check = k6.check; + var fail = k6.fail; + var http = require("k6/http");; + var res = http.get("HTTPBIN_URL/"); + exports.default = function() { console.log(test); } `)) @@ -1349,42 +1355,42 @@ func TestInitContextForbidden(t *testing.T) { table := [...][3]string{ { "http.request", - `import http from "k6/http"; - let res = http.get("HTTPBIN_URL"); - export default function() { console.log("p"); }`, + `var http = require("k6/http");; + var res = http.get("HTTPBIN_URL"); + exports.default = function() { console.log("p"); }`, k6http.ErrHTTPForbiddenInInitContext.Error(), }, { "http.batch", - `import http from "k6/http"; - let res = http.batch("HTTPBIN_URL/something", "HTTPBIN_URL/else"); - export default function() { console.log("p"); }`, + `var http = require("k6/http");; + var res = http.batch("HTTPBIN_URL/something", "HTTPBIN_URL/else"); + exports.default = function() { console.log("p"); }`, k6http.ErrBatchForbiddenInInitContext.Error(), }, { "http.cookieJar", - `import http from "k6/http"; - let jar = http.cookieJar(); - export default function() { console.log("p"); }`, + `var http = require("k6/http");; + var jar = http.cookieJar(); + exports.default = function() { console.log("p"); }`, k6http.ErrJarForbiddenInInitContext.Error(), }, { "check", - `import { check } from "k6"; - check("test", {'is test': (test) => test == "test"}) - export default function() { console.log("p"); }`, + `var check = require("k6").check; + check("test", {'is test': function(test) { return test == "test"}}) + exports.default = function() { console.log("p"); }`, k6.ErrCheckInInitContext.Error(), }, { "group", - `import { group } from "k6"; + `var group = require("k6").group; group("group1", function () { console.log("group1");}) - export default function() { console.log("p"); }`, + exports.default = function() { console.log("p"); }`, k6.ErrGroupInInitContext.Error(), }, { "ws", - `import ws from "k6/ws"; + `var ws = require("k6/ws"); var url = "ws://echo.websocket.org"; var params = { "tags": { "my_tag": "hello" } }; var response = ws.connect(url, params, function (socket) { @@ -1393,15 +1399,15 @@ func TestInitContextForbidden(t *testing.T) { }) }); - export default function() { console.log("p"); }`, + exports.default = function() { console.log("p"); }`, ws.ErrWSInInitContext.Error(), }, { "metric", - `import { Counter } from "k6/metrics"; - let counter = Counter("myCounter"); + `var Counter = require("k6/metrics").Counter; + var counter = Counter("myCounter"); counter.add(1); - export default function() { console.log("p"); }`, + exports.default = function() { console.log("p"); }`, k6metrics.ErrMetricsAddInInitContext.Error(), }, } @@ -1428,12 +1434,12 @@ func TestArchiveRunningIntegrity(t *testing.T) { fs := afero.NewMemMapFs() data := tb.Replacer.Replace(` - let fput = open("/home/somebody/test.json"); - export let options = { setupTimeout: "10s", teardownTimeout: "10s" }; - export function setup() { + var fput = open("/home/somebody/test.json"); + exports.options = { setupTimeout: "10s", teardownTimeout: "10s" }; + exports.setup = function () { return JSON.parse(fput); } - export default function(data) { + exports.default = function(data) { if (data != 42) { throw new Error("incorrect answer " + data); } @@ -1477,9 +1483,8 @@ func TestArchiveNotPanicking(t *testing.T) { fs := afero.NewMemMapFs() require.NoError(t, afero.WriteFile(fs, "/non/existent", []byte(`42`), os.ModePerm)) r1, err := getSimpleRunner("/script.js", tb.Replacer.Replace(` - let fput = open("/non/existent"); - export default function(data) { - } + var fput = open("/non/existent"); + exports.default = function(data) {} `), fs) require.NoError(t, err) @@ -1497,25 +1502,25 @@ func TestStuffNotPanicking(t *testing.T) { defer tb.Cleanup() r, err := getSimpleRunner("/script.js", tb.Replacer.Replace(` - import http from "k6/http"; - import ws from "k6/ws"; - import { group } from "k6"; - import { parseHTML } from "k6/html"; - - export let options = { iterations: 1, vus: 1, vusMax: 1 }; - - export default function() { - const doc = parseHTML(http.get("HTTPBIN_URL/html").body); - - let testCases = [ - () => group(), - () => group("test"), - () => group("test", "wat"), - () => doc.find('p').each(), - () => doc.find('p').each("wat"), - () => doc.find('p').map(), - () => doc.find('p').map("wat"), - () => ws.connect("WSBIN_URL/ws-echo"), + var http = require("k6/http"); + var ws = require("k6/ws"); + var group = require("k6").group; + var parseHTML = require("k6/html").parseHTML; + + exports.options = { iterations: 1, vus: 1, vusMax: 1 }; + + exports.default = function() { + var doc = parseHTML(http.get("HTTPBIN_URL/html").body); + + var testCases = [ + function() { return group()}, + function() { return group("test")}, + function() { return group("test", "wat")}, + function() { return doc.find('p').each()}, + function() { return doc.find('p').each("wat")}, + function() { return doc.find('p').map()}, + function() { return doc.find('p').map("wat")}, + function() { return ws.connect("WSBIN_URL/ws-echo")}, ]; testCases.forEach(function(fn, idx) {