-
Notifications
You must be signed in to change notification settings - Fork 1
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
fixup: simplify #12
base: transform-by
Are you sure you want to change the base?
fixup: simplify #12
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,7 @@ const { Readable, Transform } = require('stream'); | |
const { strictEqual } = require('assert'); | ||
|
||
async function transformBy() { | ||
const readable = Readable.from('test'); | ||
const readable = Readable.from('test'.split('')); | ||
async function * mapper(source) { | ||
for await (const chunk of source) { | ||
yield chunk.toUpperCase(); | ||
|
@@ -21,7 +21,7 @@ async function transformBy() { | |
} | ||
|
||
async function transformByFuncReturnsObjectWithSymbolAsyncIterator() { | ||
const readable = Readable.from('test'); | ||
const readable = Readable.from('test'.split('')); | ||
const mapper = (source) => ({ | ||
[Symbol.asyncIterator]() { | ||
return { | ||
|
@@ -41,26 +41,6 @@ async function transformByFuncReturnsObjectWithSymbolAsyncIterator() { | |
} | ||
} | ||
|
||
async function | ||
transformByObjReturnedWSymbolAsyncIteratorWithNonPromiseReturningNext() { | ||
const mapper = (source) => ({ | ||
[Symbol.asyncIterator]() { | ||
return { | ||
next() { | ||
const { done, value } = source.next(); | ||
return { done, value: value ? value.toUpperCase() : value }; | ||
} | ||
}; | ||
} | ||
}); | ||
|
||
expectsError(() => Transform.by(mapper), { | ||
message: 'asyncGeneratorFn must return an async iterable', | ||
code: 'ERR_ARG_RETURN_VALUE_NOT_ASYNC_ITERABLE', | ||
type: TypeError | ||
}); | ||
} | ||
|
||
async function transformByObjReturnedWSymbolAsyncIteratorWithNoNext() { | ||
const mapper = () => ({ | ||
[Symbol.asyncIterator]() { | ||
|
@@ -69,8 +49,7 @@ async function transformByObjReturnedWSymbolAsyncIteratorWithNoNext() { | |
}); | ||
|
||
expectsError(() => Transform.by(mapper), { | ||
message: 'asyncGeneratorFn must return an async iterable', | ||
code: 'ERR_ARG_RETURN_VALUE_NOT_ASYNC_ITERABLE', | ||
code: 'ERR_INVALID_ARG_TYPE', | ||
type: TypeError | ||
}); | ||
} | ||
|
@@ -81,8 +60,7 @@ async function transformByObjReturnedWSymbolAsyncIteratorThatIsNotFunction() { | |
}); | ||
|
||
expectsError(() => Transform.by(mapper), { | ||
message: 'asyncGeneratorFn must return an async iterable', | ||
code: 'ERR_ARG_RETURN_VALUE_NOT_ASYNC_ITERABLE', | ||
code: 'ERR_INVALID_ARG_TYPE', | ||
type: TypeError | ||
}); | ||
} | ||
|
@@ -91,14 +69,13 @@ async function transformByFuncReturnsObjectWithoutSymbolAsyncIterator() { | |
const mapper = () => ({}); | ||
|
||
expectsError(() => Transform.by(mapper), { | ||
message: 'asyncGeneratorFn must return an async iterable', | ||
code: 'ERR_ARG_RETURN_VALUE_NOT_ASYNC_ITERABLE', | ||
code: 'ERR_INVALID_ARG_TYPE', | ||
type: TypeError | ||
}); | ||
} | ||
|
||
async function transformByEncoding() { | ||
const readable = Readable.from('test'); | ||
const readable = Readable.from('test'.split('')); | ||
async function * mapper(source) { | ||
for await (const chunk of source) { | ||
strictEqual(source.encoding, 'ascii'); | ||
|
@@ -116,7 +93,7 @@ async function transformByEncoding() { | |
} | ||
|
||
async function transformBySourceIteratorCompletes() { | ||
const readable = Readable.from('test'); | ||
const readable = Readable.from('test'.split('')); | ||
const mustReach = mustCall(); | ||
async function * mapper(source) { | ||
for await (const chunk of source) { | ||
|
@@ -134,7 +111,7 @@ async function transformBySourceIteratorCompletes() { | |
} | ||
|
||
async function transformByYieldPlusReturn() { | ||
const readable = Readable.from('test'); | ||
const readable = Readable.from('test'.split('')); | ||
async function * mapper(source) { | ||
for await (const chunk of source) { | ||
yield chunk.toUpperCase(); | ||
|
@@ -151,7 +128,7 @@ async function transformByYieldPlusReturn() { | |
} | ||
|
||
async function transformByReturnEndsStream() { | ||
const readable = Readable.from('test'); | ||
const readable = Readable.from('test'.split('')); | ||
async function * mapper(source) { | ||
for await (const chunk of source) { | ||
yield chunk.toUpperCase(); | ||
|
@@ -170,7 +147,7 @@ async function transformByReturnEndsStream() { | |
} | ||
|
||
async function transformByOnData() { | ||
const readable = Readable.from('test'); | ||
const readable = Readable.from('test'.split('')); | ||
async function * mapper(source) { | ||
for await (const chunk of source) { | ||
yield chunk.toUpperCase(); | ||
|
@@ -191,7 +168,7 @@ async function transformByOnData() { | |
} | ||
|
||
async function transformByOnDataNonObject() { | ||
const readable = Readable.from('test', { objectMode: false }); | ||
const readable = Readable.from('test'.split(''), { objectMode: false }); | ||
async function * mapper(source) { | ||
for await (const chunk of source) { | ||
yield chunk.toString().toUpperCase(); | ||
|
@@ -212,7 +189,7 @@ async function transformByOnDataNonObject() { | |
} | ||
|
||
async function transformByOnErrorAndDestroyed() { | ||
const stream = Readable.from('test').pipe(Transform.by( | ||
const stream = Readable.from('test'.split('')).pipe(Transform.by( | ||
async function * mapper(source) { | ||
for await (const chunk of source) { | ||
if (chunk === 'e') throw new Error('kaboom'); | ||
|
@@ -230,7 +207,7 @@ async function transformByOnErrorAndDestroyed() { | |
} | ||
|
||
async function transformByErrorTryCatchAndDestroyed() { | ||
const stream = Readable.from('test').pipe(Transform.by( | ||
const stream = Readable.from('test'.split('')).pipe(Transform.by( | ||
async function * mapper(source) { | ||
for await (const chunk of source) { | ||
if (chunk === 'e') throw new Error('kaboom'); | ||
|
@@ -250,7 +227,7 @@ async function transformByErrorTryCatchAndDestroyed() { | |
} | ||
|
||
async function transformByOnErrorAndTryCatchAndDestroyed() { | ||
const stream = Readable.from('test').pipe(Transform.by( | ||
const stream = Readable.from('test'.split('')).pipe(Transform.by( | ||
async function * mapper(source) { | ||
for await (const chunk of source) { | ||
if (chunk === 'e') throw new Error('kaboom'); | ||
|
@@ -286,17 +263,17 @@ async function transformByThrowPriorToForAwait() { | |
strictEqual(err.message, 'kaboom'); | ||
})); | ||
|
||
read.pipe(stream); | ||
read.pipe(stream).resume(); | ||
} | ||
|
||
Promise.all([ | ||
transformBy(), | ||
transformByFuncReturnsObjectWithSymbolAsyncIterator(), | ||
transformByObjReturnedWSymbolAsyncIteratorWithNonPromiseReturningNext(), | ||
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. @davidmarkclements: I don't think this test is needed. Returning a non promise is fine? |
||
transformByObjReturnedWSymbolAsyncIteratorWithNoNext(), | ||
transformByObjReturnedWSymbolAsyncIteratorThatIsNotFunction(), | ||
transformByFuncReturnsObjectWithoutSymbolAsyncIterator(), | ||
transformByEncoding(), | ||
// NOTE: This doesn't make sense for iterable? Is it consistent with Readable.from? | ||
// transformByEncoding(), | ||
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. I'm not sure what this test, tests for? 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. in order to have an analogue to 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. I don't think this is taken into account in |
||
transformBySourceIteratorCompletes(), | ||
transformByYieldPlusReturn(), | ||
transformByReturnEndsStream(), | ||
|
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.
@davidmarkclements Moved invalid arg check to
Readable.from
.