New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@ogre-tools/injectable

Package Overview
Dependencies
Maintainers
2
Versions
88
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@ogre-tools/injectable - npm Package Compare versions

Comparing version 2.0.0 to 3.0.0

src/test-utils/flushPromises.js

4

ogre-tools-injectable.d.ts

@@ -30,3 +30,3 @@ /// <reference types="jest" />

runSetups: () => void;
runSetups: () => Promise<void>;

@@ -67,3 +67,3 @@ override<TInjectable extends Injectable<unknown, unknown, unknown>>(

id?: string;
setup?: (di: DependencyInjectionContainer) => void;
setup?: (di: DependencyInjectionContainer) => void | Promise<void>;
causesSideEffects?: boolean;

@@ -70,0 +70,0 @@ lifecycle: lifecycleEnum;

{
"name": "@ogre-tools/injectable",
"private": false,
"version": "2.0.0",
"version": "3.0.0",
"description": "A brutal dependency injection container",

@@ -19,3 +19,3 @@ "repository": {

"dependencies": {
"@ogre-tools/fp": "^2.0.0",
"@ogre-tools/fp": "^3.0.0",
"lodash": "^4.17.21"

@@ -26,3 +26,3 @@ },

},
"gitHead": "113b57735b1636706eaff72d37f0bb18464f48be",
"gitHead": "5805d4b230517f2c8ad5c8c0251d30c9ae5b9b4b",
"bugs": {

@@ -29,0 +29,0 @@ "url": "https://github.com/ogre-works/ogre-tools/issues"

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

import tap from 'lodash/fp/tap';
import conforms from 'lodash/fp/conforms';

@@ -122,3 +123,3 @@ import every from 'lodash/fp/every';

runSetups: () => {
runSetups: async () =>
pipeline(

@@ -139,11 +140,13 @@ injectables,

filter('setup'),
forEach(injectable => {
map(async injectable => {
injectable.isBeingSetupped = true;
injectable.setup(di);
await injectable.setup(di);
injectable.isBeingSetupped = false;
}),
);
setupsHaveBeenRan = true;
},
tap(() => {
setupsHaveBeenRan = true;
}),
),

@@ -150,0 +153,0 @@ preventSideEffects: () => {

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

import asyncFn from '@async-fn/jest';
import castArray from 'lodash/fp/castArray';
import createContainer from './createContainer';
import lifecycleEnum from './lifecycleEnum';
import castArray from 'lodash/fp/castArray';
import fromPairs from 'lodash/fp/fromPairs';
import keys from 'lodash/fp/keys';
import lifecycleEnum from './lifecycleEnum';
import map from 'lodash/fp/map';

@@ -10,2 +11,3 @@ import { pipeline } from '@ogre-tools/fp';

import getInjectable from '../getInjectable/getInjectable';
import getPromiseStatus from '../test-utils/getPromiseStatus/getPromiseStatus';

@@ -196,3 +198,3 @@ const nonCappedMap = map.convert({ cap: false });

it('given an injectable with self-injecting setup is overridden, when setups are ran, injects the override in setup', () => {
it('given an injectable with self-injecting setup is overridden, when setups are ran, injects the override in setup', async () => {
const someInjectable = getInjectable({

@@ -220,3 +222,3 @@ id: 'some-injectable-id',

di.runSetups();
await di.runSetups();

@@ -415,3 +417,3 @@ expect(someInjectableOverride.setupped).toBe(true);

it('given setup for injectable, when setups are ran, runs the setup with the DI', () => {
it('given setup for injectable, when setups are ran, runs the setup with the DI', async () => {
const setupMock = jest.fn();

@@ -427,3 +429,3 @@

di.runSetups();
await di.runSetups();

@@ -433,3 +435,44 @@ expect(setupMock).toHaveBeenCalledWith(di);

it('given setup for injectable with aliases but no way to instantiate, when setups are ran, runs setup only once', () => {
it('given multiple async setuppables and DI-setups are ran, when setups resolve, DI-setup resolves', async () => {
const someSetuppable = {
setup: asyncFn(),
};
const someOtherSetuppable = {
setup: asyncFn(),
};
const di = getDi(someSetuppable, someOtherSetuppable);
const runSetupsPromise = di.runSetups();
someSetuppable.setup.resolve();
someOtherSetuppable.setup.resolve();
const promiseStatus = await getPromiseStatus(runSetupsPromise);
expect(promiseStatus.fulfilled).toBe(true);
});
it('given multiple async setuppables and DI-setups are ran, when only some of the setups resolve, DI-setup does not resolve', async () => {
const someSetuppable = {
setup: asyncFn(),
};
const someOtherSetuppable = {
setup: asyncFn(),
};
const di = getDi(someSetuppable, someOtherSetuppable);
const runSetupsPromise = di.runSetups();
someSetuppable.setup.resolve();
const promiseStatus = await getPromiseStatus(runSetupsPromise);
expect(promiseStatus.fulfilled).toBe(false);
});
it('given setup for injectable with aliases but no way to instantiate, when setups are ran, runs setup only once', async () => {
const setupMock = jest.fn();

@@ -444,3 +487,3 @@

di.runSetups();
await di.runSetups();

@@ -450,3 +493,3 @@ expect(setupMock).toHaveBeenCalledTimes(1);

it('given injectable with setup but no way to instantiate, when injected, throws', () => {
it('given injectable with setup but no way to instantiate, when injected, throws', async () => {
const someInjectable = getInjectable({

@@ -459,3 +502,3 @@ setup: () => {},

di.runSetups();
await di.runSetups();

@@ -486,3 +529,3 @@ expect(() => {

it('given injectable with setup that injects itself, when running setups, does not throw', () => {
it('given injectable with setup that injects itself, when running setups, does not throw', async () => {
const someInjectable = getInjectable({

@@ -503,3 +546,3 @@ id: 'some-injectable-id',

di.runSetups();
await di.runSetups();

@@ -529,5 +572,3 @@ const actual = di.inject('some-alias');

expect(() => {
di.runSetups();
}).toThrow(
return expect(di.runSetups()).rejects.toThrow(
'Tried to inject setuppable "some-other-injectable-id" before setups are ran.',

@@ -534,0 +575,0 @@ );

Sorry, the diff of this file is too big to display

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