node-execution-context
Advanced tools
Comparing version
{ | ||
"name": "node-execution-context", | ||
"version": "1.1.3", | ||
"version": "1.1.4", | ||
"description": "Provides execution context wrapper for node JS, can be used to create execution wrapper for handling requests and more", | ||
@@ -5,0 +5,0 @@ "author": "Oded Goldglas <odedglas@gmail.com>", |
@@ -61,3 +61,3 @@ const { isUndefined } = require('../lib'); | ||
if (!children.length) { | ||
executionContextMap.delete(ref) | ||
suspend(() => executionContextMap.delete(ref)); | ||
@@ -95,3 +95,4 @@ return; | ||
} | ||
executionContextMap.delete(asyncId); | ||
suspend(() => executionContextMap.delete(asyncId)); | ||
}; | ||
@@ -98,0 +99,0 @@ |
@@ -103,2 +103,38 @@ const asyncHooks = require('async_hooks'); | ||
}); | ||
describe('Run', () => { | ||
let spies; | ||
let execute; | ||
const initialContext = { initial: 'value' }; | ||
beforeEach(() => { | ||
execute = jest.fn(); | ||
spies = { | ||
contextCreate: jest.spyOn(Context, 'create'), | ||
execute | ||
}; | ||
Context.run(execute, initialContext); | ||
}); | ||
it('Creates context', () => { | ||
expect(spies.contextCreate).toHaveBeenCalledWith(initialContext); | ||
}); | ||
it('Executes given function', () => { | ||
expect(spies.execute).toHaveBeenCalledTimes(1); | ||
}); | ||
it('Expose context to function execution', () => { | ||
let exposedContext = undefined; | ||
execute = jest.fn(() => { | ||
exposedContext = Context.get(); | ||
}); | ||
Context.run(execute, initialContext); | ||
expect(exposedContext).toEqual(expect.objectContaining( | ||
initialContext | ||
)); | ||
}) | ||
}); | ||
}); | ||
@@ -105,0 +141,0 @@ |
31508
3.81%686
4.41%