mirror of
https://github.com/denoland/deno.git
synced 2024-12-12 18:42:18 -05:00
6915a9b7a7
This PR adds the remaining ~650 Node.js compat test cases from std/node. Among these 650 cases, about 130 cases are now failing. These failing cases are prefixed with `TODO:` in `tests/node_compat/config.json`. These will be addressed in later PRs.
60 lines
1.9 KiB
JavaScript
60 lines
1.9 KiB
JavaScript
// deno-fmt-ignore-file
|
|
// deno-lint-ignore-file
|
|
|
|
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
|
|
// Taken from Node 18.12.1
|
|
// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually
|
|
|
|
import '../common/index.mjs';
|
|
import { Readable } from 'stream';
|
|
import { deepStrictEqual, rejects, throws } from 'assert';
|
|
|
|
{
|
|
// 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, []);
|
|
}
|
|
|
|
{
|
|
// 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, []);
|
|
}
|
|
|
|
{
|
|
// 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, []);
|
|
}
|
|
|
|
{
|
|
// 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 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/);
|
|
}
|