Socket
Socket
Sign inDemoInstall

effects-as-data

Package Overview
Dependencies
Maintainers
1
Versions
155
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

effects-as-data - npm Package Compare versions

Comparing version 2.5.10 to 2.6.0

LICENSE

43

es5/index.js

@@ -9,4 +9,2 @@ 'use strict';

function call(config, handlers, fn) {
if (!fn) return Promise.reject(new Error('A function is required.'));
for (var _len = arguments.length, args = Array(_len > 3 ? _len - 3 : 0), _key = 3; _key < _len; _key++) {

@@ -16,5 +14,10 @@ args[_key - 3] = arguments[_key];

if (!fn) return Promise.reject(new Error('A function is required.'));
var gen = fn.apply(null, args);
var el = newExecutionLog();
return run(config, handlers, gen, null, el);
onCall({ args: args, fn: fn, config: config });
return run(config, handlers, gen, null, el).then(function (result) {
onComplete({ result: result, config: config });
return result;
});
}

@@ -90,3 +93,3 @@

var end = Date.now();
report({
onCommandComplete({
success: true,

@@ -104,3 +107,3 @@ config: config,

var end = Date.now();
report({
onCommandComplete({
success: false,

@@ -119,3 +122,3 @@ config: config,

function report(_ref) {
function onCommandComplete(_ref) {
var success = _ref.success,

@@ -130,3 +133,3 @@ command = _ref.command,

if (!config.onCommandComplete) return;
if (!config.onCommandComplete || typeof config.onCommandComplete !== 'function') return;
var r = {

@@ -146,2 +149,28 @@ success: success,

function onCall(_ref2) {
var args = _ref2.args,
fn = _ref2.fn,
config = _ref2.config;
if (!config.onCall || typeof config.onCall !== 'function') return;
var r = {
args: args,
fn: fn,
config: config
};
config.onCall(r);
}
function onComplete(_ref3) {
var result = _ref3.result,
config = _ref3.config;
if (!config.onComplete || typeof config.onComplete !== 'function') return;
var r = {
result: result,
config: config
};
config.onComplete(r);
}
function buildFunctions(config, handlers, functions) {

@@ -148,0 +177,0 @@ var promiseFunctions = {};

@@ -12,3 +12,4 @@ 'use strict';

var basicMultistep = functions.basicMultistep,
badHandler = functions.badHandler;
badHandler = functions.badHandler,
basic = functions.basic;

@@ -18,3 +19,3 @@ var _require3 = require('./test-util'),

test('telemetry', async function () {
test('telemetry - onCommandComplete', async function () {
var telemetry = [];

@@ -42,3 +43,3 @@ var onCommandComplete = function onCommandComplete(t) {

test('telemetry on error', async function () {
test('telemetry on error - onCommandComplete', async function () {
var telemetry = void 0;

@@ -48,3 +49,3 @@ var onCommandComplete = function onCommandComplete(t) {

};
var config = { onCommandComplete: onCommandComplete, name: 'telemetry' };
var config = { onCommandComplete: onCommandComplete };
var now = Date.now();

@@ -66,2 +67,22 @@ var message = 'oops';

});
test('onCall', async function () {
var called = void 0;
var onCall = function onCall(t) {
called = t;
};
var config = { onCall: onCall };
await call(config, handlers, basicMultistep, 'foo', 'bar', 'baz');
expect(called.args).toEqual(['foo', 'bar', 'baz']);
});
test('onComplete', async function () {
var complete = void 0;
var onComplete = function onComplete(t) {
complete = t;
};
var config = { onComplete: onComplete, name: 'telemetry' };
await call(config, handlers, basic, 'foo');
expect(complete.result).toEqual('foo');
});
//# sourceMappingURL=telemetry.spec.js.map

195

es5/specs/test.spec.js

@@ -1,6 +0,6 @@

'use strict';
"use strict";
var _marked = [singleLine, yieldArray].map(regeneratorRuntime.mark);
var _marked = [singleLine, yieldArray, returnCmdResult, throwSemantic].map(regeneratorRuntime.mark);
var _require = require('./effects'),
var _require = require("./effects"),
functions = _require.functions,

@@ -20,3 +20,3 @@ cmds = _require.cmds;

var _require2 = require('../test'),
var _require2 = require("../test"),
testFn = _require2.testFn,

@@ -33,10 +33,10 @@ testFnV2 = _require2.testFnV2,

_context.next = 2;
return cmds.httpGet('http://example.com/api/v1/users/' + id);
return cmds.httpGet("http://example.com/api/v1/users/" + id);
case 2:
s1 = _context.sent;
return _context.abrupt('return', s1);
return _context.abrupt("return", s1);
case 4:
case 'end':
case "end":
return _context.stop();

@@ -55,10 +55,10 @@ }

_context2.next = 2;
return [{ type: 'test' }];
return [{ type: "test" }];
case 2:
s1 = _context2.sent;
return _context2.abrupt('return', s1);
return _context2.abrupt("return", s1);
case 4:
case 'end':
case "end":
return _context2.stop();

@@ -73,3 +73,3 @@ }

test('testFn should handle undefined returns for semantic test', testFn(regeneratorRuntime.mark(function _callee() {
test("testFn should handle undefined returns for semantic test", testFn(regeneratorRuntime.mark(function _callee() {
return regeneratorRuntime.wrap(function _callee$(_context3) {

@@ -79,3 +79,3 @@ while (1) {

case 0:
case 'end':
case "end":
return _context3.stop();

@@ -89,3 +89,3 @@ }

test('testFn should curry', testFn(basic)(function () {
test("testFn should curry", testFn(basic)(function () {
// prettier-ignore

@@ -95,3 +95,3 @@ return [[['foo'], cmds.echo('foo')], ['foo', 'foo']];

test('testFn should pass (basic)', testFn(basic, function () {
test("testFn should pass (basic)", testFn(basic, function () {
// prettier-ignore

@@ -103,3 +103,3 @@ return [[['foo'], cmds.echo('foo')], ['foo', 'foo']];

test('testFn semantic should pass (basic)', testFn(basic, function () {
test("testFn semantic should pass (basic)", testFn(basic, function () {
// prettier-ignore

@@ -109,3 +109,3 @@ return args('foo').yieldCmd(cmds.echo('foo')).yieldReturns('foo').returns('foo');

test('testFnV2 should pass (basic)', testFnV2(basic, function () {
test("testFnV2 should pass (basic)", testFnV2(basic, function () {
// prettier-ignore

@@ -115,3 +115,3 @@ return [['foo'], [cmds.echo('foo'), 'foo'], 'foo'];

test('testFn should pass (basicMultiArg)', testFn(basicMultiArg, function () {
test("testFn should pass (basicMultiArg)", testFn(basicMultiArg, function () {
// prettier-ignore

@@ -123,3 +123,3 @@ return [[['foo', 'bar'], cmds.echo('foobar')], ['foobar', 'foobar']];

test('testFn should pass (basicMultiArg)', testFn(basicMultiArg, function () {
test("testFn should pass (basicMultiArg)", testFn(basicMultiArg, function () {
// prettier-ignore

@@ -129,3 +129,3 @@ return [[['foo', 'bar'], cmds.echo('foobar')], ['foobar', 'foobar']];

test('testFn semantic should pass (basicMultiArg)', testFn(basicMultiArg, function () {
test("testFn semantic should pass (basicMultiArg)", testFn(basicMultiArg, function () {
// prettier-ignore

@@ -135,3 +135,3 @@ return args('foo', 'bar').yieldCmd(cmds.echo('foobar')).yieldReturns('foobar').returns('foobar');

test('testFn semantic should pass (basicMultiArg)', testFnV2(basicMultiArg, function () {
test("testFn semantic should pass (basicMultiArg)", testFnV2(basicMultiArg, function () {
// prettier-ignore

@@ -143,3 +143,3 @@ return [['foo', 'bar'], [cmds.echo('foobar'), 'foobar'], 'foobar'];

test('testFn should pass (basicMultistep)', testFn(basicMultistep, function () {
test("testFn should pass (basicMultistep)", testFn(basicMultistep, function () {
// prettier-ignore

@@ -149,3 +149,3 @@ return [[['foo'], cmds.echo('foo1')], ['foo1', cmds.echo('foo2')], ['foo2', { s1: 'foo1', s2: 'foo2' }]];

test('testFn semantic should pass (basicMultistep)', testFn(basicMultistep, function () {
test("testFn semantic should pass (basicMultistep)", testFn(basicMultistep, function () {
// prettier-ignore

@@ -155,3 +155,3 @@ return args('foo').yieldCmd(cmds.echo('foo1')).yieldReturns('foo1').yieldCmd(cmds.echo('foo2')).yieldReturns('foo2').returns({ s1: 'foo1', s2: 'foo2' });

test('testFnV2 should pass (basicMultistep)', testFnV2(basicMultistep, function () {
test("testFnV2 should pass (basicMultistep)", testFnV2(basicMultistep, function () {
// prettier-ignore

@@ -163,4 +163,4 @@ return [['foo'], [cmds.echo('foo1'), 'foo1'], [cmds.echo('foo2'), 'foo2'], { s1: 'foo1', s2: 'foo2' }];

test('testFn should pass (basicParallel)', testFn(basicParallel, function () {
var c = [cmds.echo('foo'), cmds.echo('foo')];
test("testFn should pass (basicParallel)", testFn(basicParallel, function () {
var c = [cmds.echo("foo"), cmds.echo("foo")];
// prettier-ignore

@@ -170,4 +170,4 @@ return [[['foo'], c], [['foo', 'foo'], { s1: 'foo1', s2: 'foo2' }]];

test('testFn semantic should pass (basicParallel)', testFn(basicParallel, function () {
var c = [cmds.echo('foo'), cmds.echo('foo')];
test("testFn semantic should pass (basicParallel)", testFn(basicParallel, function () {
var c = [cmds.echo("foo"), cmds.echo("foo")];
// prettier-ignore

@@ -177,4 +177,4 @@ return args('foo').yieldCmd(c).yieldReturns(['foo', 'foo']).returns({ s1: 'foo1', s2: 'foo2' });

test('testFnV2 should pass (basicParallel)', testFnV2(basicParallel, function () {
var c = [cmds.echo('foo'), cmds.echo('foo')];
test("testFnV2 should pass (basicParallel)", testFnV2(basicParallel, function () {
var c = [cmds.echo("foo"), cmds.echo("foo")];
// prettier-ignore

@@ -186,5 +186,5 @@ return [['foo'], [c, ['foo', 'foo']], { s1: 'foo1', s2: 'foo2' }];

test('testFn should pass (basicMultistepParallel)', testFn(basicMultistepParallel, function () {
var c1 = [cmds.echo('foo'), cmds.echo('foo')];
var c2 = [cmds.echo('foo'), cmds.echo('foo')];
test("testFn should pass (basicMultistepParallel)", testFn(basicMultistepParallel, function () {
var c1 = [cmds.echo("foo"), cmds.echo("foo")];
var c2 = [cmds.echo("foo"), cmds.echo("foo")];
// prettier-ignore

@@ -194,5 +194,5 @@ return [[['foo'], c1], [['foo', 'foo'], c2], [['foo', 'foo'], { s1: 'foo1', s2: 'foo2', s3: 'foo3', s4: 'foo4' }]];

test('testFn semantic should pass (basicMultistepParallel)', testFn(basicMultistepParallel, function () {
var c1 = [cmds.echo('foo'), cmds.echo('foo')];
var c2 = [cmds.echo('foo'), cmds.echo('foo')];
test("testFn semantic should pass (basicMultistepParallel)", testFn(basicMultistepParallel, function () {
var c1 = [cmds.echo("foo"), cmds.echo("foo")];
var c2 = [cmds.echo("foo"), cmds.echo("foo")];
// prettier-ignore

@@ -202,5 +202,5 @@ return args('foo').yieldCmd(c1).yieldReturns(['foo', 'foo']).yieldCmd(c2).yieldReturns(['foo', 'foo']).returns({ s1: 'foo1', s2: 'foo2', s3: 'foo3', s4: 'foo4' });

test('testFnV2 should pass (basicMultistepParallel)', testFnV2(basicMultistepParallel, function () {
var c1 = [cmds.echo('foo'), cmds.echo('foo')];
var c2 = [cmds.echo('foo'), cmds.echo('foo')];
test("testFnV2 should pass (basicMultistepParallel)", testFnV2(basicMultistepParallel, function () {
var c1 = [cmds.echo("foo"), cmds.echo("foo")];
var c2 = [cmds.echo("foo"), cmds.echo("foo")];
// prettier-ignore

@@ -212,3 +212,3 @@ return [['foo'], [c1, ['foo', 'foo']], [c2, ['foo', 'foo']], { s1: 'foo1', s2: 'foo2', s3: 'foo3', s4: 'foo4' }];

test('testFn should pass (basicEmpty)', testFn(basicEmpty, function () {
test("testFn should pass (basicEmpty)", testFn(basicEmpty, function () {
// prettier-ignore

@@ -218,3 +218,3 @@ return [[[null], []], [[], []]];

test('testFn semantic should pass (basicEmpty)', testFn(basicEmpty, function () {
test("testFn semantic should pass (basicEmpty)", testFn(basicEmpty, function () {
// prettier-ignore

@@ -224,3 +224,3 @@ return args(null).yieldCmd([]).yieldReturns([]).returns([]);

test('testFnV2 should pass (basicEmpty)', testFnV2(basicEmpty, function () {
test("testFnV2 should pass (basicEmpty)", testFnV2(basicEmpty, function () {
// prettier-ignore

@@ -232,3 +232,3 @@ return [[null], [[], []], []];

test('testFn should pass (eitherTestError)', testFn(eitherTestError, function () {
test("testFn should pass (eitherTestError)", testFn(eitherTestError, function () {
// prettier-ignore

@@ -238,3 +238,3 @@ return [[[null], cmds.either(cmds.die('oops'), 'foo')], ['foo', 'foo']];

test('testFn semantic should pass (eitherTestError)', testFn(eitherTestError, function () {
test("testFn semantic should pass (eitherTestError)", testFn(eitherTestError, function () {
// prettier-ignore

@@ -244,3 +244,3 @@ return args(null).yieldCmd(cmds.either(cmds.die('oops'), 'foo')).yieldReturns('foo').returns('foo');

test('testFnV2 semantic should pass (eitherTestError)', testFnV2(eitherTestError, function () {
test("testFnV2 semantic should pass (eitherTestError)", testFnV2(eitherTestError, function () {
// prettier-ignore

@@ -252,3 +252,3 @@ return [[null], [cmds.either(cmds.die('oops'), 'foo'), 'foo'], 'foo'];

test('testFn should handle errors (badHandler)', testFn(badHandler, function () {
test("testFn should handle errors (badHandler)", testFn(badHandler, function () {
// prettier-ignore

@@ -258,3 +258,3 @@ return [[[null], cmds.die('oops')], [new Error('oops!'), new Error('oops!')]];

test('testFn semantic should handle errors (badHandler)', testFn(badHandler, function () {
test("testFn semantic should handle errors (badHandler)", testFn(badHandler, function () {
// prettier-ignore

@@ -264,4 +264,9 @@ return args([null]).yieldCmd(cmds.die('oops')).yieldReturns(new Error('oops!')).returns(new Error('oops!'));

test('testFnV2 should handle errors (badHandler)', testFnV2(badHandler, function () {
test("testFn semantic should handle errors without returns (badHandler)", testFn(badHandler, function () {
// prettier-ignore
return args([null]).yieldCmd(cmds.die('oops')).throws(new Error('oops!'));
}));
test("testFnV2 should handle errors (badHandler)", testFnV2(badHandler, function () {
// prettier-ignore
return [[null], [cmds.die('oops'), new Error('oops!')], new Error('oops!')];

@@ -272,3 +277,3 @@ }));

test('testFn should pass (eitherTestEmpty)', testFn(eitherTestEmpty, function () {
test("testFn should pass (eitherTestEmpty)", testFn(eitherTestEmpty, function () {
// prettier-ignore

@@ -278,3 +283,3 @@ return [[[null], cmds.either(cmds.echo(null), 'foo')], ['foo', 'foo']];

test('testFn semantic should pass (eitherTestEmpty)', testFn(eitherTestEmpty, function () {
test("testFn semantic should pass (eitherTestEmpty)", testFn(eitherTestEmpty, function () {
// prettier-ignore

@@ -284,3 +289,3 @@ return args(null).yieldCmd(cmds.either(cmds.echo(null), 'foo')).yieldReturns('foo').returns('foo');

test('testFnV2 should pass (eitherTestEmpty)', testFnV2(eitherTestEmpty, function () {
test("testFnV2 should pass (eitherTestEmpty)", testFnV2(eitherTestEmpty, function () {
// prettier-ignore

@@ -292,3 +297,3 @@ return [[null], [cmds.either(cmds.echo(null), 'foo'), 'foo'], 'foo'];

test('testFn should pass (asyncTest)', testFn(asyncTest, function () {
test("testFn should pass (asyncTest)", testFn(asyncTest, function () {
// prettier-ignore

@@ -298,3 +303,3 @@ return [[[null], cmds.async({ type: 'test' })], [null, null]];

test('testFn semantic should pass (asyncTest)', testFn(asyncTest, function () {
test("testFn semantic should pass (asyncTest)", testFn(asyncTest, function () {
// prettier-ignore

@@ -304,3 +309,3 @@ return args(null).yieldCmd(cmds.async({ type: 'test' })).yieldReturns(null).returns(null);

test('testFnV2 should pass (asyncTest)', testFnV2(asyncTest, function () {
test("testFnV2 should pass (asyncTest)", testFnV2(asyncTest, function () {
// prettier-ignore

@@ -310,5 +315,73 @@ return [[null], [cmds.async({ type: 'test' }), null], null];

// Return cmd result
// Throw from semantic test builder
function returnCmdResult() {
return regeneratorRuntime.wrap(function returnCmdResult$(_context4) {
while (1) {
switch (_context4.prev = _context4.next) {
case 0:
_context4.next = 2;
return cmds.echo("foo");
case 2:
return _context4.abrupt("return", _context4.sent);
case 3:
case "end":
return _context4.stop();
}
}
}, _marked[2], this);
}
test("testFn semantic should return cmd result", testFn(returnCmdResult, function () {
// prettier-ignore
return args().yieldCmd(cmds.echo('foo')).returns("foo");
}));
// Throw from semantic test builder
function throwSemantic() {
var value;
return regeneratorRuntime.wrap(function throwSemantic$(_context5) {
while (1) {
switch (_context5.prev = _context5.next) {
case 0:
_context5.next = 2;
return cmds.echo("foo");
case 2:
value = _context5.sent;
throw new Error("oops");
case 4:
case "end":
return _context5.stop();
}
}
}, _marked[3], this);
}
test("testFn semantic should throw if .throws is used", testFn(throwSemantic, function () {
// prettier-ignore
return args().yieldCmd(cmds.echo('foo')).yieldReturns('foo').throws(new Error("oops"));
}));
test("testFn should throw proper error if function throws incorrect error", function () {
try {
testFn(throwSemantic, function () {
// prettier-ignore
return args().yieldCmd(cmds.echo('foo')).yieldReturns('foo').throws(new Error("wrong"));
})();
} catch (e) {
expect(e.name).toEqual("Error on Step 2");
return;
}
fail("Did not throw");
});
// Single line
test('single line should pass', testSingleLine(function () {
test("single line should pass", testSingleLine(function () {
// prettier-ignore

@@ -318,3 +391,3 @@ return [[['123'], cmds.httpGet('http://example.com/api/v1/users/123')], [{ foo: 'bar' }, { foo: 'bar' }]];

test('testFn semantic single line should not fail', testSingleLine(function () {
test("testFn semantic single line should not fail", testSingleLine(function () {
// prettier-ignore

@@ -324,3 +397,3 @@ return args('123').yieldCmd(cmds.httpGet('http://example.com/api/v1/users/123')).yieldReturns({ foo: 'bar' }).returns({ foo: 'bar' });

test('testFn should give proper error message if yielding array but no results', function () {
test("testFn should give proper error message if yielding array but no results", function () {
try {

@@ -332,7 +405,7 @@ testYieldArray(function () {

} catch (e) {
expect(e.message).toEqual('Your spec does not have as many steps as your function. Are you missing a return line?');
expect(e.message).toEqual("Your spec does not have as many steps as your function. Are you missing a return line?");
}
});
test('testFn should give proper error message if spec is returning undefined', function () {
test("testFn should give proper error message if spec is returning undefined", function () {
try {

@@ -345,3 +418,3 @@ testYieldArray(function () {})();

test('testFn should give proper error message if spec is returning an object', function () {
test("testFn should give proper error message if spec is returning an object", function () {
try {

@@ -356,6 +429,6 @@ testYieldArray(function () {

test('testFn should give proper error message if spec is returning an string', function () {
test("testFn should give proper error message if spec is returning an string", function () {
try {
testYieldArray(function () {
return 'what?';
return "what?";
})();

@@ -362,0 +435,0 @@ } catch (e) {

@@ -1,2 +0,2 @@

'use strict';
"use strict";

@@ -7,5 +7,5 @@ var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };

var assert = require('assert');
var curry = require('lodash/curry');
var chunk = require('lodash/chunk');
var assert = require("assert");
var curry = require("lodash/curry");
var chunk = require("lodash/chunk");

@@ -18,3 +18,3 @@ var testRunner = function testRunner(fn, expected) {

assert(fn, 'The function you are trying to test is undefined.');
assert(fn, "The function you are trying to test is undefined.");

@@ -24,3 +24,3 @@ var step = expected[index];

if (step === undefined) {
throw new Error('Your spec does not have as many steps as your function. Are you missing a return line?');
throw new Error("Your spec does not have as many steps as your function. Are you missing a return line?");
}

@@ -47,9 +47,16 @@

} else {
output = g.next(input);
try {
output = g.next(input);
} catch (e) {
output = { value: e, done: true };
}
}
var endOnError = isError(output.value);
try {
deepEqual(output.value, expectedOutput);
if (endOnError) return;
} catch (e) {
e.name = 'Error on Step ' + (index + 1);
e.name = "Error on Step " + (index + 1);
throw e;

@@ -70,3 +77,3 @@ }

if (!Array.isArray(expected)) {
throw new Error('Your spec must return an array of tuples. It is currently returning a value of type "' + (typeof expected === 'undefined' ? 'undefined' : _typeof(expected)) + '".');
throw new Error("Your spec must return an array of tuples. It is currently returning a value of type \"" + (typeof expected === "undefined" ? "undefined" : _typeof(expected)) + "\".");
}

@@ -79,3 +86,3 @@ for (var i = 0; i < expected.length; i++) {

if (Array.isArray(output)) {
assert(Array.isArray(nextInput), 'If an array of actions is yielded, it should return an array of results.');
assert(Array.isArray(nextInput), "If an array of actions is yielded, it should return an array of results.");
}

@@ -112,3 +119,3 @@ }

// a little bit of jest support
if (typeof expect !== 'undefined' && expect.extend && expect.anything) {
if (typeof expect !== "undefined" && expect.extend && expect.anything) {
expect(actual).toEqual(expected);

@@ -134,3 +141,5 @@ } else {

return {
yieldReturns: yieldReturns(t)
yieldReturns: yieldReturns(t),
throws: yieldReturnThrows(t),
returns: returnCmdResult(t)
};

@@ -146,2 +155,3 @@ };

yieldCmd: yieldCmd(t),
throws: throwAfterCmdReturns(t),
returns: returns(t)

@@ -152,2 +162,23 @@ };

var returnCmdResult = function returnCmdResult(t) {
return function (v) {
t[t.length] = [v, v];
return t;
};
};
var yieldReturnThrows = function yieldReturnThrows(t) {
return function (v) {
t[t.length] = [v, v];
return t;
};
};
var throwAfterCmdReturns = function throwAfterCmdReturns(t) {
return function (v) {
t[t.length - 1][1] = v;
return t;
};
};
var returns = function returns(t) {

@@ -154,0 +185,0 @@ return function (a) {

{
"name": "effects-as-data",
"version": "2.5.10",
"version": "2.6.0",
"description": "A micro abstraction layer for Javascript that makes writing, testing, and monitoring side-effects easy.",

@@ -5,0 +5,0 @@ "main": "src/index.js",

@@ -9,2 +9,3 @@ # Effects-as-data

* Effects-as-data has *almost* no performance overhead (see `npm run perf`).
* Anywhere you can use promises, you can use effects-as-data.

@@ -11,0 +12,0 @@ ## Effects-as-data by example

@@ -7,3 +7,7 @@ const { isGenerator, toArray, toPromise } = require('./util')

const el = newExecutionLog()
return run(config, handlers, gen, null, el)
onCall({ args, fn, config })
return run(config, handlers, gen, null, el).then(result => {
onComplete({ result, config })
return result
})
}

@@ -71,3 +75,3 @@

const end = Date.now()
report({
onCommandComplete({
success: true,

@@ -86,3 +90,3 @@ config,

const end = Date.now()
report({
onCommandComplete({
success: false,

@@ -101,4 +105,4 @@ config,

function report({ success, command, index, step, result, config, start, end }) {
if (!config.onCommandComplete) return
function onCommandComplete({ success, command, index, step, result, config, start, end }) {
if (!config.onCommandComplete || typeof config.onCommandComplete !== 'function') return
const r = {

@@ -118,2 +122,21 @@ success,

function onCall({ args, fn, config }) {
if (!config.onCall || typeof config.onCall !== 'function') return
const r = {
args,
fn,
config
};
config.onCall(r)
}
function onComplete({ result, config }) {
if (!config.onComplete || typeof config.onComplete !== 'function') return
const r = {
result,
config
};
config.onComplete(r)
}
function buildFunctions(config, handlers, functions) {

@@ -120,0 +143,0 @@ let promiseFunctions = {}

const { call } = require('../index')
const { handlers, functions, cmds } = require('./effects')
const { basicMultistep, badHandler } = functions
const { basicMultistep, badHandler, basic } = functions
const { sleep } = require('./test-util')
test('telemetry', async () => {
test('telemetry - onCommandComplete', async () => {
let telemetry = []

@@ -29,3 +29,3 @@ const onCommandComplete = t => {

test('telemetry on error', async () => {
test('telemetry on error - onCommandComplete', async () => {
let telemetry

@@ -35,3 +35,3 @@ const onCommandComplete = t => {

}
const config = { onCommandComplete, name: 'telemetry' }
const config = { onCommandComplete }
const now = Date.now()

@@ -53,1 +53,21 @@ const message = 'oops'

})
test('onCall', async () => {
let called
const onCall = t => {
called = t
}
const config = { onCall }
await call(config, handlers, basicMultistep, 'foo', 'bar', 'baz')
expect(called.args).toEqual(['foo', 'bar', 'baz'])
})
test('onComplete', async () => {
let complete
const onComplete = t => {
complete = t
}
const config = { onComplete, name: 'telemetry' }
await call(config, handlers, basic, 'foo')
expect(complete.result).toEqual('foo')
})

@@ -1,2 +0,2 @@

const { functions, cmds } = require('./effects')
const { functions, cmds } = require("./effects")
const {

@@ -14,3 +14,3 @@ basic,

} = functions
const { testFn, testFnV2, args } = require('../test')
const { testFn, testFnV2, args } = require("../test")

@@ -23,3 +23,3 @@ function* singleLine(id) {

function* yieldArray() {
const s1 = yield [{ type: 'test' }]
const s1 = yield [{ type: "test" }]
return s1

@@ -32,3 +32,3 @@ }

test(
'testFn should handle undefined returns for semantic test',
"testFn should handle undefined returns for semantic test",
testFn(function*() {}, () => {

@@ -40,3 +40,3 @@ return args().returns()

test(
'testFn should curry',
"testFn should curry",
testFn(basic)(() => {

@@ -52,3 +52,3 @@ // prettier-ignore

test(
'testFn should pass (basic)',
"testFn should pass (basic)",
testFn(basic, () => {

@@ -66,3 +66,3 @@ // prettier-ignore

test(
'testFn semantic should pass (basic)',
"testFn semantic should pass (basic)",
testFn(basic, () => {

@@ -77,3 +77,3 @@ // prettier-ignore

test(
'testFnV2 should pass (basic)',
"testFnV2 should pass (basic)",
testFnV2(basic, () => {

@@ -90,3 +90,3 @@ // prettier-ignore

test(
'testFn should pass (basicMultiArg)',
"testFn should pass (basicMultiArg)",
testFn(basicMultiArg, () => {

@@ -104,3 +104,3 @@ // prettier-ignore

test(
'testFn should pass (basicMultiArg)',
"testFn should pass (basicMultiArg)",
testFn(basicMultiArg, () => {

@@ -116,3 +116,3 @@ // prettier-ignore

test(
'testFn semantic should pass (basicMultiArg)',
"testFn semantic should pass (basicMultiArg)",
testFn(basicMultiArg, () => {

@@ -127,3 +127,3 @@ // prettier-ignore

test(
'testFn semantic should pass (basicMultiArg)',
"testFn semantic should pass (basicMultiArg)",
testFnV2(basicMultiArg, () => {

@@ -142,3 +142,3 @@ // prettier-ignore

test(
'testFn should pass (basicMultistep)',
"testFn should pass (basicMultistep)",
testFn(basicMultistep, () => {

@@ -155,3 +155,3 @@ // prettier-ignore

test(
'testFn semantic should pass (basicMultistep)',
"testFn semantic should pass (basicMultistep)",
testFn(basicMultistep, () => {

@@ -167,3 +167,3 @@ // prettier-ignore

test(
'testFnV2 should pass (basicMultistep)',
"testFnV2 should pass (basicMultistep)",
testFnV2(basicMultistep, () => {

@@ -183,5 +183,5 @@ // prettier-ignore

test(
'testFn should pass (basicParallel)',
"testFn should pass (basicParallel)",
testFn(basicParallel, () => {
const c = [cmds.echo('foo'), cmds.echo('foo')]
const c = [cmds.echo("foo"), cmds.echo("foo")]
// prettier-ignore

@@ -196,5 +196,5 @@ return [

test(
'testFn semantic should pass (basicParallel)',
"testFn semantic should pass (basicParallel)",
testFn(basicParallel, () => {
const c = [cmds.echo('foo'), cmds.echo('foo')]
const c = [cmds.echo("foo"), cmds.echo("foo")]
// prettier-ignore

@@ -208,5 +208,5 @@ return args('foo')

test(
'testFnV2 should pass (basicParallel)',
"testFnV2 should pass (basicParallel)",
testFnV2(basicParallel, () => {
const c = [cmds.echo('foo'), cmds.echo('foo')]
const c = [cmds.echo("foo"), cmds.echo("foo")]
// prettier-ignore

@@ -224,6 +224,6 @@ return [

test(
'testFn should pass (basicMultistepParallel)',
"testFn should pass (basicMultistepParallel)",
testFn(basicMultistepParallel, () => {
const c1 = [cmds.echo('foo'), cmds.echo('foo')]
const c2 = [cmds.echo('foo'), cmds.echo('foo')]
const c1 = [cmds.echo("foo"), cmds.echo("foo")]
const c2 = [cmds.echo("foo"), cmds.echo("foo")]
// prettier-ignore

@@ -239,6 +239,6 @@ return [

test(
'testFn semantic should pass (basicMultistepParallel)',
"testFn semantic should pass (basicMultistepParallel)",
testFn(basicMultistepParallel, () => {
const c1 = [cmds.echo('foo'), cmds.echo('foo')]
const c2 = [cmds.echo('foo'), cmds.echo('foo')]
const c1 = [cmds.echo("foo"), cmds.echo("foo")]
const c2 = [cmds.echo("foo"), cmds.echo("foo")]
// prettier-ignore

@@ -253,6 +253,6 @@ return args('foo')

test(
'testFnV2 should pass (basicMultistepParallel)',
"testFnV2 should pass (basicMultistepParallel)",
testFnV2(basicMultistepParallel, () => {
const c1 = [cmds.echo('foo'), cmds.echo('foo')]
const c2 = [cmds.echo('foo'), cmds.echo('foo')]
const c1 = [cmds.echo("foo"), cmds.echo("foo")]
const c2 = [cmds.echo("foo"), cmds.echo("foo")]
// prettier-ignore

@@ -271,3 +271,3 @@ return [

test(
'testFn should pass (basicEmpty)',
"testFn should pass (basicEmpty)",
testFn(basicEmpty, () => {

@@ -283,3 +283,3 @@ // prettier-ignore

test(
'testFn semantic should pass (basicEmpty)',
"testFn semantic should pass (basicEmpty)",
testFn(basicEmpty, () => {

@@ -294,3 +294,3 @@ // prettier-ignore

test(
'testFnV2 should pass (basicEmpty)',
"testFnV2 should pass (basicEmpty)",
testFnV2(basicEmpty, () => {

@@ -309,3 +309,3 @@ // prettier-ignore

test(
'testFn should pass (eitherTestError)',
"testFn should pass (eitherTestError)",
testFn(eitherTestError, () => {

@@ -321,3 +321,3 @@ // prettier-ignore

test(
'testFn semantic should pass (eitherTestError)',
"testFn semantic should pass (eitherTestError)",
testFn(eitherTestError, () => {

@@ -332,3 +332,3 @@ // prettier-ignore

test(
'testFnV2 semantic should pass (eitherTestError)',
"testFnV2 semantic should pass (eitherTestError)",
testFnV2(eitherTestError, () => {

@@ -347,3 +347,3 @@ // prettier-ignore

test(
'testFn should handle errors (badHandler)',
"testFn should handle errors (badHandler)",
testFn(badHandler, () => {

@@ -359,3 +359,3 @@ // prettier-ignore

test(
'testFn semantic should handle errors (badHandler)',
"testFn semantic should handle errors (badHandler)",
testFn(badHandler, () => {

@@ -370,3 +370,12 @@ // prettier-ignore

test(
'testFnV2 should handle errors (badHandler)',
"testFn semantic should handle errors without returns (badHandler)",
testFn(badHandler, () => {
// prettier-ignore
return args([null])
.yieldCmd(cmds.die('oops')).throws(new Error('oops!'))
})
)
test(
"testFnV2 should handle errors (badHandler)",
testFnV2(badHandler, () => {

@@ -385,3 +394,3 @@ // prettier-ignore

test(
'testFn should pass (eitherTestEmpty)',
"testFn should pass (eitherTestEmpty)",
testFn(eitherTestEmpty, () => {

@@ -397,3 +406,3 @@ // prettier-ignore

test(
'testFn semantic should pass (eitherTestEmpty)',
"testFn semantic should pass (eitherTestEmpty)",
testFn(eitherTestEmpty, () => {

@@ -408,3 +417,3 @@ // prettier-ignore

test(
'testFnV2 should pass (eitherTestEmpty)',
"testFnV2 should pass (eitherTestEmpty)",
testFnV2(eitherTestEmpty, () => {

@@ -423,3 +432,3 @@ // prettier-ignore

test(
'testFn should pass (asyncTest)',
"testFn should pass (asyncTest)",
testFn(asyncTest, () => {

@@ -435,3 +444,3 @@ // prettier-ignore

test(
'testFn semantic should pass (asyncTest)',
"testFn semantic should pass (asyncTest)",
testFn(asyncTest, () => {

@@ -446,3 +455,3 @@ // prettier-ignore

test(
'testFnV2 should pass (asyncTest)',
"testFnV2 should pass (asyncTest)",
testFnV2(asyncTest, () => {

@@ -458,6 +467,54 @@ // prettier-ignore

// Return cmd result
// Throw from semantic test builder
function* returnCmdResult() {
return yield cmds.echo("foo")
}
test(
"testFn semantic should return cmd result",
testFn(returnCmdResult, () => {
// prettier-ignore
return args()
.yieldCmd(cmds.echo('foo')).returns("foo")
})
)
// Throw from semantic test builder
function* throwSemantic() {
const value = yield cmds.echo("foo")
throw new Error("oops")
}
test(
"testFn semantic should throw if .throws is used",
testFn(throwSemantic, () => {
// prettier-ignore
return args()
.yieldCmd(cmds.echo('foo')).yieldReturns('foo')
.throws(new Error("oops"))
})
)
test("testFn should throw proper error if function throws incorrect error", () => {
try {
testFn(throwSemantic, () => {
// prettier-ignore
return args()
.yieldCmd(cmds.echo('foo')).yieldReturns('foo')
.throws(new Error("wrong"))
})()
} catch (e) {
expect(e.name).toEqual("Error on Step 2")
return
}
fail("Did not throw")
})
// Single line
test(
'single line should pass',
"single line should pass",
testSingleLine(() => {

@@ -473,3 +530,3 @@ // prettier-ignore

test(
'testFn semantic single line should not fail',
"testFn semantic single line should not fail",
testSingleLine(() => {

@@ -483,3 +540,3 @@ // prettier-ignore

test('testFn should give proper error message if yielding array but no results', () => {
test("testFn should give proper error message if yielding array but no results", () => {
try {

@@ -494,3 +551,3 @@ testYieldArray(() => {

expect(e.message).toEqual(
'Your spec does not have as many steps as your function. Are you missing a return line?'
"Your spec does not have as many steps as your function. Are you missing a return line?"
)

@@ -500,3 +557,3 @@ }

test('testFn should give proper error message if spec is returning undefined', () => {
test("testFn should give proper error message if spec is returning undefined", () => {
try {

@@ -511,3 +568,3 @@ testYieldArray(() => {})()

test('testFn should give proper error message if spec is returning an object', () => {
test("testFn should give proper error message if spec is returning an object", () => {
try {

@@ -524,6 +581,6 @@ testYieldArray(() => {

test('testFn should give proper error message if spec is returning an string', () => {
test("testFn should give proper error message if spec is returning an string", () => {
try {
testYieldArray(() => {
return 'what?'
return "what?"
})()

@@ -530,0 +587,0 @@ } catch (e) {

@@ -1,4 +0,4 @@

const assert = require('assert')
const curry = require('lodash/curry')
const chunk = require('lodash/chunk')
const assert = require("assert")
const curry = require("lodash/curry")
const chunk = require("lodash/chunk")

@@ -8,3 +8,3 @@ const testRunner = (fn, expected, index = 0, previousOutput = null) => {

assert(fn, 'The function you are trying to test is undefined.')
assert(fn, "The function you are trying to test is undefined.")

@@ -15,3 +15,3 @@ const step = expected[index]

throw new Error(
'Your spec does not have as many steps as your function. Are you missing a return line?'
"Your spec does not have as many steps as your function. Are you missing a return line?"
)

@@ -36,7 +36,14 @@ }

} else {
output = g.next(input)
try {
output = g.next(input)
} catch (e) {
output = { value: e, done: true }
}
}
const endOnError = isError(output.value)
try {
deepEqual(output.value, expectedOutput)
if (endOnError) return
} catch (e) {

@@ -71,3 +78,3 @@ e.name = `Error on Step ${index + 1}`

Array.isArray(nextInput),
'If an array of actions is yielded, it should return an array of results.'
"If an array of actions is yielded, it should return an array of results."
)

@@ -105,3 +112,3 @@ }

// a little bit of jest support
if (typeof expect !== 'undefined' && expect.extend && expect.anything) {
if (typeof expect !== "undefined" && expect.extend && expect.anything) {
expect(actual).toEqual(expected)

@@ -122,3 +129,5 @@ } else {

return {
yieldReturns: yieldReturns(t)
yieldReturns: yieldReturns(t),
throws: yieldReturnThrows(t),
returns: returnCmdResult(t)
}

@@ -132,2 +141,3 @@ }

yieldCmd: yieldCmd(t),
throws: throwAfterCmdReturns(t),
returns: returns(t)

@@ -137,2 +147,17 @@ }

const returnCmdResult = t => v => {
t[t.length] = [v, v]
return t
}
const yieldReturnThrows = t => v => {
t[t.length] = [v, v]
return t
}
const throwAfterCmdReturns = t => v => {
t[t.length - 1][1] = v
return t
}
const returns = t => a => {

@@ -139,0 +164,0 @@ t[t.length - 1][1] = a

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc