Skip to content

Commit

Permalink
optimize js package test by using compatibility mode base by default
Browse files Browse the repository at this point in the history
  • Loading branch information
mstoykov committed Apr 30, 2020
1 parent 284d3e3 commit d3f563a
Show file tree
Hide file tree
Showing 3 changed files with 141 additions and 135 deletions.
6 changes: 3 additions & 3 deletions js/console_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
17 changes: 9 additions & 8 deletions js/module_loading_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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}))
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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));
}
Expand Down
Loading

0 comments on commit d3f563a

Please sign in to comment.