-
Notifications
You must be signed in to change notification settings - Fork 230
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Lazily require abort-controller (#478)
* Lazily require abort-controller, since it throws when it has been bundled, then loaded in node * Make changes to build script and re-run them. Only did 18.0.0 to minimize the changeset.
- Loading branch information
Showing
17 changed files
with
315 additions
and
282 deletions.
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
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
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
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 |
---|---|---|
@@ -1,17 +1,5 @@ | ||
import fixtures from './fixtures.js'; | ||
import fixtures from './fixtures.js' | ||
|
||
const { | ||
fixturesDir, | ||
path, | ||
fileURL, | ||
readSync, | ||
readKey, | ||
} = fixtures; | ||
const { fixturesDir, path, fileURL, readSync, readKey } = fixtures | ||
|
||
export { | ||
fixturesDir, | ||
path, | ||
fileURL, | ||
readSync, | ||
readKey, | ||
}; | ||
export { fixturesDir, path, fileURL, readSync, readKey } |
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
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 |
---|---|---|
@@ -1,64 +1,82 @@ | ||
import '../common/index.mjs'; | ||
import { Readable }from '../../lib/ours/index.js'; | ||
import { deepStrictEqual, rejects, throws } from 'assert'; | ||
import tap from 'tap'; | ||
import '../common/index.mjs' | ||
import { Readable } from '../../lib/ours/index.js' | ||
import { deepStrictEqual, rejects, throws } from 'assert' | ||
import tap from 'tap' | ||
|
||
{ | ||
// asIndexedPairs with a synchronous stream | ||
const pairs = await Readable.from([1, 2, 3]).asIndexedPairs().toArray(); | ||
deepStrictEqual(pairs, [[0, 1], [1, 2], [2, 3]]); | ||
const empty = await Readable.from([]).asIndexedPairs().toArray(); | ||
deepStrictEqual(empty, []); | ||
const pairs = await Readable.from([1, 2, 3]).asIndexedPairs().toArray() | ||
deepStrictEqual(pairs, [ | ||
[0, 1], | ||
[1, 2], | ||
[2, 3] | ||
]) | ||
const empty = await Readable.from([]).asIndexedPairs().toArray() | ||
deepStrictEqual(empty, []) | ||
} | ||
|
||
{ | ||
// asIndexedPairs works an asynchronous streams | ||
const asyncFrom = (...args) => Readable.from(...args).map(async (x) => x); | ||
const pairs = await asyncFrom([1, 2, 3]).asIndexedPairs().toArray(); | ||
deepStrictEqual(pairs, [[0, 1], [1, 2], [2, 3]]); | ||
const empty = await asyncFrom([]).asIndexedPairs().toArray(); | ||
deepStrictEqual(empty, []); | ||
const asyncFrom = (...args) => Readable.from(...args).map(async (x) => x) | ||
const pairs = await asyncFrom([1, 2, 3]).asIndexedPairs().toArray() | ||
deepStrictEqual(pairs, [ | ||
[0, 1], | ||
[1, 2], | ||
[2, 3] | ||
]) | ||
const empty = await asyncFrom([]).asIndexedPairs().toArray() | ||
deepStrictEqual(empty, []) | ||
} | ||
|
||
{ | ||
// Does not enumerate an infinite stream | ||
const infinite = () => Readable.from(async function* () { | ||
while (true) yield 1; | ||
}()); | ||
const pairs = await infinite().asIndexedPairs().take(3).toArray(); | ||
deepStrictEqual(pairs, [[0, 1], [1, 1], [2, 1]]); | ||
const empty = await infinite().asIndexedPairs().take(0).toArray(); | ||
deepStrictEqual(empty, []); | ||
const infinite = () => | ||
Readable.from( | ||
(async function* () { | ||
while (true) yield 1 | ||
})() | ||
) | ||
const pairs = await infinite().asIndexedPairs().take(3).toArray() | ||
deepStrictEqual(pairs, [ | ||
[0, 1], | ||
[1, 1], | ||
[2, 1] | ||
]) | ||
const empty = await infinite().asIndexedPairs().take(0).toArray() | ||
deepStrictEqual(empty, []) | ||
} | ||
|
||
{ | ||
// AbortSignal | ||
await rejects(async () => { | ||
const ac = new AbortController(); | ||
const { signal } = ac; | ||
const p = Readable.from([1, 2, 3]).asIndexedPairs({ signal }).toArray(); | ||
ac.abort(); | ||
await p; | ||
}, { name: 'AbortError' }); | ||
await rejects( | ||
async () => { | ||
const ac = new AbortController() | ||
const { signal } = ac | ||
const p = Readable.from([1, 2, 3]).asIndexedPairs({ signal }).toArray() | ||
ac.abort() | ||
await p | ||
}, | ||
{ name: 'AbortError' } | ||
) | ||
|
||
await rejects(async () => { | ||
const signal = AbortSignal.abort(); | ||
await Readable.from([1, 2, 3]).asIndexedPairs({ signal }).toArray(); | ||
}, /AbortError/); | ||
const signal = AbortSignal.abort() | ||
await Readable.from([1, 2, 3]).asIndexedPairs({ signal }).toArray() | ||
}, /AbortError/) | ||
} | ||
|
||
{ | ||
// Error cases | ||
throws(() => Readable.from([1]).asIndexedPairs(1), /ERR_INVALID_ARG_TYPE/); | ||
throws(() => Readable.from([1]).asIndexedPairs({ signal: true }), /ERR_INVALID_ARG_TYPE/); | ||
throws(() => Readable.from([1]).asIndexedPairs(1), /ERR_INVALID_ARG_TYPE/) | ||
throws(() => Readable.from([1]).asIndexedPairs({ signal: true }), /ERR_INVALID_ARG_TYPE/) | ||
} | ||
|
||
/* replacement start */ | ||
process.on('beforeExit', (code) => { | ||
if(code === 0) { | ||
tap.pass('test succeeded'); | ||
} else { | ||
tap.fail(`test failed - exited code ${code}`); | ||
} | ||
}); | ||
/* replacement end */ | ||
/* replacement start */ | ||
process.on('beforeExit', (code) => { | ||
if (code === 0) { | ||
tap.pass('test succeeded') | ||
} else { | ||
tap.fail(`test failed - exited code ${code}`) | ||
} | ||
}) | ||
/* replacement end */ |
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
Oops, something went wrong.