UNPKG

redioactive

Version:

Reactive streams for chaining overlapping promises.

92 lines (91 loc) 4 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); __setModuleDefault(result, mod); return result; }; Object.defineProperty(exports, "__esModule", { value: true }); const redio_1 = __importStar(require("../redio")); describe('Zipping two streams', () => { test('Zip two streams of equal length is as expected', async () => { const numbers = (0, redio_1.default)([1, 2, 3]); const words = (0, redio_1.default)(['one', 'two', 'three']); await expect(numbers.zip(words).toArray()).resolves.toEqual([ [1, 'one'], [2, 'two'], [3, 'three'] ]); }); test('Zip two empty streams', async () => { const empty1 = (0, redio_1.default)([]); const empty2 = (0, redio_1.default)([]); await expect(empty1.zip(empty2).toArray()).resolves.toEqual([]); }); test('Zip streams of different lengths - shorter first', async () => { const numbers = (0, redio_1.default)([1, 2]); const words = (0, redio_1.default)(['one', 'two', 'three']); await expect(numbers.zip(words).toArray()).resolves.toEqual([ [1, 'one'], [2, 'two'] ]); }); test('Zip streams of different lengths - shorter second', async () => { const numbers = (0, redio_1.default)([1, 2, 3]); const words = (0, redio_1.default)(['one', 'two']); await expect(numbers.zip(words).toArray()).resolves.toEqual([ [1, 'one'], [2, 'two'] ]); }); test('Zip streams with one empty - empty first', async () => { const numbers = (0, redio_1.default)([]); const words = (0, redio_1.default)(['one', 'two', 'three']); await expect(numbers.zip(words).toArray()).resolves.toEqual([]); }); test('Zip streams with one empty - empty second', async () => { const numbers = (0, redio_1.default)([1, 2, 3]); const words = (0, redio_1.default)([]); await expect(numbers.zip(words).toArray()).resolves.toEqual([]); }); test('Zip streams with big difference in lengths', async () => { const numbers = (0, redio_1.default)([1, 2, 3, 4, 5, 6, 7, 8, 8, 10, 11, 12, 13, 14, 15]); const words = (0, redio_1.default)(['one', 'two', 'three']); await expect(numbers.zip(words).toArray()).resolves.toEqual([ [1, 'one'], [2, 'two'], [3, 'three'] ]); }); test('Zip with different speed streams', async () => { const wait = (t) => new Promise((r) => setTimeout(() => r(t), t * 5)); function addWait(n) { let count = 0; return async () => (count < n ? await wait(++count) : redio_1.end); } await expect((0, redio_1.default)(addWait(4)) .zip((0, redio_1.default)(['one', 'two', 'three'])) .toArray()).resolves.toEqual([ [1, 'one'], [2, 'two'], [3, 'three'] ]); }); });