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

test: use blocks instead of async IIFE #24989

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 38 additions & 38 deletions test/parallel/test-stream-readable-async-iterators.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ async function tests() {
AsyncIteratorPrototype);
}

await (async function() {
{
const readable = new Readable({ objectMode: true, read() {} });
readable.push(0);
readable.push(1);
Expand All @@ -25,9 +25,9 @@ async function tests() {
for await (const d of iter) {
assert.strictEqual(d, 1);
}
})();
}

await (async function() {
{
console.log('read without for..await');
const max = 5;
const readable = new Readable({
Expand Down Expand Up @@ -55,9 +55,9 @@ async function tests() {

const last = await iter.next();
assert.strictEqual(last.done, true);
})();
}

await (async function() {
{
console.log('read without for..await deferred');
const readable = new Readable({
objectMode: true,
Expand Down Expand Up @@ -95,9 +95,9 @@ async function tests() {

const last = await iter.next();
assert.strictEqual(last.done, true);
})();
}

await (async function() {
{
console.log('read without for..await with errors');
const max = 3;
const readable = new Readable({
Expand Down Expand Up @@ -133,9 +133,9 @@ async function tests() {
});

readable.destroy(new Error('kaboom'));
})();
}

await (async function() {
{
console.log('call next() after error');
const readable = new Readable({
read() {}
Expand All @@ -145,9 +145,9 @@ async function tests() {
const err = new Error('kaboom');
readable.destroy(new Error('kaboom'));
await assert.rejects(iterator.next.bind(iterator), err);
})();
}

await (async function() {
{
console.log('read object mode');
const max = 42;
let readed = 0;
Expand All @@ -168,9 +168,9 @@ async function tests() {
}

assert.strictEqual(readed, received);
})();
}

await (async function() {
{
console.log('destroy sync');
const readable = new Readable({
objectMode: true,
Expand All @@ -187,9 +187,9 @@ async function tests() {
err = e;
}
assert.strictEqual(err.message, 'kaboom from read');
})();
}

await (async function() {
{
console.log('destroy async');
const readable = new Readable({
objectMode: true,
Expand Down Expand Up @@ -219,9 +219,9 @@ async function tests() {

assert.strictEqual(err.message, 'kaboom');
assert.strictEqual(received, 1);
})();
}

await (async function() {
{
console.log('destroyed by throw');
const readable = new Readable({
objectMode: true,
Expand All @@ -242,9 +242,9 @@ async function tests() {

assert.strictEqual(err.message, 'kaboom');
assert.strictEqual(readable.destroyed, true);
})();
}

await (async function() {
{
console.log('destroyed sync after push');
const readable = new Readable({
objectMode: true,
Expand All @@ -268,9 +268,9 @@ async function tests() {

assert.strictEqual(err.message, 'kaboom');
assert.strictEqual(received, 1);
})();
}

await (async function() {
{
console.log('push async');
const max = 42;
let readed = 0;
Expand All @@ -293,9 +293,9 @@ async function tests() {
}

assert.strictEqual(readed, received);
})();
}

await (async function() {
{
console.log('push binary async');
const max = 42;
let readed = 0;
Expand Down Expand Up @@ -323,9 +323,9 @@ async function tests() {
}

assert.strictEqual(data, expected);
})();
}

await (async function() {
{
console.log('.next() on destroyed stream');
const readable = new Readable({
read() {
Expand All @@ -337,9 +337,9 @@ async function tests() {

const { done } = await readable[Symbol.asyncIterator]().next();
assert.strictEqual(done, true);
})();
}

await (async function() {
{
console.log('.next() on pipelined stream');
const readable = new Readable({
read() {
Expand All @@ -358,9 +358,9 @@ async function tests() {
} catch (e) {
assert.strictEqual(e, err);
}
})();
}

await (async () => {
{
console.log('iterating on an ended stream completes');
const r = new Readable({
objectMode: true,
Expand All @@ -376,9 +376,9 @@ async function tests() {
// eslint-disable-next-line no-unused-vars
for await (const b of r) {
}
})();
}

await (async () => {
{
console.log('destroy mid-stream does not error');
const r = new Readable({
objectMode: true,
Expand All @@ -392,9 +392,9 @@ async function tests() {
for await (const a of r) {
r.destroy(null);
}
})();
}

await (async () => {
{
console.log('all next promises must be resolved on end');
const r = new Readable({
objectMode: true,
Expand All @@ -408,9 +408,9 @@ async function tests() {
r.push(null);
assert.deepStrictEqual(await c, { done: true, value: undefined });
assert.deepStrictEqual(await d, { done: true, value: undefined });
})();
}

await (async () => {
{
console.log('all next promises must be resolved on destroy');
const r = new Readable({
objectMode: true,
Expand All @@ -424,9 +424,9 @@ async function tests() {
r.destroy();
assert.deepStrictEqual(await c, { done: true, value: undefined });
assert.deepStrictEqual(await d, { done: true, value: undefined });
})();
}

await (async () => {
{
console.log('all next promises must be resolved on destroy with error');
const r = new Readable({
objectMode: true,
Expand Down Expand Up @@ -457,7 +457,7 @@ async function tests() {
}
assert.strictEqual(e, err);
})()]);
})();
}
}

// to avoid missing some tests if a promise does not resolve
Expand Down