From 12e7ee31bf75300d15b409dc85ff8c7cf690bd43 Mon Sep 17 00:00:00 2001 From: Jared K. Smith Date: Aug 09 2016 15:43:05 +0000 Subject: Initial packaging --- diff --git a/.gitignore b/.gitignore index e69de29..1f34c5d 100644 --- a/.gitignore +++ b/.gitignore @@ -0,0 +1 @@ +/merge-stream-1.0.0.tgz diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..94a4c0a --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) Stephen Sugden (stephensugden.com) + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. diff --git a/nodejs-merge-stream.spec b/nodejs-merge-stream.spec new file mode 100644 index 0000000..15241b2 --- /dev/null +++ b/nodejs-merge-stream.spec @@ -0,0 +1,71 @@ +%{?nodejs_find_provides_and_requires} + +%global packagename merge-stream +%global enable_tests 1 + +Name: nodejs-merge-stream +Version: 1.0.0 +Release: 1%{?dist} +Summary: Create a stream that emits events from multiple other streams + +License: MIT +URL: https://github.com/grncdr/merge-stream.git +Source0: https://registry.npmjs.org/%{packagename}/-/%{packagename}-%{version}.tgz +Source1: https://raw.githubusercontent.com/grncdr/merge-stream/master/LICENSE +# Tests are not in npm tarball +Source2: https://raw.githubusercontent.com/grncdr/merge-stream/v%{version}/test.js + + +BuildArch: noarch +%if 0%{?fedora} >= 19 +ExclusiveArch: %{nodejs_arches} noarch +%else +ExclusiveArch: %{ix86} x86_64 %{arm} noarch +%endif + +BuildRequires: nodejs-packaging +%if 0%{?enable_tests} +BuildRequires: mocha +BuildRequires: npm(from2) +%endif + +%description +Create a stream that emits events from multiple other streams + + +%prep +%setup -q -n package +cp -p %{SOURCE1} . +cp -p %{SOURCE2} . + + +%build +# nothing to do! + +%install +mkdir -p %{buildroot}%{nodejs_sitelib}/%{packagename} +cp -pr package.json index.js \ + %{buildroot}%{nodejs_sitelib}/%{packagename} + +%nodejs_symlink_deps + +%check +%nodejs_symlink_deps --check +%{__nodejs} -e 'require("./")' +%if 0%{?enable_tests} +%{__nodejs} test.js +%else +%{_bindir}/echo -e "\e[101m -=#=- Tests disabled -=#=- \e[0m" +%endif + + +%files +%{!?_licensedir:%global license %doc} +%doc *.md +%license LICENSE +%{nodejs_sitelib}/%{packagename} + + +%changelog +* Sun Feb 21 2016 Jared Smith - 1.0.0-1 +- Initial packaging diff --git a/sources b/sources index e69de29..e5e9e6f 100644 --- a/sources +++ b/sources @@ -0,0 +1 @@ +c823d4b18f0cf7896166c5f991371864 merge-stream-1.0.0.tgz diff --git a/test.js b/test.js new file mode 100644 index 0000000..0880881 --- /dev/null +++ b/test.js @@ -0,0 +1,79 @@ +'use strict'; + +var assert = require('assert') +var from = require('from2') + +var merge = require('./') + +function test (name, fn, c) { + var combined = c || merge(); + var to = after(1000, process.emit.bind(process), 'error', new Error('Timed out: ' + name)) + combined.on('end', function () { + clearTimeout(to) + }); + fn(combined); +} + +test('smoke', function (combined) { + + function addSource (i) { + if (i === 38) return; + combined.add(range(i)) + after(6, addSource, i + 1) + } + + var total = 0 + + combined.on('data', function (i) { total += i }) + combined.on('end', function () { assert.equal(666, total) }) + + addSource(-36) +}) + +test('pause/resume', function (combined) { + combined.add(range(100)) + combined.add(range(-100)) + var counter = 0; + combined.on('data', function () { counter++ }) + + after(20, function () { + combined.pause() + assert(counter < 200) + var pauseCount = counter; + + after(50, function () { + assert.equal(pauseCount, counter); + combined.resume(); + }); + + }); + + combined.on('end', function () { assert.equal(counter, 200) }) +}) + +test('array', function (combined) { + var counter = 0; + combined.on('data', function () { counter++ }) + combined.on('end', function () { assert.equal(counter, 200) }) +}, merge([ + range(100), + range(-100) +])) + +test('isEmpty', function (combined) { + assert(combined.isEmpty()); + combined.on('data', function (n) { assert.equal(0, n) }); + combined.add(range(1)); + assert(!combined.isEmpty()); +}) + +function range (n) { + var k = n > 0 ? -1 : 1 + return from.obj(function (_, next) { + setTimeout(function () { + next(null, n === 0 ? null : n += k) + }, Math.round(6 + Math.round(Math.random() * 6))); + }) +} + +function after (ms, fn, a, b, c) { return setTimeout(fn, ms, a, b, c) }