Skip to content

Commit

Permalink
Enable console in init context fix #951
Browse files Browse the repository at this point in the history
This commit does the bare minimal to enable useage of console init
context. Unfortunetely this means that redirection to file is currently
not supported in init context.
  • Loading branch information
mstoykov committed Aug 26, 2019
1 parent c202415 commit 570fc36
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
1 change: 1 addition & 0 deletions js/bundle.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ func (b *Bundle) instantiate(rt *goja.Runtime, init *InitContext) error {
rt.Set("module", module)

rt.Set("__ENV", b.Env)
rt.Set("console", common.Bind(rt, newConsole(), init.ctxPtr))

*init.ctxPtr = common.WithRuntime(context.Background(), rt)
unbindInit := common.BindToGlobal(rt, common.Bind(rt, init, init.ctxPtr))
Expand Down
22 changes: 22 additions & 0 deletions js/runner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,28 @@ func TestSetupDataNoSetup(t *testing.T) {
};`)
}

func TestConsoleInInitContext(t *testing.T) {
r1, err := getSimpleRunner("/script.js", `
console.log("1");
export default function(data) {
};
`)
require.NoError(t, err)

testdata := map[string]*Runner{"Source": r1}
for name, r := range testdata {
r := r
t.Run(name, func(t *testing.T) {
samples := make(chan stats.SampleContainer, 100)
vu, err := r.NewVU(samples)
if assert.NoError(t, err) {
err := vu.RunOnce(context.Background())
assert.NoError(t, err)
}
})
}
}

func TestSetupDataNoReturn(t *testing.T) {
testSetupDataHelper(t, `
export let options = { setupTimeout: "1s", teardownTimeout: "1s" };
Expand Down

0 comments on commit 570fc36

Please sign in to comment.