effects-as-data
Advanced tools
Comparing version 2.6.0 to 2.7.0
@@ -6,3 +6,4 @@ 'use strict'; | ||
toArray = _require.toArray, | ||
toPromise = _require.toPromise; | ||
toPromise = _require.toPromise, | ||
delay = _require.delay; | ||
@@ -17,5 +18,7 @@ function call(config, handlers, fn) { | ||
var el = newExecutionLog(); | ||
var start = Date.now(); | ||
onCall({ args: args, fn: fn, config: config }); | ||
return run(config, handlers, gen, null, el).then(function (result) { | ||
onComplete({ result: result, config: config }); | ||
var end = Date.now(); | ||
onComplete({ result: result, config: config, start: start, end: end, latency: end - start }); | ||
return result; | ||
@@ -142,3 +145,5 @@ }); | ||
}; | ||
config.onCommandComplete(r); | ||
delay(function () { | ||
return config.onCommandComplete(r); | ||
}); | ||
} | ||
@@ -157,3 +162,5 @@ | ||
}; | ||
config.onCall(r); | ||
delay(function () { | ||
return config.onCall(r); | ||
}); | ||
} | ||
@@ -163,10 +170,18 @@ | ||
var result = _ref3.result, | ||
config = _ref3.config; | ||
config = _ref3.config, | ||
start = _ref3.start, | ||
end = _ref3.end, | ||
latency = _ref3.latency; | ||
if (!config.onComplete || typeof config.onComplete !== 'function') return; | ||
var r = { | ||
config: config, | ||
end: end, | ||
latency: latency, | ||
result: result, | ||
config: config | ||
start: start | ||
}; | ||
config.onComplete(r); | ||
delay(function () { | ||
return config.onComplete(r); | ||
}); | ||
} | ||
@@ -173,0 +188,0 @@ |
@@ -1,7 +0,9 @@ | ||
'use strict'; | ||
"use strict"; | ||
var _require = require('../index'), | ||
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 _require = require("../index"), | ||
call = _require.call; | ||
var _require2 = require('./effects'), | ||
var _require2 = require("./effects"), | ||
handlers = _require2.handlers, | ||
@@ -15,6 +17,6 @@ functions = _require2.functions, | ||
var _require3 = require('./test-util'), | ||
var _require3 = require("./test-util"), | ||
sleep = _require3.sleep; | ||
test('telemetry - onCommandComplete', async function () { | ||
test("telemetry - onCommandComplete", async function () { | ||
var telemetry = []; | ||
@@ -24,8 +26,9 @@ var onCommandComplete = function onCommandComplete(t) { | ||
}; | ||
var config = { onCommandComplete: onCommandComplete, name: 'telemetry' }; | ||
var config = { onCommandComplete: onCommandComplete, name: "telemetry" }; | ||
var now = Date.now(); | ||
await call(config, handlers, basicMultistep, 'foo'); | ||
await call(config, handlers, basicMultistep, "foo"); | ||
await sleep(10); | ||
expect(telemetry.length).toEqual(2); | ||
telemetry.forEach(function (t, i) { | ||
var message = 'foo' + (i + 1); | ||
var message = "foo" + (i + 1); | ||
expect(t.success).toEqual(true); | ||
@@ -43,3 +46,3 @@ expect(t.command).toEqual(cmds.echo(message)); | ||
test('telemetry on error - onCommandComplete', async function () { | ||
test("telemetry on error - onCommandComplete", async function () { | ||
var telemetry = void 0; | ||
@@ -51,3 +54,3 @@ var onCommandComplete = function onCommandComplete(t) { | ||
var now = Date.now(); | ||
var message = 'oops'; | ||
var message = "oops"; | ||
try { | ||
@@ -64,25 +67,27 @@ await call(config, handlers, badHandler, message); | ||
expect(telemetry.step).toEqual(0); | ||
expect(telemetry.result.message).toEqual('oops'); | ||
expect(telemetry.result.message).toEqual("oops"); | ||
expect(telemetry.config).toEqual(config); | ||
}); | ||
test('onCall', async function () { | ||
var called = void 0; | ||
var onCall = function onCall(t) { | ||
called = t; | ||
test("onCall", function (done) { | ||
var onCall = function onCall(called) { | ||
expect(called.args).toEqual(["foo", "bar", "baz"]); | ||
done(); | ||
}; | ||
var config = { onCall: onCall }; | ||
await call(config, handlers, basicMultistep, 'foo', 'bar', 'baz'); | ||
expect(called.args).toEqual(['foo', 'bar', 'baz']); | ||
call(config, handlers, basicMultistep, "foo", "bar", "baz"); | ||
}); | ||
test('onComplete', async function () { | ||
var complete = void 0; | ||
var onComplete = function onComplete(t) { | ||
complete = t; | ||
test("onComplete", function (done) { | ||
var now = Date.now(); | ||
var onComplete = function onComplete(complete) { | ||
expect(complete.result).toEqual("foo"); | ||
expect(_typeof(complete.latency)).toEqual("number"); | ||
expect(complete.start).toBeGreaterThanOrEqual(now); | ||
expect(complete.end).toBeGreaterThanOrEqual(complete.start); | ||
done(); | ||
}; | ||
var config = { onComplete: onComplete, name: 'telemetry' }; | ||
await call(config, handlers, basic, 'foo'); | ||
expect(complete.result).toEqual('foo'); | ||
var config = { onComplete: onComplete, name: "telemetry" }; | ||
call(config, handlers, basic, "foo"); | ||
}); | ||
//# sourceMappingURL=telemetry.spec.js.map |
'use strict'; | ||
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; }; | ||
function isGenerator(fn) { | ||
@@ -18,7 +20,12 @@ return fn && fn.constructor && fn.constructor.name === 'GeneratorFunction'; | ||
var delay = (typeof setImmediate === 'undefined' ? 'undefined' : _typeof(setImmediate)) === undefined ? function (fn) { | ||
return setTimeout(fn, 0); | ||
} : setImmediate; | ||
module.exports = { | ||
isGenerator: isGenerator, | ||
toArray: toArray, | ||
toPromise: toPromise | ||
toPromise: toPromise, | ||
delay: delay | ||
}; | ||
//# sourceMappingURL=util.js.map |
{ | ||
"name": "effects-as-data", | ||
"version": "2.6.0", | ||
"version": "2.7.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", |
@@ -1,2 +0,2 @@ | ||
const { isGenerator, toArray, toPromise } = require('./util') | ||
const { isGenerator, toArray, toPromise, delay } = require('./util') | ||
@@ -7,5 +7,7 @@ function call(config, handlers, fn, ...args) { | ||
const el = newExecutionLog() | ||
const start = Date.now() | ||
onCall({ args, fn, config }) | ||
return run(config, handlers, gen, null, el).then(result => { | ||
onComplete({ result, config }) | ||
const end = Date.now() | ||
onComplete({ result, config, start, end, latency: end - start }) | ||
return result | ||
@@ -116,3 +118,3 @@ }) | ||
} | ||
config.onCommandComplete(r) | ||
delay(() => config.onCommandComplete(r)) | ||
} | ||
@@ -126,13 +128,16 @@ | ||
config | ||
}; | ||
config.onCall(r) | ||
} | ||
delay(() => config.onCall(r)) | ||
} | ||
function onComplete({ result, config }) { | ||
function onComplete({ result, config, start, end, latency }) { | ||
if (!config.onComplete || typeof config.onComplete !== 'function') return | ||
const r = { | ||
config, | ||
end, | ||
latency, | ||
result, | ||
config | ||
}; | ||
config.onComplete(r) | ||
start | ||
} | ||
delay(() => config.onComplete(r)) | ||
} | ||
@@ -139,0 +144,0 @@ |
@@ -1,7 +0,7 @@ | ||
const { call } = require('../index') | ||
const { handlers, functions, cmds } = require('./effects') | ||
const { call } = require("../index") | ||
const { handlers, functions, cmds } = require("./effects") | ||
const { basicMultistep, badHandler, basic } = functions | ||
const { sleep } = require('./test-util') | ||
const { sleep } = require("./test-util") | ||
test('telemetry - onCommandComplete', async () => { | ||
test("telemetry - onCommandComplete", async () => { | ||
let telemetry = [] | ||
@@ -11,8 +11,9 @@ const onCommandComplete = t => { | ||
} | ||
const config = { onCommandComplete, name: 'telemetry' } | ||
const config = { onCommandComplete, name: "telemetry" } | ||
const now = Date.now() | ||
await call(config, handlers, basicMultistep, 'foo') | ||
await call(config, handlers, basicMultistep, "foo") | ||
await sleep(10) | ||
expect(telemetry.length).toEqual(2) | ||
telemetry.forEach((t, i) => { | ||
const message = 'foo' + (i + 1) | ||
const message = "foo" + (i + 1) | ||
expect(t.success).toEqual(true) | ||
@@ -30,3 +31,3 @@ expect(t.command).toEqual(cmds.echo(message)) | ||
test('telemetry on error - onCommandComplete', async () => { | ||
test("telemetry on error - onCommandComplete", async () => { | ||
let telemetry | ||
@@ -38,3 +39,3 @@ const onCommandComplete = t => { | ||
const now = Date.now() | ||
const message = 'oops' | ||
const message = "oops" | ||
try { | ||
@@ -51,24 +52,26 @@ await call(config, handlers, badHandler, message) | ||
expect(telemetry.step).toEqual(0) | ||
expect(telemetry.result.message).toEqual('oops') | ||
expect(telemetry.result.message).toEqual("oops") | ||
expect(telemetry.config).toEqual(config) | ||
}) | ||
test('onCall', async () => { | ||
let called | ||
const onCall = t => { | ||
called = t | ||
test("onCall", done => { | ||
const onCall = called => { | ||
expect(called.args).toEqual(["foo", "bar", "baz"]) | ||
done() | ||
} | ||
const config = { onCall } | ||
await call(config, handlers, basicMultistep, 'foo', 'bar', 'baz') | ||
expect(called.args).toEqual(['foo', 'bar', 'baz']) | ||
call(config, handlers, basicMultistep, "foo", "bar", "baz") | ||
}) | ||
test('onComplete', async () => { | ||
let complete | ||
const onComplete = t => { | ||
complete = t | ||
test("onComplete", done => { | ||
const now = Date.now() | ||
const onComplete = complete => { | ||
expect(complete.result).toEqual("foo") | ||
expect(typeof complete.latency).toEqual("number") | ||
expect(complete.start).toBeGreaterThanOrEqual(now) | ||
expect(complete.end).toBeGreaterThanOrEqual(complete.start) | ||
done() | ||
} | ||
const config = { onComplete, name: 'telemetry' } | ||
await call(config, handlers, basic, 'foo') | ||
expect(complete.result).toEqual('foo') | ||
const config = { onComplete, name: "telemetry" } | ||
call(config, handlers, basic, "foo") | ||
}) |
@@ -137,3 +137,3 @@ const { functions, cmds } = require("./effects") | ||
['foo1', cmds.echo('foo2')], | ||
['foo2', {s1: 'foo1', s2: 'foo2'}] | ||
['foo2', { s1: 'foo1', s2: 'foo2' }] | ||
] | ||
@@ -176,3 +176,3 @@ }) | ||
[['foo'], c], | ||
[['foo', 'foo'], {s1: 'foo1', s2: 'foo2'}] | ||
[['foo', 'foo'], { s1: 'foo1', s2: 'foo2' }] | ||
] | ||
@@ -217,3 +217,3 @@ }) | ||
[['foo', 'foo'], c2], | ||
[['foo', 'foo'], {s1: 'foo1', s2: 'foo2', s3: 'foo3', s4: 'foo4'}] | ||
[['foo', 'foo'], { s1: 'foo1', s2: 'foo2', s3: 'foo3', s4: 'foo4' }] | ||
] | ||
@@ -246,3 +246,3 @@ }) | ||
[c2, ['foo', 'foo']], | ||
{s1: 'foo1', s2: 'foo2', s3: 'foo3', s4: 'foo4'} | ||
{ s1: 'foo1', s2: 'foo2', s3: 'foo3', s4: 'foo4' } | ||
] | ||
@@ -492,3 +492,3 @@ }) | ||
[['123'], cmds.httpGet('http://example.com/api/v1/users/123')], | ||
[{foo: 'bar'}, {foo: 'bar'}] | ||
[{ foo: 'bar' }, { foo: 'bar' }] | ||
] | ||
@@ -513,3 +513,3 @@ }) | ||
return [ | ||
[undefined, [{type: 'test'}]] | ||
[undefined, [{ type: 'test' }]] | ||
] | ||
@@ -516,0 +516,0 @@ })() |
@@ -12,6 +12,9 @@ function isGenerator(fn) { | ||
const delay = typeof setImmediate === undefined ? fn => setTimeout(fn, 0) : setImmediate | ||
module.exports = { | ||
isGenerator, | ||
toArray, | ||
toPromise | ||
toPromise, | ||
delay | ||
} |
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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
201094
3251