New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor js modules system in js/modules package and use it #2991
Conversation
Codecov Report
@@ Coverage Diff @@
## master #2991 +/- ##
==========================================
- Coverage 75.20% 73.52% -1.69%
==========================================
Files 236 239 +3
Lines 17722 18244 +522
==========================================
+ Hits 13328 13414 +86
- Misses 3536 3959 +423
- Partials 858 871 +13
Flags with carried forward coverage won't be shown. Click here to find out more.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know all of the subtle details here, nor do I fully grok the desired end state yet, but this change LGTM on its own.
bae7d2b
to
6680534
Compare
6680534
to
7ed9300
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like the refactor, but don't have the full context of why this is needed, besides being neater (which is not a reason to not do it).
I just left minor suggestions and questions, and mostly typo fixes.
m := new(RootModule).NewModuleInstance(ts.VU) | ||
|
||
rt := ts.VU.Runtime() | ||
require.NoError(t, rt.Set("instrumentHTTP", m.Exports().Named["instrumentHTTP"])) | ||
|
||
export := http.New().NewModuleInstance(ts.VU).Exports().Default | ||
require.NoError(t, rt.Set("require", func(module string) *goja.Object { | ||
require.Equal(t, "k6/http", module) | ||
return rt.ToValue(export).ToObject(rt) | ||
})) | ||
err := ts.SetupModuleSystem(map[string]interface{}{ | ||
"k6/http": http.New(), | ||
"k6/experimental/tracing": new(RootModule), | ||
}, nil, compiler.New(ts.VU.InitEnvField.Logger)) | ||
require.NoError(t, err) | ||
|
||
_, err = ts.VU.Runtime().RunString("var instrumentHTTP = require('k6/experimental/tracing').instrumentHTTP") | ||
require.NoError(t, err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice, much cleaner 👍
e9a1e2f
to
51ee021
Compare
This is mostly a stepping stone to let it be used in tests but also to make the js package smaller
This is the main place where the module system being available and working the same in tests as it does when k6 runs is really important for the test itself.
Sorry @olegbespalov it take me a while to rebase and squash the fixes in the correct commits as you can see in https://github.com/grafana/k6/compare/e9a1e2f4ec5f0150b7908d637d1eb24f3d4f61e7..51ee0214bbfe7d8b00664ce776ed917aa804eeca I also forcepushed to rebase on master to fix the go-tip tests 😬 |
51ee021
to
9392a59
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚀
This is mostly a stepping stone to let it be used in tests but also to make the js package smaller.
This also has a separate commit that uses it in
k6/experimental/tracing
where this actually matters.