From 9a7bc8cbe92cab7d005831ececd6c6d22ecced7c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Einar=20Nor=C3=B0fj=C3=B6r=C3=B0?= Date: Fri, 26 Jan 2018 17:07:40 +0000 Subject: [PATCH] Get coverage up --- lib/index.js | 11 ++--- module/flatmap/test/index.js | 61 ----------------------- package.json | 2 +- test/index.js | 96 ++++++++++++++++++++++++++++++++++++ 4 files changed, 100 insertions(+), 70 deletions(-) delete mode 100644 module/flatmap/test/index.js diff --git a/lib/index.js b/lib/index.js index fc2ccf8..0727e82 100644 --- a/lib/index.js +++ b/lib/index.js @@ -272,9 +272,6 @@ flyd.fromPromise = function(promise) { promise.then(function onSuccess(val) { s(val); s.end(true); - }, function onError(err) { - s.end(true); - throw err; }); return s; } @@ -417,11 +414,8 @@ function boundAp(s2) { /** * @private */ -function fantasy_land_ap(s2) { - var s1 = this; - return combine(function(s1, s2, self) { - self(s2.val(s1.val)); - }, [s1, s2]); +function fantasy_land_ap(s1) { + return ap(this, s1); } /** @@ -614,6 +608,7 @@ function flushUpdate() { * @param {*} value */ function updateStreamValue(s, n) { + /* istanbul ignore if */ if (n !== undefined && n !== null && isFunction(n.then)) { console.warn('Promise swallowing has been deprecated in favour of flyd.fromPromise'); n.then(s); diff --git a/module/flatmap/test/index.js b/module/flatmap/test/index.js deleted file mode 100644 index 03f2a92..0000000 --- a/module/flatmap/test/index.js +++ /dev/null @@ -1,61 +0,0 @@ -var assert = require('assert'); -var flyd = require('../../../flyd'); -var stream = flyd.stream; -var flatMap = require('../index.js'); - -describe('flatMap', function() { - it('applies function to values in stream', function() { - var result = []; - function f(v) { - result.push(v); - return stream(); - } - var s = stream(); - flatMap(f, s); - s(1)(2)(3)(4)(5); - assert.deepEqual(result, [1, 2, 3, 4, 5]); - }); - it('returns stream with result from all streams created by function', function() { - var result = []; - function f(v) { - var s = stream(); - setImmediate(function() { - s(v + 1)(v + 2)(v + 3); - }); - return s; - } - var s = stream(); - flyd.map(function(v) { - result.push(v); - }, flatMap(f, s)); - s(1)(3)(5); - setImmediate(function() { - assert.deepEqual(result, [2, 3, 4, - 4, 5, 6, - 6, 7, 8]); - }); - }); - it('passed bug outlined in https://github.com/paldepind/flyd/issues/31', function(done) { - function delay(val, ms) { - var outStream = flyd.stream(); - - setTimeout(function() { - outStream(val); - outStream.end(true); - }, ms); - - return outStream; - } - - var main = delay(1, 500); - var merged = flatMap(function(v) { - return delay(v, 1000) - }, main); - - flyd.on(function() { - assert(main() === 1); - assert(merged() === 1); - done(); - }, merged.end); - }); -}); diff --git a/package.json b/package.json index 9372e6f..0f9f3c1 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,7 @@ }, "dependencies": { "fantasy-land": "^3.5.0", - "ramda": "^0.19.1" + "ramda": "^0.25.0" }, "devDependencies": { "benchmark": "^1.0.0", diff --git a/test/index.js b/test/index.js index 413797e..ae483f8 100644 --- a/test/index.js +++ b/test/index.js @@ -454,6 +454,63 @@ describe('stream', function() { }); }); + describe('chain', function() { + it('applies function to values in stream', function() { + var result = []; + function f(v) { + result.push(v); + return stream(); + } + var s = stream(); + flyd.chain(f, s); + s(1)(2)(3)(4)(5); + assert.deepEqual(result, [1, 2, 3, 4, 5]); + }); + it('returns stream with result from all streams created by function', function() { + var result = []; + function f(v) { + var s = stream(); + setImmediate(function() { + s(v + 1)(v + 2)(v + 3); + }); + return s; + } + var s = stream(); + flyd.map(function(v) { + result.push(v); + }, flyd.chain(f, s)); + s(1)(3)(5); + setImmediate(function() { + assert.deepEqual(result, [2, 3, 4, + 4, 5, 6, + 6, 7, 8]); + }); + }); + it('passed bug outlined in https://github.com/paldepind/flyd/issues/31', function(done) { + function delay(val, ms) { + var outStream = flyd.stream(); + + setTimeout(function() { + outStream(val); + outStream.end(true); + }, ms); + + return outStream; + } + + var main = delay(1, 500); + var merged = flyd.chain(function(v) { + return delay(v, 1000) + }, main); + + flyd.on(function() { + assert(main() === 1); + assert(merged() === 1); + done(); + }, merged.end); + }); + }); + describe('scan', function() { it('has initial acc as value when stream is undefined', function() { var numbers = stream(); @@ -839,4 +896,43 @@ describe('stream', function() { ]); }); }); + + describe('fantasy-land', function() { + it('map', function() { + var s = stream(1); + var mapped = R.map(R.add(3), s); + assert.equal(mapped(), 4); + assert.equal(s(), 1); + }); + + it('chain', function() { + var s = stream(1); + var chained = R.chain(R.compose(stream, R.add(3)), s); + assert.equal(chained(), 4); + assert.equal(s(), 1); + }); + + it('ap', function() { + var s = stream(R.add(3)); + var val = stream(3); + var applied = R.ap(s, val); + assert.equal(applied(), 6); + }); + + it('old ap', function() { + var s = stream(R.add(3)) + .ap(stream(3)); + assert.equal(s(), 6); + }); + + it('of', function() { + var s = flyd.of(3); + var s2 = s['fantasy-land/of'](5); + assert(flyd.isStream(s)); + assert.equal(s(), 3); + + assert(flyd.isStream(s2)); + assert.equal(s2(), 5); + }) + }); });