-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Support to init a ReadableStream from a io.Reader #3740
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
541c814
Support to init a ReadableStream from a io.Reader
joanlopez b7ee559
Merge remote-tracking branch 'upstream/master' into readable-stream-i…
joanlopez 9cbf451
streams.NewReadableStreamForReader test
joanlopez b578b7e
Fix linter complains
joanlopez 28a6b50
Apply suggestions from code review
joanlopez 3bf5ccf
Merge remote-tracking branch 'upstream/master' into readable-stream-i…
joanlopez 3b681e6
Replace goja => sobek
joanlopez File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package streams | ||
|
||
import ( | ||
"bytes" | ||
"testing" | ||
|
||
"github.com/grafana/sobek" | ||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
"go.k6.io/k6/js/modulestest" | ||
) | ||
|
||
func TestNewReadableStreamForReader(t *testing.T) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same |
||
t.Parallel() | ||
|
||
// The value to be streamed. | ||
exp := "Hello, World!" | ||
|
||
// We initialize the runtime, with the ReadableStream(rs) accessible in JS. | ||
r := modulestest.NewRuntime(t) | ||
rs := NewReadableStreamFromReader(r.VU, bytes.NewReader([]byte(exp))) | ||
require.NoError(t, r.VU.Runtime().Set("rs", rs)) | ||
|
||
// Then, we run some JS code that reads from the ReadableStream(rs). | ||
var ret sobek.Value | ||
err := r.EventLoop.Start(func() (err error) { | ||
ret, err = r.VU.Runtime().RunString(`(async () => { | ||
const reader = rs.getReader(); | ||
const {value} = await reader.read(); | ||
return value; | ||
})()`) | ||
return err | ||
}) | ||
assert.NoError(t, err) | ||
|
||
// Finally, we expect the returned promise to resolve | ||
// to the expected value (the one we streamed). | ||
p, ok := ret.Export().(*sobek.Promise) | ||
require.True(t, ok) | ||
assert.Equal(t, exp, p.Result().String()) | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
It seems we miss a replacement here
s/For/From/