@dmail/action
Advanced tools
Comparing version 1.1.0 to 1.2.0
@@ -55,2 +55,26 @@ "use strict"; | ||
var _compose = require("./src/compose/compose.js"); | ||
Object.keys(_compose).forEach(function (key) { | ||
if (key === "default" || key === "__esModule") return; | ||
Object.defineProperty(exports, key, { | ||
enumerable: true, | ||
get: function get() { | ||
return _compose[key]; | ||
} | ||
}); | ||
}); | ||
var _composeWithAllocatedMs = require("./src/composeWithAllocatedMs/composeWithAllocatedMs.js"); | ||
Object.keys(_composeWithAllocatedMs).forEach(function (key) { | ||
if (key === "default" || key === "__esModule") return; | ||
Object.defineProperty(exports, key, { | ||
enumerable: true, | ||
get: function get() { | ||
return _composeWithAllocatedMs[key]; | ||
} | ||
}); | ||
}); | ||
var _failed = require("./src/failed/failed.js"); | ||
@@ -57,0 +81,0 @@ |
"use strict"; | ||
var _test = require("./test.js"); | ||
var _testCheap = require("@dmail/test-cheap"); | ||
var _action = require("./action.js"); | ||
(0, _test.test)("action.js", function (_ref) { | ||
var ensure = _ref.ensure, | ||
assert = _ref.assert, | ||
assertPassed = _ref.assertPassed, | ||
assertFailed = _ref.assertFailed, | ||
assertResult = _ref.assertResult; | ||
var _assertions = require("./assertions.js"); | ||
(0, _testCheap.test)("action.js", function (_ref) { | ||
var ensure = _ref.ensure; | ||
ensure("action.pass(itself) throw", function () { | ||
var action = (0, _action.createAction)(); | ||
assert.throws(function () { | ||
_assertions.assert.throws(function () { | ||
action.pass(action); | ||
@@ -21,3 +20,4 @@ }); | ||
var action = (0, _action.createAction)(); | ||
assert.throws(function () { | ||
_assertions.assert.throws(function () { | ||
action.fail(action); | ||
@@ -29,3 +29,4 @@ }); | ||
action.pass(); | ||
assert.throws(function () { | ||
_assertions.assert.throws(function () { | ||
action.pass(); | ||
@@ -37,3 +38,4 @@ }); | ||
action.fail(); | ||
assert.throws(function () { | ||
_assertions.assert.throws(function () { | ||
action.fail(); | ||
@@ -45,3 +47,4 @@ }); | ||
action.fail(); | ||
assert.throws(function () { | ||
_assertions.assert.throws(function () { | ||
action.pass(); | ||
@@ -53,3 +56,4 @@ }); | ||
action.pass(); | ||
assert.throws(function () { | ||
_assertions.assert.throws(function () { | ||
action.fail(); | ||
@@ -67,4 +71,4 @@ }); | ||
action.pass(resolvedThenable); | ||
assertPassed(action); | ||
assertResult(action, value); | ||
(0, _assertions.assertPassed)(action); | ||
(0, _assertions.assertResult)(action, value); | ||
}); | ||
@@ -80,4 +84,4 @@ ensure("action.fail(resolvedThenable) pass with resolvedThenable wrapped value", function () { | ||
action.fail(resolvedThenable); | ||
assertPassed(action); | ||
assertResult(action, value); | ||
(0, _assertions.assertPassed)(action); | ||
(0, _assertions.assertResult)(action, value); | ||
}); | ||
@@ -93,4 +97,4 @@ ensure("action.pass(rejectedThenable) fail with rejectedThenable wrapped value", function () { | ||
action.pass(rejectedThenable); | ||
assertFailed(action); | ||
assertResult(action, value); | ||
(0, _assertions.assertFailed)(action); | ||
(0, _assertions.assertResult)(action, value); | ||
}); | ||
@@ -106,4 +110,4 @@ ensure("action.fail(rejectedThenable) fail with rejectedThenable wrapped value", function () { | ||
action.fail(rejectedThenable); | ||
assertFailed(action); | ||
assertResult(action, value); | ||
(0, _assertions.assertFailed)(action); | ||
(0, _assertions.assertResult)(action, value); | ||
}); | ||
@@ -118,3 +122,4 @@ ensure("action.then(onPass) call onpass immediatly when passed", function () { | ||
}); | ||
assert.equal(passedValue, value); | ||
_assertions.assert.equal(passedValue, value); | ||
}); | ||
@@ -128,5 +133,8 @@ ensure("action.then(onPass) calls onpass as soon as passed", function () { | ||
}); | ||
assert.equal(passedValue, undefined); | ||
_assertions.assert.equal(passedValue, undefined); | ||
action.pass(value); | ||
assert.equal(passedValue, value); | ||
_assertions.assert.equal(passedValue, value); | ||
}); | ||
@@ -141,3 +149,4 @@ ensure("action.then(null, onFail) call onFail immediatly when failed", function () { | ||
}); | ||
assert.equal(failedValue, value); | ||
_assertions.assert.equal(failedValue, value); | ||
}); | ||
@@ -151,5 +160,8 @@ ensure("action.then(null, onFail) calls onFail as soon as failed", function () { | ||
}); | ||
assert.equal(failedValue, undefined); | ||
_assertions.assert.equal(failedValue, undefined); | ||
action.fail(value); | ||
assert.equal(failedValue, value); | ||
_assertions.assert.equal(failedValue, value); | ||
}); | ||
@@ -161,4 +173,4 @@ ensure("action.then() when passed", function () { | ||
action.pass(value); | ||
assertPassed(nextAction); | ||
assertResult(nextAction, value); | ||
(0, _assertions.assertPassed)(nextAction); | ||
(0, _assertions.assertResult)(nextAction, value); | ||
}); | ||
@@ -170,4 +182,4 @@ ensure("action.then() when failed", function () { | ||
action.fail(value); | ||
assertFailed(nextAction); | ||
assertResult(nextAction, value); | ||
(0, _assertions.assertFailed)(nextAction); | ||
(0, _assertions.assertResult)(nextAction, value); | ||
}); | ||
@@ -182,7 +194,9 @@ ensure("action.mixin add property to action", function () { | ||
}); | ||
assert.equal(action.foo, foo); | ||
_assertions.assert.equal(action.foo, foo); | ||
}); | ||
ensure("action.mixin throw on existing property", function () { | ||
var action = (0, _action.createAction)(); | ||
assert.throws(function () { | ||
_assertions.assert.throws(function () { | ||
return action.mixin({ | ||
@@ -205,4 +219,6 @@ pass: function pass() {} | ||
}); | ||
assert.equal(firstArg, action); | ||
assert.equal(action.foo, foo); | ||
_assertions.assert.equal(firstArg, action); | ||
_assertions.assert.equal(action.foo, foo); | ||
}); | ||
@@ -209,0 +225,0 @@ ensure("action mixin can return null", function () { |
"use strict"; | ||
var _test = require("../test.js"); | ||
var _testCheap = require("@dmail/test-cheap"); | ||
@@ -9,8 +9,6 @@ var _action = require("../action.js"); | ||
(0, _test.test)("all.js", function (_ref) { | ||
var ensure = _ref.ensure, | ||
assert = _ref.assert, | ||
assertPassed = _ref.assertPassed, | ||
assertFailed = _ref.assertFailed, | ||
assertResult = _ref.assertResult; | ||
var _assertions = require("../assertions.js"); | ||
(0, _testCheap.test)("all.js", function (_ref) { | ||
var ensure = _ref.ensure; | ||
ensure("all with only values", function () { | ||
@@ -20,4 +18,5 @@ var firstValue = "foo"; | ||
var action = (0, _all.all)([firstValue, secondValue]); | ||
assertPassed(action); | ||
assert.deepEqual(action.getResult(), [firstValue, secondValue]); | ||
(0, _assertions.assertPassed)(action); | ||
_assertions.assert.deepEqual(action.getResult(), [firstValue, secondValue]); | ||
}); | ||
@@ -30,4 +29,5 @@ ensure("all with value mixed with thenable", function () { | ||
secondValueInAction.pass(secondValue); | ||
assertPassed(action); | ||
assert.deepEqual(action.getResult(), [firstValue, secondValue]); | ||
(0, _assertions.assertPassed)(action); | ||
_assertions.assert.deepEqual(action.getResult(), [firstValue, secondValue]); | ||
}); | ||
@@ -45,6 +45,6 @@ ensure("action passed/failed after fail are ignored", function () { | ||
thirdAction.fail(thirdValue); | ||
assertFailed(action); | ||
assertResult(action, firstValue); | ||
(0, _assertions.assertFailed)(action); | ||
(0, _assertions.assertResult)(action, firstValue); | ||
}); | ||
}); | ||
//# sourceMappingURL=all.test.js.map |
"use strict"; | ||
var _test = require("../test.js"); | ||
var _testCheap = require("@dmail/test-cheap"); | ||
@@ -9,7 +9,6 @@ var _action = require("../action.js"); | ||
(0, _test.test)("any.js", function (_ref) { | ||
var ensure = _ref.ensure, | ||
assertPassed = _ref.assertPassed, | ||
assertFailed = _ref.assertFailed, | ||
assertResult = _ref.assertResult; | ||
var _assertions = require("../assertions.js"); | ||
(0, _testCheap.test)("any.js", function (_ref) { | ||
var ensure = _ref.ensure; | ||
ensure("any with only values", function () { | ||
@@ -19,4 +18,4 @@ var value = "a"; | ||
var action = (0, _any.any)([value, secondValue]); | ||
assertPassed(action); | ||
assertResult(action, value); | ||
(0, _assertions.assertPassed)(action); | ||
(0, _assertions.assertResult)(action, value); | ||
}); | ||
@@ -27,4 +26,4 @@ ensure("with value mixed with thenable", function () { | ||
var action = (0, _any.any)([thenable, value]); | ||
assertPassed(action); | ||
assertResult(action, value); | ||
(0, _assertions.assertPassed)(action); | ||
(0, _assertions.assertResult)(action, value); | ||
}); | ||
@@ -36,4 +35,4 @@ ensure("with resolved thenable", function () { | ||
var action = (0, _any.any)([thenable]); | ||
assertPassed(action); | ||
assertResult(action, value); | ||
(0, _assertions.assertPassed)(action); | ||
(0, _assertions.assertResult)(action, value); | ||
}); | ||
@@ -45,4 +44,4 @@ ensure("with rejected thenable", function () { | ||
var action = (0, _any.any)([thenable]); | ||
assertFailed(action); | ||
assertResult(action, value); | ||
(0, _assertions.assertFailed)(action); | ||
(0, _assertions.assertResult)(action, value); | ||
}); | ||
@@ -55,6 +54,6 @@ ensure("thenable resolved once passed are ignored", function () { | ||
firstAction.pass(value); | ||
assertPassed(action); | ||
assertResult(action, value); | ||
(0, _assertions.assertPassed)(action); | ||
(0, _assertions.assertResult)(action, value); | ||
secondAction.pass(); | ||
assertResult(action, value); | ||
(0, _assertions.assertResult)(action, value); | ||
}); | ||
@@ -67,8 +66,8 @@ ensure("thenable rejected once passed are ignored", function () { | ||
firstAction.pass(value); | ||
assertPassed(action); | ||
assertResult(action, value); | ||
(0, _assertions.assertPassed)(action); | ||
(0, _assertions.assertResult)(action, value); | ||
secondAction.fail(); | ||
assertResult(action, value); | ||
(0, _assertions.assertResult)(action, value); | ||
}); | ||
}); | ||
//# sourceMappingURL=any.test.js.map |
"use strict"; | ||
var _test = require("../test.js"); | ||
var _testCheap = require("@dmail/test-cheap"); | ||
@@ -9,8 +9,6 @@ var _action = require("../action.js"); | ||
(0, _test.test)("aroundAction.js", function (_ref) { | ||
var ensure = _ref.ensure, | ||
assert = _ref.assert, | ||
assertPassed = _ref.assertPassed, | ||
assertFailed = _ref.assertFailed, | ||
assertResult = _ref.assertResult; | ||
var _assertions = require("../assertions.js"); | ||
(0, _testCheap.test)("aroundAction.js", function (_ref) { | ||
var ensure = _ref.ensure; | ||
ensure("on passed action", function () { | ||
@@ -43,6 +41,9 @@ var beforeArgs = void 0; | ||
}, after); | ||
assert.deepEqual(beforeArgs, []); | ||
assert.deepEqual(afterArgs, [value, true]); | ||
assertPassed(action); | ||
assertResult(action, value); | ||
_assertions.assert.deepEqual(beforeArgs, []); | ||
_assertions.assert.deepEqual(afterArgs, [value, true]); | ||
(0, _assertions.assertPassed)(action); | ||
(0, _assertions.assertResult)(action, value); | ||
}); | ||
@@ -76,8 +77,11 @@ ensure("on failed action", function () { | ||
}, after); | ||
assert.deepEqual(beforeArgs, []); | ||
assert.deepEqual(afterArgs, [value, false]); | ||
assertFailed(action); | ||
assertResult(action, value); | ||
_assertions.assert.deepEqual(beforeArgs, []); | ||
_assertions.assert.deepEqual(afterArgs, [value, false]); | ||
(0, _assertions.assertFailed)(action); | ||
(0, _assertions.assertResult)(action, value); | ||
}); | ||
}); | ||
//# sourceMappingURL=aroundAction.test.js.map |
"use strict"; | ||
var _test = require("../test.js"); | ||
var _testCheap = require("@dmail/test-cheap"); | ||
@@ -13,11 +13,11 @@ var _action = require("../action.js"); | ||
(0, _test.test)("compose.js", function (_ref) { | ||
var ensure = _ref.ensure, | ||
assert = _ref.assert, | ||
assertPassed = _ref.assertPassed, | ||
assertFailed = _ref.assertFailed; | ||
var _assertions = require("../assertions.js"); | ||
(0, _testCheap.test)("compose.js", function (_ref) { | ||
var ensure = _ref.ensure; | ||
ensure("composeSequence with values", function () { | ||
var action = (0, _compose.composeSequence)([0, 1]); | ||
assertPassed(action); | ||
assert.deepEqual(action.getResult(), [{ | ||
(0, _assertions.assertPassed)(action); | ||
_assertions.assert.deepEqual(action.getResult(), [{ | ||
state: "passed", | ||
@@ -32,4 +32,5 @@ result: 0 | ||
var action = (0, _compose.composeSequence)([(0, _passed.passed)(0), (0, _passed.passed)(1)]); | ||
assertPassed(action); | ||
assert.deepEqual(action.getResult(), [{ | ||
(0, _assertions.assertPassed)(action); | ||
_assertions.assert.deepEqual(action.getResult(), [{ | ||
state: "passed", | ||
@@ -44,4 +45,5 @@ result: 0 | ||
var action = (0, _compose.composeSequence)([(0, _failed.failed)(0), (0, _failed.failed)(1)]); | ||
assertFailed(action); | ||
assert.deepEqual(action.getResult(), [{ | ||
(0, _assertions.assertFailed)(action); | ||
_assertions.assert.deepEqual(action.getResult(), [{ | ||
state: "failed", | ||
@@ -66,3 +68,4 @@ result: 0 | ||
}); | ||
assert.deepEqual(action.getResult(), [{ | ||
_assertions.assert.deepEqual(action.getResult(), [{ | ||
state: "passed", | ||
@@ -86,5 +89,8 @@ result: 0 | ||
}); | ||
assert.equal(callCount, 1); | ||
_assertions.assert.equal(callCount, 1); | ||
firstAction.pass(); | ||
assert.equal(callCount, 2); | ||
_assertions.assert.equal(callCount, 2); | ||
}); | ||
@@ -97,5 +103,6 @@ ensure("composeTogether called concurrently", function () { | ||
}); | ||
assert.equal(callCount, 2); | ||
_assertions.assert.equal(callCount, 2); | ||
}); | ||
}); | ||
//# sourceMappingURL=compose.test.js.map |
@@ -10,4 +10,2 @@ "use strict"; | ||
var _fromFunction = require("../fromFunction/fromFunction.js"); | ||
var _withAllocableMs = require("../withAllocableMs/withAllocableMs.js"); | ||
@@ -27,10 +25,8 @@ | ||
allocatedMs = _ref$allocatedMs === void 0 ? Infinity : _ref$allocatedMs; | ||
return (0, _fromFunction.fromFunction)(function (action) { | ||
action.mixin(_withAllocableMs.withAllocableMs); | ||
action.allocateMs(allocatedMs); | ||
return composer(iterable, function (composedAction, value, index) { | ||
composedAction.mixin(_withAllocableMs.withAllocableMs); | ||
composedAction.allocateMs(action.getRemainingMs()); | ||
return handle(composedAction, value, index, iterable); | ||
}); | ||
var previousAction = void 0; | ||
return composer(iterable, function (composedAction, value, index) { | ||
composedAction.mixin(_withAllocableMs.withAllocableMs); | ||
composedAction.allocateMs(index === 0 ? allocatedMs : previousAction.getRemainingMs()); | ||
previousAction = composedAction; | ||
return handle(composedAction, value, index, iterable); | ||
}); | ||
@@ -37,0 +33,0 @@ }; |
@@ -5,3 +5,3 @@ "use strict"; | ||
var _test = require("../test.js"); | ||
var _testCheap = require("@dmail/test-cheap"); | ||
@@ -12,28 +12,26 @@ var _action = require("../action.js"); | ||
(0, _test.test)("composeWithAllocableMs.js", function (_ref) { | ||
var ensure = _ref.ensure, | ||
assert = _ref.assert; | ||
ensure("by default compositeAction is given infinite ms", function () { | ||
var action = (0, _composeWithAllocatedMs.composeSequenceWithAllocatedMs)([0]); | ||
assert.equal(action.getRemainingMs(), Infinity); | ||
}); | ||
ensure("compositeAction is given the allocatedMs", function () { | ||
var compositeAction = (0, _composeWithAllocatedMs.composeSequenceWithAllocatedMs)([0], undefined, 10); | ||
var compositeActionRemainingMs = compositeAction.getRemainingMs(); | ||
assert.equal(_typeof(compositeActionRemainingMs), "number"); | ||
assert(compositeActionRemainingMs < 11); | ||
}); | ||
var _assertions = require("../assertions.js"); | ||
(0, _testCheap.test)("composeWithAllocableMs.js", function (_ref) { | ||
var ensure = _ref.ensure; | ||
ensure("each composed action is allocated the compositeAction remainingMs", function () { | ||
var firstAction = (0, _action.createAction)(); | ||
var secondAction = (0, _action.createAction)(); | ||
var compositeAction = (0, _composeWithAllocatedMs.composeSequenceWithAllocatedMs)([firstAction, secondAction], undefined, 10); | ||
(0, _composeWithAllocatedMs.composeSequenceWithAllocatedMs)([firstAction, secondAction], undefined, 10); | ||
var firstActionRemainingMs = firstAction.getRemainingMs(); | ||
assert.equal(_typeof(firstActionRemainingMs), "number"); | ||
assert(firstActionRemainingMs <= compositeAction.getRemainingMs()); | ||
assert.equal(secondAction.getRemainingMs, undefined); // because first action is running | ||
_assertions.assert.equal(_typeof(firstActionRemainingMs), "number"); | ||
(0, _assertions.assert)(firstActionRemainingMs <= 10); | ||
_assertions.assert.equal(secondAction.getRemainingMs, undefined); // because first action is running | ||
firstAction.pass(); | ||
var secondActionRemainingMs = secondAction.getRemainingMs(); | ||
assert.equal(_typeof(secondActionRemainingMs), "number"); | ||
assert(secondActionRemainingMs <= compositeAction.getRemainingMs()); | ||
_assertions.assert.equal(_typeof(secondActionRemainingMs), "number"); | ||
firstActionRemainingMs = firstAction.getRemainingMs(); | ||
(0, _assertions.assert)(secondActionRemainingMs <= firstActionRemainingMs); | ||
}); | ||
@@ -51,15 +49,26 @@ ensure("handle always receive an action as first arg", function () { | ||
}); | ||
assert.equal(calls.length, 2); | ||
assert((0, _action.isAction)(calls[0][0])); | ||
assert.equal(calls[0][1], 1); | ||
assert.equal(calls[0][2], 0); | ||
assert.equal(calls[0][3], iterable); | ||
assert.equal(calls[1].length, 4); | ||
assert.equal(calls[1][0], action); | ||
assert.equal(calls[1][1], action); | ||
assert.equal(calls[1][2], 1); | ||
assert.equal(calls[1][3], iterable); | ||
assert.equal(calls[1].length, 4); | ||
_assertions.assert.equal(calls.length, 2); | ||
(0, _assertions.assert)((0, _action.isAction)(calls[0][0])); | ||
_assertions.assert.equal(calls[0][1], 1); | ||
_assertions.assert.equal(calls[0][2], 0); | ||
_assertions.assert.equal(calls[0][3], iterable); | ||
_assertions.assert.equal(calls[1].length, 4); | ||
_assertions.assert.equal(calls[1][0], action); | ||
_assertions.assert.equal(calls[1][1], action); | ||
_assertions.assert.equal(calls[1][2], 1); | ||
_assertions.assert.equal(calls[1][3], iterable); | ||
_assertions.assert.equal(calls[1].length, 4); | ||
}); | ||
}); | ||
//# sourceMappingURL=composeWithAllocatedMs.test.js.map |
"use strict"; | ||
var _test = require("../test.js"); | ||
var _testCheap = require("@dmail/test-cheap"); | ||
@@ -9,12 +9,11 @@ var _passed = require("../passed/passed.js"); | ||
(0, _test.test)("failed.js", function (_ref) { | ||
var ensure = _ref.ensure, | ||
assert = _ref.assert, | ||
assertFailed = _ref.assertFailed, | ||
assertResult = _ref.assertResult; | ||
var _assertions = require("../assertions.js"); | ||
(0, _testCheap.test)("failed.js", function (_ref) { | ||
var ensure = _ref.ensure; | ||
ensure("failed return an action failed with the value", function () { | ||
var value = 1; | ||
var action = (0, _failed.failed)(value); | ||
assertFailed(action); | ||
assertResult(action, value); | ||
(0, _assertions.assertFailed)(action); | ||
(0, _assertions.assertResult)(action, value); | ||
}); | ||
@@ -24,3 +23,4 @@ ensure("failed with failed action", function () { | ||
var action = (0, _failed.failed)(failedAction); | ||
assert.equal(action, failedAction); | ||
_assertions.assert.equal(action, failedAction); | ||
}); | ||
@@ -30,5 +30,6 @@ ensure("failed with passed action", function () { | ||
var action = (0, _failed.failed)(passedAction); | ||
assert.equal(action, passedAction); | ||
_assertions.assert.equal(action, passedAction); | ||
}); | ||
}); | ||
//# sourceMappingURL=failed.test.js.map |
"use strict"; | ||
var _test = require("../test.js"); | ||
var _testCheap = require("@dmail/test-cheap"); | ||
var _fromFunction = require("./fromFunction.js"); | ||
(0, _test.test)("fromFunction.js", function (_ref) { | ||
var ensure = _ref.ensure, | ||
assert = _ref.assert, | ||
assertPassed = _ref.assertPassed, | ||
assertFailed = _ref.assertFailed, | ||
assertResult = _ref.assertResult; | ||
var _assertions = require("../assertions.js"); | ||
(0, _testCheap.test)("fromFunction.js", function (_ref) { | ||
var ensure = _ref.ensure; | ||
ensure("function returning resolved thenable pass action", function () { | ||
@@ -23,4 +21,4 @@ var value = 1; | ||
}); | ||
assertPassed(action); | ||
assertResult(action, value); | ||
(0, _assertions.assertPassed)(action); | ||
(0, _assertions.assertResult)(action, value); | ||
}); | ||
@@ -37,4 +35,4 @@ ensure("function returning rejected thenable fails action", function () { | ||
}); | ||
assertFailed(action); | ||
assertResult(action, value); | ||
(0, _assertions.assertFailed)(action); | ||
(0, _assertions.assertResult)(action, value); | ||
}); | ||
@@ -45,5 +43,6 @@ ensure("function can return the action itself", function () { | ||
}); | ||
assert.equal(action.getState(), "unknown"); | ||
_assertions.assert.equal(action.getState(), "unknown"); | ||
}); | ||
}); | ||
//# sourceMappingURL=fromFunction.test.js.map |
"use strict"; | ||
var _test = require("../test.js"); | ||
var _testCheap = require("@dmail/test-cheap"); | ||
var _fromNodeCallback = require("./fromNodeCallback.js"); | ||
(0, _test.test)("fromNodeCallback.js", function (_ref) { | ||
var ensure = _ref.ensure, | ||
assert = _ref.assert, | ||
assertPassed = _ref.assertPassed, | ||
assertResult = _ref.assertResult; | ||
var _assertions = require("../assertions.js"); | ||
(0, _testCheap.test)("fromNodeCallback.js", function (_ref) { | ||
var ensure = _ref.ensure; | ||
var nodeCallbackError = function nodeCallbackError(error, callback) { | ||
@@ -24,8 +23,9 @@ return callback(error); | ||
var action = (0, _fromNodeCallback.fromNodeCallback)(nodeCallbackSuccess)(value); | ||
assertPassed(action); | ||
assertResult(action, value); | ||
(0, _assertions.assertPassed)(action); | ||
(0, _assertions.assertResult)(action, value); | ||
}); | ||
ensure("when callback is errored", function () { | ||
var exception = 1; | ||
assert.throws(function () { | ||
_assertions.assert.throws(function () { | ||
return (0, _fromNodeCallback.fromNodeCallback)(nodeCallbackError)(exception); | ||
@@ -32,0 +32,0 @@ }, function (error) { |
"use strict"; | ||
var _test = require("../test.js"); | ||
var _testCheap = require("@dmail/test-cheap"); | ||
var _fromNodeCallbackCatching = require("./fromNodeCallbackCatching.js"); | ||
(0, _test.test)("fromNodeCallbackCatching.js", function (_ref) { | ||
var ensure = _ref.ensure, | ||
assert = _ref.assert, | ||
assertPassed = _ref.assertPassed, | ||
assertResult = _ref.assertResult; | ||
var _assertions = require("../assertions.js"); | ||
(0, _testCheap.test)("fromNodeCallbackCatching.js", function (_ref) { | ||
var ensure = _ref.ensure; | ||
var nodeCallbackError = function nodeCallbackError(error, callback) { | ||
@@ -24,4 +23,4 @@ return callback(error); | ||
var action = (0, _fromNodeCallbackCatching.fromNodeCallbackCatching)(nodeCallbackSuccess)(value); | ||
assertPassed(action); | ||
assertResult(action, value); | ||
(0, _assertions.assertPassed)(action); | ||
(0, _assertions.assertResult)(action, value); | ||
}); | ||
@@ -34,8 +33,9 @@ ensure("when callback is errored and catched", function () { | ||
}, recoverValue)(exception); | ||
assertPassed(action); | ||
assertResult(action, recoverValue); | ||
(0, _assertions.assertPassed)(action); | ||
(0, _assertions.assertResult)(action, recoverValue); | ||
}); | ||
ensure("when callback is errored and not catched", function () { | ||
var exception = 1; | ||
assert.throws(function () { | ||
_assertions.assert.throws(function () { | ||
return (0, _fromNodeCallbackCatching.fromNodeCallbackCatching)(nodeCallbackError, function () { | ||
@@ -42,0 +42,0 @@ return false; |
"use strict"; | ||
var _test = require("../test.js"); | ||
var _testCheap = require("@dmail/test-cheap"); | ||
var _fromPromise = require("./fromPromise.js"); | ||
(0, _test.test)("fromPromise.js", function (_ref) { | ||
var assert = _ref.assert, | ||
waitUntil = _ref.waitUntil; | ||
var _assertions = require("../assertions.js"); | ||
(0, _testCheap.test)("fromPromise.js", function (_ref) { | ||
var waitUntil = _ref.waitUntil; | ||
var done = waitUntil(); | ||
@@ -27,3 +28,4 @@ var passException = 1; | ||
setTimeout(function () { | ||
assert.equal(caughtException, passException); | ||
_assertions.assert.equal(caughtException, passException); | ||
var failException = 2; | ||
@@ -46,3 +48,4 @@ process.once("uncaughtException", function (e) { | ||
setTimeout(function () { | ||
assert.equal(caughtException, failException); | ||
_assertions.assert.equal(caughtException, failException); | ||
done(); | ||
@@ -49,0 +52,0 @@ }, 20); |
"use strict"; | ||
var _test = require("../test.js"); | ||
var _testCheap = require("@dmail/test-cheap"); | ||
@@ -9,7 +9,6 @@ var _action = require("../action.js"); | ||
(0, _test.test)("mapFailed.js", function (_ref) { | ||
var ensure = _ref.ensure, | ||
assert = _ref.assert, | ||
assertFailed = _ref.assertFailed, | ||
assertResult = _ref.assertResult; | ||
var _assertions = require("../assertions.js"); | ||
(0, _testCheap.test)("mapFailed.js", function (_ref) { | ||
var ensure = _ref.ensure; | ||
ensure("transforms failure value", function () { | ||
@@ -29,7 +28,9 @@ var action = (0, _action.createAction)(); | ||
}); | ||
assert.deepEqual(callArgs, [value]); | ||
assertFailed(mappedAction); | ||
assertResult(mappedAction, mappedValue); | ||
_assertions.assert.deepEqual(callArgs, [value]); | ||
(0, _assertions.assertFailed)(mappedAction); | ||
(0, _assertions.assertResult)(mappedAction, mappedValue); | ||
}); | ||
}); | ||
//# sourceMappingURL=mapFailed.test.js.map |
"use strict"; | ||
var _test = require("../test.js"); | ||
var _testCheap = require("@dmail/test-cheap"); | ||
@@ -9,12 +9,11 @@ var _failed = require("../failed/failed.js"); | ||
(0, _test.test)("passed.js", function (_ref) { | ||
var ensure = _ref.ensure, | ||
assert = _ref.assert, | ||
assertPassed = _ref.assertPassed, | ||
assertResult = _ref.assertResult; | ||
var _assertions = require("../assertions.js"); | ||
(0, _testCheap.test)("passed.js", function (_ref) { | ||
var ensure = _ref.ensure; | ||
ensure("passed return an action passed with the value", function () { | ||
var value = 1; | ||
var action = (0, _passed.passed)(value); | ||
assertPassed(action); | ||
assertResult(action, value); | ||
(0, _assertions.assertPassed)(action); | ||
(0, _assertions.assertResult)(action, value); | ||
}); | ||
@@ -24,3 +23,4 @@ ensure("passed with failed action", function () { | ||
var action = (0, _passed.passed)(failedAction); | ||
assert.equal(action, failedAction); | ||
_assertions.assert.equal(action, failedAction); | ||
}); | ||
@@ -30,5 +30,6 @@ ensure("passed with passed action", function () { | ||
var action = (0, _passed.passed)(passedAction); | ||
assert.equal(action, passedAction); | ||
_assertions.assert.equal(action, passedAction); | ||
}); | ||
}); | ||
//# sourceMappingURL=passed.test.js.map |
"use strict"; | ||
var _test = require("../test.js"); | ||
var _testCheap = require("@dmail/test-cheap"); | ||
@@ -9,8 +9,6 @@ var _action = require("../action.js"); | ||
(0, _test.test)("sequence.js", function (_ref) { | ||
var ensure = _ref.ensure, | ||
assert = _ref.assert, | ||
assertPassed = _ref.assertPassed, | ||
assertFailed = _ref.assertFailed, | ||
assertResult = _ref.assertResult; | ||
var _assertions = require("../assertions.js"); | ||
(0, _testCheap.test)("sequence.js", function (_ref) { | ||
var ensure = _ref.ensure; | ||
ensure("with only values", function () { | ||
@@ -20,4 +18,5 @@ var firstValue = "foo"; | ||
var action = (0, _sequence.sequence)([firstValue, secondValue]); | ||
assertPassed(action); | ||
assert.deepEqual(action.getResult(), [firstValue, secondValue]); | ||
(0, _assertions.assertPassed)(action); | ||
_assertions.assert.deepEqual(action.getResult(), [firstValue, secondValue]); | ||
}); | ||
@@ -30,4 +29,5 @@ ensure("with value mixed with thenable", function () { | ||
secondValueInAction.pass(secondValue); | ||
assertPassed(action); | ||
assert.deepEqual(action.getResult(), [firstValue, secondValue]); | ||
(0, _assertions.assertPassed)(action); | ||
_assertions.assert.deepEqual(action.getResult(), [firstValue, secondValue]); | ||
}); | ||
@@ -40,4 +40,4 @@ ensure("first fail fails everything", function () { | ||
firstAction.fail(value); | ||
assertFailed(action); | ||
assertResult(action, value); | ||
(0, _assertions.assertFailed)(action); | ||
(0, _assertions.assertResult)(action, value); | ||
}); | ||
@@ -49,6 +49,6 @@ ensure("second argument is used to dynamically create action/value", function () { | ||
}); | ||
assertPassed(action); | ||
assertResult(action, value + 1); | ||
(0, _assertions.assertPassed)(action); | ||
(0, _assertions.assertResult)(action, value + 1); | ||
}); | ||
}); | ||
//# sourceMappingURL=sequence.test.js.map |
@@ -13,2 +13,3 @@ "use strict"; | ||
var startMs = void 0; | ||
var endMs = void 0; | ||
@@ -24,2 +25,4 @@ var cancelTimeout = function cancelTimeout() { | ||
allocatedMs = ms < 0 ? Infinity : ms; | ||
startMs = undefined; | ||
endMs = undefined; | ||
cancelTimeout(); | ||
@@ -36,3 +39,11 @@ | ||
var getConsumedMs = function getConsumedMs() { | ||
return startMs === undefined ? undefined : Date.now() - startMs; | ||
if (startMs === undefined) { | ||
return undefined; | ||
} | ||
if (endMs === undefined) { | ||
return Date.now() - startMs; | ||
} | ||
return endMs - startMs; | ||
}; | ||
@@ -48,3 +59,8 @@ | ||
then(cancelTimeout, cancelTimeout); | ||
var onEnded = function onEnded() { | ||
endMs = Date.now(); | ||
cancelTimeout(); | ||
}; | ||
then(onEnded, onEnded); | ||
return { | ||
@@ -51,0 +67,0 @@ allocateMs: allocateMs, |
"use strict"; | ||
var _test = require("../test.js"); | ||
var _testCheap = require("@dmail/test-cheap"); | ||
var _lolex = require("lolex"); | ||
var _action = require("../action.js"); | ||
@@ -9,7 +11,9 @@ | ||
(0, _test.test)("withAllocableMs.js", function (_ref) { | ||
var waitUntil = _ref.waitUntil, | ||
assert = _ref.assert; | ||
var done = waitUntil(); | ||
var _assertions = require("../assertions.js"); | ||
(0, _testCheap.test)("withAllocableMs.js", function (_ref) { | ||
var ensure = _ref.ensure; | ||
var clock = (0, _lolex.install)(); | ||
clock.tick(15); | ||
var createActionWithAllocableMs = function createActionWithAllocableMs() { | ||
@@ -19,31 +23,64 @@ return (0, _action.createAction)().mixin(_withAllocableMs.withAllocableMs); | ||
var actionPassedQuickly = createActionWithAllocableMs(); | ||
actionPassedQuickly.allocateMs(1); | ||
actionPassedQuickly.pass(); | ||
assert.equal(actionPassedQuickly.getState(), "passed"); | ||
var failedValue = 2; | ||
var actionFailedQuickly = createActionWithAllocableMs(); | ||
actionFailedQuickly.allocateMs(1); | ||
actionFailedQuickly.fail(failedValue); | ||
assert.equal(actionFailedQuickly.getState(), "failed"); | ||
assert.equal(actionFailedQuickly.getResult(), failedValue); | ||
var tooLongAction = createActionWithAllocableMs(); | ||
assert.equal(tooLongAction.getConsumedMs(), undefined); | ||
assert.equal(tooLongAction.getRemainingMs(), Infinity); | ||
assert.equal(tooLongAction.getAllocatedMs(), Infinity); | ||
tooLongAction.allocateMs(Infinity); | ||
assert.equal(tooLongAction.getAllocatedMs(), Infinity); | ||
tooLongAction.allocateMs(-1); | ||
assert.equal(tooLongAction.getAllocatedMs(), Infinity); | ||
tooLongAction.allocateMs(-2); | ||
assert.equal(tooLongAction.getAllocatedMs(), Infinity); | ||
tooLongAction.allocateMs(1); | ||
assert.equal(tooLongAction.getConsumedMs(), 0); | ||
assert.equal(tooLongAction.getRemainingMs(), 1); | ||
setTimeout(function () { | ||
assert.equal(tooLongAction.getState(), "failed"); | ||
assert.equal(tooLongAction.getResult(), "must pass or fail in less than 1ms"); | ||
done(); | ||
}, 20); | ||
ensure("an action passed fast enough", function () { | ||
var actionPassedQuickly = createActionWithAllocableMs(); | ||
actionPassedQuickly.allocateMs(1); | ||
actionPassedQuickly.pass(); | ||
_assertions.assert.equal(actionPassedQuickly.getState(), "passed"); | ||
}); | ||
ensure("an action failed fast enough", function () { | ||
var failedValue = 2; | ||
var actionFailedQuickly = createActionWithAllocableMs(); | ||
actionFailedQuickly.allocateMs(1); | ||
actionFailedQuickly.fail(failedValue); | ||
_assertions.assert.equal(actionFailedQuickly.getState(), "failed"); | ||
_assertions.assert.equal(actionFailedQuickly.getResult(), failedValue); | ||
}); | ||
ensure("an action still pending after allocatedMs", function () { | ||
var tooLongAction = createActionWithAllocableMs(); | ||
_assertions.assert.equal(tooLongAction.getConsumedMs(), undefined); | ||
_assertions.assert.equal(tooLongAction.getRemainingMs(), Infinity); | ||
_assertions.assert.equal(tooLongAction.getAllocatedMs(), Infinity); | ||
tooLongAction.allocateMs(Infinity); | ||
_assertions.assert.equal(tooLongAction.getAllocatedMs(), Infinity); | ||
tooLongAction.allocateMs(-1); | ||
_assertions.assert.equal(tooLongAction.getAllocatedMs(), Infinity); | ||
tooLongAction.allocateMs(-2); | ||
_assertions.assert.equal(tooLongAction.getAllocatedMs(), Infinity); | ||
var allocatedMs = 10; | ||
var consumedMs = 2; | ||
tooLongAction.allocateMs(allocatedMs); | ||
_assertions.assert.equal(tooLongAction.getConsumedMs(), 0); | ||
_assertions.assert.equal(tooLongAction.getRemainingMs(), allocatedMs); | ||
clock.tick(consumedMs); | ||
_assertions.assert.equal(tooLongAction.getConsumedMs(), consumedMs); | ||
_assertions.assert.equal(tooLongAction.getRemainingMs(), allocatedMs - consumedMs); | ||
clock.tick(allocatedMs - consumedMs); | ||
_assertions.assert.equal(tooLongAction.getConsumedMs(), allocatedMs); | ||
_assertions.assert.equal(tooLongAction.getState(), "failed"); | ||
_assertions.assert.equal(tooLongAction.getResult(), "must pass or fail in less than 10ms"); | ||
}); | ||
clock.uninstall(); | ||
}); | ||
//# sourceMappingURL=withAllocableMs.test.js.map |
{ | ||
"name": "@dmail/action", | ||
"version": "1.1.0", | ||
"licence": "MIT", | ||
"version": "1.2.0", | ||
"license": "MIT", | ||
"repository": { | ||
@@ -27,2 +27,3 @@ "type": "git", | ||
"@dmail/shared-config": "1.1.1", | ||
"@dmail/test-cheap": "0.0.2", | ||
"babel-cli": "7.0.0-beta.0", | ||
@@ -35,2 +36,3 @@ "babel-core": "7.0.0-beta.0", | ||
"eslint-plugin-import": "2.6.0", | ||
"lolex": "2.1.3", | ||
"nyc": "11.2.1", | ||
@@ -49,18 +51,3 @@ "prettier": "1.7.0", | ||
"test-before": "npm run code-lint && npm run code-format && npm run code-compile", | ||
"test-all": "node ./dist/src/all/all.test.js", | ||
"test-any": "node ./dist/src/any/any.test.js", | ||
"test-around-action": "node ./dist/src/aroundAction/aroundAction.test.js", | ||
"test-action": "node ./dist/src/action.test.js", | ||
"test-compose": "node ./dist/src/compose/compose.test.js", | ||
"test-compose-with-allocated-ms": "node ./dist/src/composeWithAllocatedMs/composeWithAllocatedMs.test.js", | ||
"test-failed": "node ./dist/src/failed/failed.test.js", | ||
"test-from-function": "node ./dist/src/fromFunction/fromFunction.test.js", | ||
"test-from-node-callback": "node ./dist/src/fromNodeCallback/fromNodeCallback.test.js", | ||
"test-from-node-callback-catching": "node ./dist/src/fromNodeCallbackCatching/fromNodeCallbackCatching.test.js", | ||
"test-from-promise": "node ./dist/src/fromPromise/fromPromise.test.js", | ||
"test-map-failed": "node ./dist/src/mapFailed/mapFailed.test.js", | ||
"test-passed": "node ./dist/src/passed/passed.test.js", | ||
"test-sequence": "node ./dist/src/sequence/sequence.test.js", | ||
"test-with-allocable-ms": "node ./dist/src/withAllocableMs/withAllocableMs.test.js", | ||
"test-run": "npm run test-action && npm run test-all && npm run test-any && npm run test-around-action && npm run test-compose && npm run test-compose-with-allocated-ms && npm run test-failed && npm run test-from-function && npm run test-from-node-callback && npm run test-from-node-callback-catching && npm run test-from-promise && npm run test-map-failed && npm run test-passed && npm run test-sequence && npm run test-with-allocable-ms", | ||
"test-run": "test-run", | ||
"test": "npm run test-before && npm run test-run", | ||
@@ -67,0 +54,0 @@ "test-cover": "npm run test-before && nyc npm run test-run", |
@@ -1,5 +0,6 @@ | ||
import { test } from "./test.js" | ||
import { test } from "@dmail/test-cheap" | ||
import { createAction } from "./action.js" | ||
import { assert, assertPassed, assertFailed, assertResult } from "./assertions.js" | ||
test("action.js", ({ ensure, assert, assertPassed, assertFailed, assertResult }) => { | ||
test("action.js", ({ ensure }) => { | ||
ensure("action.pass(itself) throw", () => { | ||
@@ -6,0 +7,0 @@ const action = createAction() |
@@ -1,6 +0,7 @@ | ||
import { test } from "../test.js" | ||
import { test } from "@dmail/test-cheap" | ||
import { createAction } from "../action.js" | ||
import { all } from "./all.js" | ||
import { assert, assertPassed, assertFailed, assertResult } from "../assertions.js" | ||
test("all.js", ({ ensure, assert, assertPassed, assertFailed, assertResult }) => { | ||
test("all.js", ({ ensure }) => { | ||
ensure("all with only values", () => { | ||
@@ -7,0 +8,0 @@ const firstValue = "foo" |
@@ -1,6 +0,7 @@ | ||
import { test } from "../test.js" | ||
import { test } from "@dmail/test-cheap" | ||
import { createAction } from "../action.js" | ||
import { any } from "./any.js" | ||
import { assertPassed, assertFailed, assertResult } from "../assertions.js" | ||
test("any.js", ({ ensure, assertPassed, assertFailed, assertResult }) => { | ||
test("any.js", ({ ensure }) => { | ||
ensure("any with only values", () => { | ||
@@ -7,0 +8,0 @@ const value = "a" |
@@ -1,6 +0,7 @@ | ||
import { test } from "../test.js" | ||
import { test } from "@dmail/test-cheap" | ||
import { createAction } from "../action.js" | ||
import { aroundAction } from "./aroundAction.js" | ||
import { assert, assertPassed, assertFailed, assertResult } from "../assertions.js" | ||
test("aroundAction.js", ({ ensure, assert, assertPassed, assertFailed, assertResult }) => { | ||
test("aroundAction.js", ({ ensure }) => { | ||
ensure("on passed action", () => { | ||
@@ -7,0 +8,0 @@ let beforeArgs |
@@ -1,2 +0,2 @@ | ||
import { test } from "../test.js" | ||
import { test } from "@dmail/test-cheap" | ||
import { createAction } from "../action.js" | ||
@@ -6,4 +6,5 @@ import { passed } from "../passed/passed.js" | ||
import { composeSequence, composeTogether } from "./compose.js" | ||
import { assert, assertPassed, assertFailed } from "../assertions.js" | ||
test("compose.js", ({ ensure, assert, assertPassed, assertFailed }) => { | ||
test("compose.js", ({ ensure }) => { | ||
ensure("composeSequence with values", () => { | ||
@@ -10,0 +11,0 @@ const action = composeSequence([0, 1]) |
import { passed } from "../passed/passed.js" | ||
import { fromFunction } from "../fromFunction/fromFunction.js" | ||
import { withAllocableMs } from "../withAllocableMs/withAllocableMs.js" | ||
@@ -11,12 +10,11 @@ import { composeSequence, composeTogether } from "../compose/compose.js" | ||
{ handle = defaultHandle, composer, allocatedMs = Infinity } | ||
) => | ||
fromFunction(action => { | ||
action.mixin(withAllocableMs) | ||
action.allocateMs(allocatedMs) | ||
return composer(iterable, (composedAction, value, index) => { | ||
composedAction.mixin(withAllocableMs) | ||
composedAction.allocateMs(action.getRemainingMs()) | ||
return handle(composedAction, value, index, iterable) | ||
}) | ||
) => { | ||
let previousAction | ||
return composer(iterable, (composedAction, value, index) => { | ||
composedAction.mixin(withAllocableMs) | ||
composedAction.allocateMs(index === 0 ? allocatedMs : previousAction.getRemainingMs()) | ||
previousAction = composedAction | ||
return handle(composedAction, value, index, iterable) | ||
}) | ||
} | ||
@@ -23,0 +21,0 @@ export const composeSequenceWithAllocatedMs = (iterable, handle, allocatedMs) => |
@@ -1,2 +0,2 @@ | ||
import { test } from "../test.js" | ||
import { test } from "@dmail/test-cheap" | ||
import { createAction, isAction } from "../action.js" | ||
@@ -7,29 +7,13 @@ import { | ||
} from "./composeWithAllocatedMs.js" | ||
import { assert } from "../assertions.js" | ||
test("composeWithAllocableMs.js", ({ ensure, assert }) => { | ||
ensure("by default compositeAction is given infinite ms", () => { | ||
const action = composeSequenceWithAllocatedMs([0]) | ||
assert.equal(action.getRemainingMs(), Infinity) | ||
}) | ||
ensure("compositeAction is given the allocatedMs", () => { | ||
const compositeAction = composeSequenceWithAllocatedMs([0], undefined, 10) | ||
const compositeActionRemainingMs = compositeAction.getRemainingMs() | ||
assert.equal(typeof compositeActionRemainingMs, "number") | ||
assert(compositeActionRemainingMs < 11) | ||
}) | ||
test("composeWithAllocableMs.js", ({ ensure }) => { | ||
ensure("each composed action is allocated the compositeAction remainingMs", () => { | ||
const firstAction = createAction() | ||
const secondAction = createAction() | ||
const compositeAction = composeSequenceWithAllocatedMs( | ||
[firstAction, secondAction], | ||
undefined, | ||
10 | ||
) | ||
composeSequenceWithAllocatedMs([firstAction, secondAction], undefined, 10) | ||
const firstActionRemainingMs = firstAction.getRemainingMs() | ||
let firstActionRemainingMs = firstAction.getRemainingMs() | ||
assert.equal(typeof firstActionRemainingMs, "number") | ||
assert(firstActionRemainingMs <= compositeAction.getRemainingMs()) | ||
assert(firstActionRemainingMs <= 10) | ||
@@ -41,3 +25,4 @@ assert.equal(secondAction.getRemainingMs, undefined) // because first action is running | ||
assert.equal(typeof secondActionRemainingMs, "number") | ||
assert(secondActionRemainingMs <= compositeAction.getRemainingMs()) | ||
firstActionRemainingMs = firstAction.getRemainingMs() | ||
assert(secondActionRemainingMs <= firstActionRemainingMs) | ||
}) | ||
@@ -44,0 +29,0 @@ |
@@ -1,6 +0,7 @@ | ||
import { test } from "../test.js" | ||
import { test } from "@dmail/test-cheap" | ||
import { passed } from "../passed/passed.js" | ||
import { failed } from "./failed.js" | ||
import { assert, assertFailed, assertResult } from "../assertions.js" | ||
test("failed.js", ({ ensure, assert, assertFailed, assertResult }) => { | ||
test("failed.js", ({ ensure }) => { | ||
ensure("failed return an action failed with the value", () => { | ||
@@ -7,0 +8,0 @@ const value = 1 |
@@ -1,5 +0,6 @@ | ||
import { test } from "../test.js" | ||
import { test } from "@dmail/test-cheap" | ||
import { fromFunction } from "./fromFunction.js" | ||
import { assert, assertPassed, assertFailed, assertResult } from "../assertions.js" | ||
test("fromFunction.js", ({ ensure, assert, assertPassed, assertFailed, assertResult }) => { | ||
test("fromFunction.js", ({ ensure }) => { | ||
ensure("function returning resolved thenable pass action", () => { | ||
@@ -6,0 +7,0 @@ const value = 1 |
@@ -1,5 +0,6 @@ | ||
import { test } from "../test.js" | ||
import { test } from "@dmail/test-cheap" | ||
import { fromNodeCallback } from "./fromNodeCallback.js" | ||
import { assert, assertPassed, assertResult } from "../assertions.js" | ||
test("fromNodeCallback.js", ({ ensure, assert, assertPassed, assertResult }) => { | ||
test("fromNodeCallback.js", ({ ensure }) => { | ||
const nodeCallbackError = (error, callback) => callback(error) | ||
@@ -6,0 +7,0 @@ const nodeCallbackSuccess = (value, callback) => callback(null, value) |
@@ -1,5 +0,6 @@ | ||
import { test } from "../test.js" | ||
import { test } from "@dmail/test-cheap" | ||
import { fromNodeCallbackCatching } from "./fromNodeCallbackCatching.js" | ||
import { assert, assertPassed, assertResult } from "../assertions.js" | ||
test("fromNodeCallbackCatching.js", ({ ensure, assert, assertPassed, assertResult }) => { | ||
test("fromNodeCallbackCatching.js", ({ ensure }) => { | ||
const nodeCallbackError = (error, callback) => callback(error) | ||
@@ -6,0 +7,0 @@ const nodeCallbackSuccess = (value, callback) => callback(null, value) |
@@ -1,5 +0,6 @@ | ||
import { test } from "../test.js" | ||
import { test } from "@dmail/test-cheap" | ||
import { fromPromise } from "./fromPromise.js" | ||
import { assert } from "../assertions.js" | ||
test("fromPromise.js", ({ assert, waitUntil }) => { | ||
test("fromPromise.js", ({ waitUntil }) => { | ||
const done = waitUntil() | ||
@@ -6,0 +7,0 @@ |
@@ -1,6 +0,7 @@ | ||
import { test } from "../test.js" | ||
import { test } from "@dmail/test-cheap" | ||
import { createAction } from "../action.js" | ||
import { mapFailed } from "./mapFailed.js" | ||
import { assert, assertFailed, assertResult } from "../assertions.js" | ||
test("mapFailed.js", ({ ensure, assert, assertFailed, assertResult }) => { | ||
test("mapFailed.js", ({ ensure }) => { | ||
ensure("transforms failure value", () => { | ||
@@ -7,0 +8,0 @@ const action = createAction() |
@@ -1,6 +0,7 @@ | ||
import { test } from "../test.js" | ||
import { test } from "@dmail/test-cheap" | ||
import { failed } from "../failed/failed.js" | ||
import { passed } from "./passed.js" | ||
import { assert, assertPassed, assertResult } from "../assertions.js" | ||
test("passed.js", ({ ensure, assert, assertPassed, assertResult }) => { | ||
test("passed.js", ({ ensure }) => { | ||
ensure("passed return an action passed with the value", () => { | ||
@@ -7,0 +8,0 @@ const value = 1 |
@@ -1,6 +0,7 @@ | ||
import { test } from "../test.js" | ||
import { test } from "@dmail/test-cheap" | ||
import { createAction } from "../action.js" | ||
import { sequence } from "./sequence.js" | ||
import { assert, assertPassed, assertFailed, assertResult } from "../assertions.js" | ||
test("sequence.js", ({ ensure, assert, assertPassed, assertFailed, assertResult }) => { | ||
test("sequence.js", ({ ensure }) => { | ||
ensure("with only values", () => { | ||
@@ -7,0 +8,0 @@ const firstValue = "foo" |
@@ -5,2 +5,3 @@ export const withAllocableMs = ({ fail, then }) => { | ||
let startMs | ||
let endMs | ||
const cancelTimeout = () => { | ||
@@ -14,2 +15,4 @@ if (timeoutid !== undefined) { | ||
allocatedMs = ms < 0 ? Infinity : ms | ||
startMs = undefined | ||
endMs = undefined | ||
cancelTimeout() | ||
@@ -24,8 +27,20 @@ if (ms !== Infinity) { | ||
} | ||
const getConsumedMs = () => (startMs === undefined ? undefined : Date.now() - startMs) | ||
const getConsumedMs = () => { | ||
if (startMs === undefined) { | ||
return undefined | ||
} | ||
if (endMs === undefined) { | ||
return Date.now() - startMs | ||
} | ||
return endMs - startMs | ||
} | ||
const getAllocatedMs = () => allocatedMs | ||
const getRemainingMs = () => (allocatedMs === Infinity ? Infinity : allocatedMs - getConsumedMs()) | ||
then(cancelTimeout, cancelTimeout) | ||
const onEnded = () => { | ||
endMs = Date.now() | ||
cancelTimeout() | ||
} | ||
then(onEnded, onEnded) | ||
return { allocateMs, getAllocatedMs, getConsumedMs, getRemainingMs } | ||
} |
@@ -1,42 +0,60 @@ | ||
import { test } from "../test.js" | ||
import { test } from "@dmail/test-cheap" | ||
import { install } from "lolex" | ||
import { createAction } from "../action.js" | ||
import { withAllocableMs } from "./withAllocableMs.js" | ||
import { assert } from "../assertions.js" | ||
test("withAllocableMs.js", ({ waitUntil, assert }) => { | ||
const done = waitUntil() | ||
test("withAllocableMs.js", ({ ensure }) => { | ||
const clock = install() | ||
clock.tick(15) | ||
const createActionWithAllocableMs = () => createAction().mixin(withAllocableMs) | ||
const actionPassedQuickly = createActionWithAllocableMs() | ||
actionPassedQuickly.allocateMs(1) | ||
actionPassedQuickly.pass() | ||
assert.equal(actionPassedQuickly.getState(), "passed") | ||
ensure("an action passed fast enough", () => { | ||
const actionPassedQuickly = createActionWithAllocableMs() | ||
actionPassedQuickly.allocateMs(1) | ||
actionPassedQuickly.pass() | ||
assert.equal(actionPassedQuickly.getState(), "passed") | ||
}) | ||
const failedValue = 2 | ||
const actionFailedQuickly = createActionWithAllocableMs() | ||
actionFailedQuickly.allocateMs(1) | ||
actionFailedQuickly.fail(failedValue) | ||
assert.equal(actionFailedQuickly.getState(), "failed") | ||
assert.equal(actionFailedQuickly.getResult(), failedValue) | ||
ensure("an action failed fast enough", () => { | ||
const failedValue = 2 | ||
const actionFailedQuickly = createActionWithAllocableMs() | ||
actionFailedQuickly.allocateMs(1) | ||
actionFailedQuickly.fail(failedValue) | ||
assert.equal(actionFailedQuickly.getState(), "failed") | ||
assert.equal(actionFailedQuickly.getResult(), failedValue) | ||
}) | ||
const tooLongAction = createActionWithAllocableMs() | ||
assert.equal(tooLongAction.getConsumedMs(), undefined) | ||
assert.equal(tooLongAction.getRemainingMs(), Infinity) | ||
assert.equal(tooLongAction.getAllocatedMs(), Infinity) | ||
ensure("an action still pending after allocatedMs", () => { | ||
const tooLongAction = createActionWithAllocableMs() | ||
assert.equal(tooLongAction.getConsumedMs(), undefined) | ||
assert.equal(tooLongAction.getRemainingMs(), Infinity) | ||
assert.equal(tooLongAction.getAllocatedMs(), Infinity) | ||
tooLongAction.allocateMs(Infinity) | ||
assert.equal(tooLongAction.getAllocatedMs(), Infinity) | ||
tooLongAction.allocateMs(-1) | ||
assert.equal(tooLongAction.getAllocatedMs(), Infinity) | ||
tooLongAction.allocateMs(-2) | ||
assert.equal(tooLongAction.getAllocatedMs(), Infinity) | ||
tooLongAction.allocateMs(Infinity) | ||
assert.equal(tooLongAction.getAllocatedMs(), Infinity) | ||
tooLongAction.allocateMs(-1) | ||
assert.equal(tooLongAction.getAllocatedMs(), Infinity) | ||
tooLongAction.allocateMs(-2) | ||
assert.equal(tooLongAction.getAllocatedMs(), Infinity) | ||
tooLongAction.allocateMs(1) | ||
assert.equal(tooLongAction.getConsumedMs(), 0) | ||
assert.equal(tooLongAction.getRemainingMs(), 1) | ||
const allocatedMs = 10 | ||
const consumedMs = 2 | ||
setTimeout(() => { | ||
tooLongAction.allocateMs(allocatedMs) | ||
assert.equal(tooLongAction.getConsumedMs(), 0) | ||
assert.equal(tooLongAction.getRemainingMs(), allocatedMs) | ||
clock.tick(consumedMs) | ||
assert.equal(tooLongAction.getConsumedMs(), consumedMs) | ||
assert.equal(tooLongAction.getRemainingMs(), allocatedMs - consumedMs) | ||
clock.tick(allocatedMs - consumedMs) | ||
assert.equal(tooLongAction.getConsumedMs(), allocatedMs) | ||
assert.equal(tooLongAction.getState(), "failed") | ||
assert.equal(tooLongAction.getResult(), `must pass or fail in less than 1ms`) | ||
done() | ||
}, 20) | ||
assert.equal(tooLongAction.getResult(), `must pass or fail in less than 10ms`) | ||
}) | ||
clock.uninstall() | ||
}) |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
179318
16
103
2861