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.11.0 to 2.11.1

mocha.opts

36

es5/specs/errors.spec.js

@@ -1,7 +0,7 @@

'use strict';
"use strict";
var _require = require('../index'),
var _require = require("../index"),
call = _require.call;
var _require2 = require('./effects'),
var _require2 = require("./effects"),
handlers = _require2.handlers,

@@ -15,38 +15,38 @@ functions = _require2.functions;

var _require3 = require('./test-util'),
var _require3 = require("./test-util"),
expectError = _require3.expectError;
test('call should reject for an undefined function', async function () {
test("call should reject for an undefined function", async function () {
try {
await call({}, handlers, undefined);
} catch (actual) {
var message = 'A function is required.';
var message = "A function is required.";
return expectError(actual, message);
}
fail('Function did not reject.');
fail("Function did not reject.");
});
test('call should catch function errors', async function () {
test("call should catch function errors", async function () {
try {
await call({}, handlers, functionErrorTest);
} catch (actual) {
var message = 'oops!';
var message = "oops!";
return expectError(actual, message);
}
fail('Function did not reject.');
fail("Function did not reject.");
});
test('call should throw error at the yield', async function () {
test("call should throw error at the yield", async function () {
var actual = await call({}, handlers, throwAtYield);
var expected = 'caught!';
var expected = "caught!";
expect(actual).toEqual(expected);
});
test('call should throw error at the yield and recover', async function () {
test("call should throw error at the yield and recover", async function () {
var actual = await call({}, handlers, throwAtYieldRecovery);
var expected = 'foo';
var expected = "foo";
expect(actual).toEqual(expected);
});
test('call should throw error for unregistered handler', async function () {
test("call should throw error for unregistered handler", async function () {
var fn = regeneratorRuntime.mark(function fn() {

@@ -58,6 +58,6 @@ return regeneratorRuntime.wrap(function fn$(_context) {

_context.next = 2;
return { type: 'dne' };
return { type: "dne" };
case 2:
case 'end':
case "end":
return _context.stop();

@@ -74,4 +74,4 @@ }

}
fail('Did not throw.');
fail("Did not throw.");
});
//# sourceMappingURL=errors.spec.js.map
'use strict';
var assert = require("assert");
function errorToJson(e) {

@@ -44,6 +46,28 @@ var props = Object.getOwnPropertyNames(e).concat('name');

function deepEqual(actual, expected) {
var a = normalizeError(actual);
var e = normalizeError(expected);
if (usingJest()) expect(a).toEqual(e);else assert.deepEqual(a, e);
}
function normalizeError(v) {
var isError = v instanceof Error;
if (!isError) return v;
var props = Object.getOwnPropertyNames(v).concat("name");
return props.reduce(function (p, c) {
if (c === "stack") return p;
p[c] = v[c];
return p;
}, {});
}
function usingJest() {
return typeof expect !== "undefined" && expect.extend && expect.anything;
}
module.exports = {
expectError: expectError,
sleep: sleep
sleep: sleep,
deepEqual: deepEqual
};
//# sourceMappingURL=test-util.js.map
"use strict";
var _marked = [singleLine, yieldArray, returnCmdResult, throwSemantic].map(regeneratorRuntime.mark);
var _marked = [singleLine, yieldArray, rethrow, throwFoo, returnCmdResult, throwSemantic].map(regeneratorRuntime.mark);

@@ -25,2 +25,5 @@ var _require = require("./effects"),

var _require3 = require("./test-util"),
deepEqual = _require3.deepEqual;
function singleLine(id) {

@@ -71,7 +74,20 @@ var s1;

test("testFn should handle undefined returns for semantic test", testFn(regeneratorRuntime.mark(function _callee() {
return regeneratorRuntime.wrap(function _callee$(_context3) {
function rethrow() {
return regeneratorRuntime.wrap(function rethrow$(_context3) {
while (1) {
switch (_context3.prev = _context3.next) {
case 0:
_context3.prev = 0;
_context3.next = 3;
return cmds.echo("foo");
case 3:
return _context3.abrupt("return", _context3.sent);
case 6:
_context3.prev = 6;
_context3.t0 = _context3["catch"](0);
throw new Error("bar");
case 9:
case "end":

@@ -81,2 +97,47 @@ return _context3.stop();

}
}, _marked[2], this, [[0, 6]]);
}
function throwFoo() {
return regeneratorRuntime.wrap(function throwFoo$(_context4) {
while (1) {
switch (_context4.prev = _context4.next) {
case 0:
throw new Error("foo");
case 1:
case "end":
return _context4.stop();
}
}
}, _marked[3], this);
}
test("testFn should fail if the function error is different than the test error", function () {
try {
testFn(throwFoo, function () {
// prettier-ignore
return [[[], new Error("bar")]];
})();
} catch (e) {
deepEqual(e.name, 'Error on Step 1');
return;
}
throw new Error("Failed: Did not compare error messages");
});
test("should be able to rethrow errors", testFnV2(rethrow, function () {
// prettier-ignore
return [[], [cmds.echo('foo'), new Error("whatever")], new Error("bar")];
}));
test("testFn should handle undefined returns for semantic test", testFn(regeneratorRuntime.mark(function _callee() {
return regeneratorRuntime.wrap(function _callee$(_context5) {
while (1) {
switch (_context5.prev = _context5.next) {
case 0:
case "end":
return _context5.stop();
}
}
}, _callee, this);

@@ -285,18 +346,18 @@ }), function () {

function returnCmdResult() {
return regeneratorRuntime.wrap(function returnCmdResult$(_context4) {
return regeneratorRuntime.wrap(function returnCmdResult$(_context6) {
while (1) {
switch (_context4.prev = _context4.next) {
switch (_context6.prev = _context6.next) {
case 0:
_context4.next = 2;
_context6.next = 2;
return cmds.echo("foo");
case 2:
return _context4.abrupt("return", _context4.sent);
return _context6.abrupt("return", _context6.sent);
case 3:
case "end":
return _context4.stop();
return _context6.stop();
}
}
}, _marked[2], this);
}, _marked[4], this);
}

@@ -313,11 +374,11 @@

var value;
return regeneratorRuntime.wrap(function throwSemantic$(_context5) {
return regeneratorRuntime.wrap(function throwSemantic$(_context7) {
while (1) {
switch (_context5.prev = _context5.next) {
switch (_context7.prev = _context7.next) {
case 0:
_context5.next = 2;
_context7.next = 2;
return cmds.echo("foo");
case 2:
value = _context5.sent;
value = _context7.sent;
throw new Error("oops");

@@ -327,6 +388,6 @@

case "end":
return _context5.stop();
return _context7.stop();
}
}
}, _marked[3], this);
}, _marked[5], this);
}

@@ -346,6 +407,6 @@

} catch (e) {
expect(e.name).toEqual("Error on Step 2");
deepEqual(e.name, "Error on Step 2");
return;
}
fail("Did not throw");
throw new Error("Failed: Did not throw");
});

@@ -372,3 +433,3 @@

} catch (e) {
expect(e.message).toEqual("Your spec does not have as many steps as your function. Are you missing a return line?");
deepEqual(e.message, "Your spec does not have as many steps as your function. Are you missing a return line?");
}

@@ -381,3 +442,3 @@ });

} catch (e) {
expect(e.message).toEqual('Your spec must return an array of tuples. It is currently returning a value of type "undefined".');
deepEqual(e.message, 'Your spec must return an array of tuples. It is currently returning a value of type "undefined".');
}

@@ -392,3 +453,3 @@ });

} catch (e) {
expect(e.message).toEqual('Your spec must return an array of tuples. It is currently returning a value of type "object".');
deepEqual(e.message, 'Your spec must return an array of tuples. It is currently returning a value of type "object".');
}

@@ -403,5 +464,5 @@ });

} catch (e) {
expect(e.message).toEqual('Your spec must return an array of tuples. It is currently returning a value of type "string".');
deepEqual(e.message, 'Your spec must return an array of tuples. It is currently returning a value of type "string".');
}
});
//# sourceMappingURL=test.spec.js.map

@@ -11,2 +11,5 @@ "use strict";

var _require = require("./specs/test-util"),
deepEqual = _require.deepEqual;
var testRunner = function testRunner(fn, expected) {

@@ -112,11 +115,2 @@ var index = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;

function deepEqual(actual, expected) {
// a little bit of jest support
if (typeof expect !== "undefined" && expect.extend && expect.anything) {
expect(actual).toEqual(expected);
} else {
assert.deepEqual(actual, expected);
}
}
// Semantic test builder

@@ -123,0 +117,0 @@ var args = function args() {

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

@@ -12,3 +12,3 @@ "main": "src/index.js",

"test": "jest",
"test-mocha": "mocha src/**/*.spec.js --recursive --compilers js:babel-register --require babel-polyfill",
"test:mocha": "mocha --opts mocha.opts",
"transpile": "babel src --out-dir es5 --source-maps",

@@ -27,3 +27,4 @@ "deploy": "npm run transpile && npm test && npm publish; rm -rf es5",

"babel-preset-es2015": "^6.24.1",
"jest-cli": "^20.0.0"
"jest-cli": "^20.0.0",
"mocha": "^3.5.0"
},

@@ -30,0 +31,0 @@ "jest": {

@@ -7,3 +7,3 @@ # Effects-as-data

* Effects-as-data outputs a `command` log allowing you to see every side-effect (HTTP, Disk IO, etc), its latency, and its result giving you detailed insight into your code while it runs in development and production.
* Effects-as-data is <1kb minified+gzipped.
* Effects-as-data is ~1kb minified+gzipped.
* Effects-as-data has *almost* no performance overhead (see `npm run perf`).

@@ -10,0 +10,0 @@ * Anywhere you can use promises, you can use effects-as-data.

@@ -1,3 +0,3 @@

const { call } = require('../index')
const { handlers, functions } = require('./effects')
const { call } = require("../index")
const { handlers, functions } = require("./effects")
const {

@@ -9,39 +9,39 @@ badHandler,

} = functions
const { expectError } = require('./test-util')
const { expectError } = require("./test-util")
test('call should reject for an undefined function', async () => {
test("call should reject for an undefined function", async () => {
try {
await call({}, handlers, undefined)
} catch (actual) {
const message = 'A function is required.'
const message = "A function is required."
return expectError(actual, message)
}
fail('Function did not reject.')
fail("Function did not reject.")
})
test('call should catch function errors', async () => {
test("call should catch function errors", async () => {
try {
await call({}, handlers, functionErrorTest)
} catch (actual) {
const message = 'oops!'
const message = "oops!"
return expectError(actual, message)
}
fail('Function did not reject.')
fail("Function did not reject.")
})
test('call should throw error at the yield', async () => {
test("call should throw error at the yield", async () => {
const actual = await call({}, handlers, throwAtYield)
const expected = 'caught!'
const expected = "caught!"
expect(actual).toEqual(expected)
})
test('call should throw error at the yield and recover', async () => {
test("call should throw error at the yield and recover", async () => {
const actual = await call({}, handlers, throwAtYieldRecovery)
const expected = 'foo'
const expected = "foo"
expect(actual).toEqual(expected)
})
test('call should throw error for unregistered handler', async () => {
test("call should throw error for unregistered handler", async () => {
const fn = function*() {
yield { type: 'dne' }
yield { type: "dne" }
}

@@ -54,3 +54,3 @@ try {

}
fail('Did not throw.')
fail("Did not throw.")
})

@@ -0,1 +1,3 @@

const assert = require("assert")
function errorToJson(e) {

@@ -38,5 +40,28 @@ const props = Object.getOwnPropertyNames(e).concat('name')

function deepEqual(actual, expected) {
const a = normalizeError(actual)
const e = normalizeError(expected)
if (usingJest()) expect(a).toEqual(e)
else assert.deepEqual(a, e)
}
function normalizeError(v) {
const isError = v instanceof Error
if (!isError) return v
const props = Object.getOwnPropertyNames(v).concat("name")
return props.reduce((p, c) => {
if (c === "stack") return p
p[c] = v[c]
return p
}, {})
}
function usingJest() {
return typeof expect !== "undefined" && expect.extend && expect.anything
}
module.exports = {
expectError,
sleep
sleep,
deepEqual
}

@@ -15,2 +15,3 @@ const { functions, cmds } = require("./effects")

const { testFn, testFnV2, args } = require("../test")
const { deepEqual } = require("./test-util")

@@ -30,3 +31,44 @@ function* singleLine(id) {

function* rethrow() {
try {
return yield cmds.echo("foo")
} catch (e) {
throw new Error("bar")
}
}
function* throwFoo() {
throw new Error("foo")
}
test(
"testFn should fail if the function error is different than the test error",() => {
try {
testFn(throwFoo, () => {
// prettier-ignore
return [
[ [], new Error("bar") ]
]
})()
} catch (e) {
deepEqual(e.name, 'Error on Step 1')
return
}
throw new Error("Failed: Did not compare error messages")
}
)
test(
"should be able to rethrow errors",
testFnV2(rethrow, () => {
// prettier-ignore
return [
[],
[cmds.echo('foo'), new Error("whatever")],
new Error("bar")
]
})
)
test(
"testFn should handle undefined returns for semantic test",

@@ -476,6 +518,6 @@ testFn(function*() {}, () => {

} catch (e) {
expect(e.name).toEqual("Error on Step 2")
deepEqual(e.name, "Error on Step 2")
return
}
fail("Did not throw")
throw new Error("Failed: Did not throw")
})

@@ -515,5 +557,3 @@

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

@@ -526,5 +566,3 @@ })

} catch (e) {
expect(e.message).toEqual(
'Your spec must return an array of tuples. It is currently returning a value of type "undefined".'
)
deepEqual(e.message, 'Your spec must return an array of tuples. It is currently returning a value of type "undefined".')
}

@@ -539,5 +577,3 @@ })

} catch (e) {
expect(e.message).toEqual(
'Your spec must return an array of tuples. It is currently returning a value of type "object".'
)
deepEqual(e.message, 'Your spec must return an array of tuples. It is currently returning a value of type "object".')
}

@@ -552,6 +588,4 @@ })

} catch (e) {
expect(e.message).toEqual(
'Your spec must return an array of tuples. It is currently returning a value of type "string".'
)
deepEqual(e.message, 'Your spec must return an array of tuples. It is currently returning a value of type "string".')
}
})
const assert = require("assert")
const curry = require("lodash/curry")
const chunk = require("lodash/chunk")
const { deepEqual } = require("./specs/test-util")

@@ -106,11 +107,2 @@ const testRunner = (fn, expected, index = 0, previousOutput = null) => {

function deepEqual(actual, expected) {
// a little bit of jest support
if (typeof expect !== "undefined" && expect.extend && expect.anything) {
expect(actual).toEqual(expected)
} else {
assert.deepEqual(actual, expected)
}
}
// Semantic test builder

@@ -117,0 +109,0 @@ const args = (...fnArgs) => {

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