Skip to content
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

[WIP] ReadableStream @@asyncIterator tests #13362

Closed

Conversation

devsnek
Copy link

@devsnek devsnek commented Oct 4, 2018

@ricea
Copy link
Contributor

ricea commented Oct 5, 2018

If you run node generate-test-wrappers.js readable-streams/async-iterator.js in the parent directory it will generate the rest of the wrapper files for you.

Copy link
Contributor

@ricea ricea left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great overall. Just a few minor comments.


try {
for await (const chunk of s) {}
assert(false);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should use assert_unreached() here and in other places where you have assert(false).


promise_test(async () => {
const s = new ReadableStream({
start(s) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using the same name for the start() parameter and ReadableStream object is confusion. I suggest using c or controller for the paramter.

}
});

await (async () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I find this immediately-executed-async-function structure hard to understand. Is there a reason why a simple try ... catch wouldn't work?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

testing return. I suppose it can be reworked a little bit though.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably if you just split the creation of the function from the execution of the function it will be enough to make it less confusing.


promise_test(async () => {
{
const s = new ReadableStream({});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick: you don't actually need the {} here.

}, '@@asyncIterator() method is === to getIterator() method');

promise_test(async () => {
const s = recordingReadableStream({
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test uses recordingReadableStream() but never looks at `s.events'.

},
});
const it = s.getIterator();
assert_throws(() => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The first argument to assert_throws() needs to match the exception. In this case new TypeError() should be the first argument.

}
})().catch(() => 0);

assert_equals(s.locked, preventCancel);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's easier to debug assert failures if they have a description. In this case, I'd use something like `s.locked should equal preventCancel when type = ${type} and preventCancel = ${preventCancel}`.

In this case, the assertion is wrong because s.locked is always false after the loop terminates. The easiest way to detect if preventCancel worked is to look at s.events. Something like this should work:

if (preventCancel) {
  assert_array_equals(s.events, [], `cancel() should not be called when type = '${type}' and preventCancel is true`);
} else {
  assert_array_equals(s.events, ['cancel', undefined], `cancel() should be called when type = '${type}' and preventCancel is false`);
}

@ricea
Copy link
Contributor

ricea commented Oct 5, 2018

I uploaded some brand-checks.js tests to this branch. I hope they don't cause any conflicts.

@devsnek
Copy link
Author

devsnek commented Oct 7, 2018

interestingly, the assert_equals(Object.getPrototypeOf(next), Object.prototype); test is failing with the reference implementation.

Copy link
Contributor

@ricea ricea left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

interestingly, the assert_equals(Object.getPrototypeOf(next), Object.prototype); test is failing with the reference implementation.

I think this is a result of the way the wpt-runner works. ReadableStream is compiled with a different global, so its Object is different from the Object of the page.

Unfortunately, this currently will mean including this check will prevent any further changes to the streams standard from landing. But maybe we should do that and then fix it over there.

}
});

await (async () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably if you just split the creation of the function from the execution of the function it will be enough to make it less confusing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants