diff --git a/API.md b/API.md index a95bbeb..39efe46 100644 --- a/API.md +++ b/API.md @@ -12,6 +12,10 @@
initInitializerBuilder(services)Promise.<function()>

Instantiate the initializer builder service

+
initDispose()
+

Allow to dispose the services of an +initialized silo content.

+
constant(name, value)function

Decorator that creates an initializer for a constant value

@@ -212,6 +216,13 @@ const buildInitializer = await initInitializerBuilder({ const content = await buildInitializer(['entryPoint']); ``` + + +## initDispose() +Allow to dispose the services of an +initialized silo content. + +**Kind**: global function ## constant(name, value) ⇒ function @@ -255,7 +266,7 @@ Decorator that creates an initializer from a service builder | [name] | String | The service's name | | [dependencies] | Array.<String> | The service's injected dependencies | | [singleton] | Boolean | Whether the service is a singleton or not | -| [extra] | any | Eventual extra informations | +| [extra] | any | Eventual extra information | **Example** ```js @@ -303,7 +314,7 @@ Decorator that creates an initializer for a provider | [name] | String | The service's name | | [dependencies] | Array.<String> | The service's dependencies | | [singleton] | Boolean | Whether the service is a singleton or not | -| [extra] | any | Eventual extra informations | +| [extra] | any | Eventual extra information | **Example** ```js diff --git a/ARCHITECTURE.md b/ARCHITECTURE.md index f4ce33b..f8ef704 100644 --- a/ARCHITECTURE.md +++ b/ARCHITECTURE.md @@ -64,11 +64,11 @@ A service provider is full of state since its concern is referred to as another initializer dependency. - type: an initializer can be of three types at the moment (constant, service or provider). The initializer annotations - varies accordsing to those types as we'll see later on. + varies according to those types as we'll see later on. - injected dependencies: an array of dependencies declarations that - declares which initializer htis initializer depends on. Constants + declares which initializer this initializer depends on. Constants logically cannot have dependencies. -- options: various options like for exemple, if the initializer +- options: various options like for example, if the initializer implements the singleton pattern or not. - value: only used for constant, this property allows to know the value the initializer resolves to without actually executing it. diff --git a/README.md b/README.md index 5b3ea6d..37769cd 100644 --- a/README.md +++ b/README.md @@ -434,6 +434,10 @@ is maybe the best feature of this library 😉.
initInitializerBuilder(services)Promise.<function()>

Instantiate the initializer builder service

+
initDispose()
+

Allow to dispose the services of an +initialized silo content.

+
constant(name, value)function

Decorator that creates an initializer for a constant value

@@ -634,6 +638,13 @@ const buildInitializer = await initInitializerBuilder({ const content = await buildInitializer(['entryPoint']); ``` + + +## initDispose() +Allow to dispose the services of an +initialized silo content. + +**Kind**: global function ## constant(name, value) ⇒ function @@ -677,7 +688,7 @@ Decorator that creates an initializer from a service builder | [name] | String | The service's name | | [dependencies] | Array.<String> | The service's injected dependencies | | [singleton] | Boolean | Whether the service is a singleton or not | -| [extra] | any | Eventual extra informations | +| [extra] | any | Eventual extra information | **Example** ```js @@ -725,7 +736,7 @@ Decorator that creates an initializer for a provider | [name] | String | The service's name | | [dependencies] | Array.<String> | The service's dependencies | | [singleton] | Boolean | Whether the service is a singleton or not | -| [extra] | any | Eventual extra informations | +| [extra] | any | Eventual extra information | **Example** ```js diff --git a/package.json b/package.json index b2bc95a..8c0fb7e 100644 --- a/package.json +++ b/package.json @@ -99,7 +99,6 @@ "metapak-nfroidure": "^18.2.0", "prettier": "^3.3.3", "rimraf": "^6.0.1", - "sinon": "^14.0.0", "typescript": "^5.5.3", "typescript-eslint": "^7.16.0" }, diff --git a/src/dispose.ts b/src/dispose.ts index 390dba5..71276f6 100644 --- a/src/dispose.ts +++ b/src/dispose.ts @@ -14,6 +14,10 @@ const debug = initDebug('knifecycle'); export const DISPOSE = '$dispose'; +/** + * Allow to dispose the services of an + * initialized silo content. + */ async function initDispose({ $instance, $siloContext, diff --git a/src/fatalError.ts b/src/fatalError.ts index 3aaa04e..9d91098 100644 --- a/src/fatalError.ts +++ b/src/fatalError.ts @@ -6,6 +6,10 @@ const debug = initDebug('knifecycle'); export const FATAL_ERROR = '$fatalError'; +/** + * Allow to manage processes lifecycle fatal + * errors. + */ export type FatalErrorService = { errorPromise: Promise; registerErrorPromise: (errorPromise: Promise) => void; diff --git a/src/index.test.ts b/src/index.test.ts index 28411f5..fe4d4a6 100644 --- a/src/index.test.ts +++ b/src/index.test.ts @@ -1,8 +1,6 @@ /* eslint-disable @typescript-eslint/no-explicit-any */ /* eslint max-nested-callbacks:0 */ -import { jest, describe, beforeEach, test } from '@jest/globals'; -import assert from 'assert'; -import sinon from 'sinon'; +import { jest, describe, beforeEach, test, expect } from '@jest/globals'; import { YError } from 'yerror'; import { @@ -101,14 +99,14 @@ describe('Knifecycle', () => { test('should work when overriding a previously set constant', async () => { $.register(constant('TEST', 1)); $.register(constant('TEST', 2)); - assert.deepEqual(await $.run(['TEST']), { + expect(await $.run(['TEST'])).toEqual({ TEST: 2, }); }); test('should fail when overriding an initialized constant', async () => { $.register(constant('TEST', 1)); - assert.deepEqual(await $.run(['TEST']), { + expect(await $.run(['TEST'])).toEqual({ TEST: 1, }); @@ -116,8 +114,7 @@ describe('Knifecycle', () => { $.register(constant('TEST', 2)); throw new YError('E_UNEXPECTED_SUCCESS'); } catch (err) { - assert.equal( - (err as YError).code, + expect((err as YError).code).toEqual( 'E_INITIALIZER_ALREADY_INSTANCIATED', ); } @@ -128,7 +125,7 @@ describe('Knifecycle', () => { $.register(constant('$dispose', 2)); throw new YError('E_UNEXPECTED_SUCCESS'); } catch (err) { - assert.equal((err as YError).code, 'E_IMMUTABLE_SERVICE_NAME'); + expect((err as YError).code).toEqual('E_IMMUTABLE_SERVICE_NAME'); } }); @@ -137,7 +134,7 @@ describe('Knifecycle', () => { $.register(service(timeService, '$overrides')); throw new YError('E_UNEXPECTED_SUCCESS'); } catch (err) { - assert.equal((err as YError).code, 'E_CONSTANT_SERVICE_NAME'); + expect((err as YError).code).toEqual('E_CONSTANT_SERVICE_NAME'); } }); }); @@ -152,20 +149,19 @@ describe('Knifecycle', () => { $.register(service(async () => () => 2, 'test')); const { test } = await $.run(['test']); - assert.deepEqual(test(), 2); + expect(test()).toEqual(2); }); test('should fail when overriding an initialized service', async () => { $.register(service(async () => () => 1, 'test')); const { test } = await $.run(['test']); - assert.deepEqual(test(), 1); + expect(test()).toEqual(1); try { $.register(service(async () => () => 2, 'test')); throw new YError('E_UNEXPECTED_SUCCESS'); } catch (err) { - assert.equal( - (err as YError).code, + expect((err as YError).code).toEqual( 'E_INITIALIZER_ALREADY_INSTANCIATED', ); } @@ -187,7 +183,7 @@ describe('Knifecycle', () => { const { test } = await $.run(['test']); - assert.deepEqual(test(), 3); + expect(test()).toEqual(3); }); test('should work with complex services names overrides', async () => { @@ -212,7 +208,7 @@ describe('Knifecycle', () => { const { log } = await $.run(['log']); - assert.deepEqual(log(), 'log from debugLog'); + expect(log()).toEqual('log from debugLog'); }); }); @@ -248,7 +244,7 @@ describe('Knifecycle', () => { ); const { test } = await $.run(['test']); - assert.deepEqual(test, 2); + expect(test).toEqual(2); }); test('should work when overriding a previously set singleton provider', async () => { @@ -279,7 +275,7 @@ describe('Knifecycle', () => { ); const { test } = await $.run(['test']); - assert.deepEqual(test, 2); + expect(test).toEqual(2); }); test('should fail when overriding an initialized provider', async () => { @@ -298,7 +294,7 @@ describe('Knifecycle', () => { ); const { test } = await $.run(['test']); - assert.deepEqual(test, 1); + expect(test).toEqual(1); try { $.register( @@ -315,8 +311,7 @@ describe('Knifecycle', () => { ); throw new YError('E_UNEXPECTED_SUCCESS'); } catch (err) { - assert.equal( - (err as YError).code, + expect((err as YError).code).toEqual( 'E_INITIALIZER_ALREADY_INSTANCIATED', ); } @@ -363,115 +358,101 @@ describe('Knifecycle', () => { const { test } = await $.run(['test']); - assert.deepEqual(test, 3); + expect(test).toEqual(3); }); }); test('should fail when initializer is no a function', () => { - assert.throws( - () => { - $.register('not_a_function' as any); - }, - (err) => { - assert.deepEqual((err as YError).code, 'E_BAD_INITIALIZER'); - assert.deepEqual((err as YError).params, ['not_a_function']); - return true; - }, - ); + try { + $.register('not_a_function' as any); + + throw new YError('E_UNEXPECTED_SUCCESS'); + } catch (err) { + expect((err as YError).code).toEqual('E_BAD_INITIALIZER'); + expect((err as YError).params).toEqual(['not_a_function']); + } }); test('should fail with no service name', () => { - assert.throws( - () => { - $.register(async () => undefined); - }, - (err) => { - assert.deepEqual((err as YError).code, 'E_ANONYMOUS_ANALYZER'); - assert.deepEqual((err as YError).params, []); - return true; - }, - ); + try { + $.register(async () => undefined); + + throw new YError('E_UNEXPECTED_SUCCESS'); + } catch (err) { + expect((err as YError).code).toEqual('E_ANONYMOUS_ANALYZER'); + expect((err as YError).params).toEqual([]); + } }); test('should fail with a bad service type', () => { - assert.throws( - () => { - const fn = async () => undefined; - fn[SPECIAL_PROPS.NAME] = 'test'; - fn[SPECIAL_PROPS.TYPE] = 'not_allowed_type'; - $.register(fn); - }, - (err) => { - assert.deepEqual((err as YError).code, 'E_BAD_INITIALIZER_TYPE'); - assert.deepEqual((err as YError).params, [ - 'test', - 'not_allowed_type', - ALLOWED_INITIALIZER_TYPES, - ]); - return true; - }, - ); + try { + const fn = async () => undefined; + fn[SPECIAL_PROPS.NAME] = 'test'; + fn[SPECIAL_PROPS.TYPE] = 'not_allowed_type'; + $.register(fn); + + throw new YError('E_UNEXPECTED_SUCCESS'); + } catch (err) { + expect((err as YError).code).toEqual('E_BAD_INITIALIZER_TYPE'); + expect((err as YError).params).toEqual([ + 'test', + 'not_allowed_type', + ALLOWED_INITIALIZER_TYPES, + ]); + } }); test('should fail with an undefined constant', () => { - assert.throws( - () => { - const fn = async () => undefined; - fn[SPECIAL_PROPS.NAME] = 'THE_NUMBER'; - fn[SPECIAL_PROPS.TYPE] = 'constant'; - fn[SPECIAL_PROPS.VALUE] = undefined; - $.register(fn); - }, - (err) => { - assert.deepEqual( - (err as YError).code, - 'E_UNDEFINED_CONSTANT_INITIALIZER', - ); - assert.deepEqual((err as YError).params, ['THE_NUMBER']); - return true; - }, - ); + try { + const fn = async () => undefined; + fn[SPECIAL_PROPS.NAME] = 'THE_NUMBER'; + fn[SPECIAL_PROPS.TYPE] = 'constant'; + fn[SPECIAL_PROPS.VALUE] = undefined; + $.register(fn); + + throw new YError('E_UNEXPECTED_SUCCESS'); + } catch (err) { + expect((err as YError).code).toEqual( + 'E_UNDEFINED_CONSTANT_INITIALIZER', + ); + expect((err as YError).params).toEqual(['THE_NUMBER']); + } }); test('should fail with a non constant that has a value', () => { - assert.throws( - () => { - const fn = async () => undefined; - fn[SPECIAL_PROPS.NAME] = 'myService'; - fn[SPECIAL_PROPS.TYPE] = 'service'; - fn[SPECIAL_PROPS.VALUE] = 42; - $.register(fn); - }, - (err) => { - assert.deepEqual( - (err as YError).code, - 'E_BAD_VALUED_NON_CONSTANT_INITIALIZER', - ); - assert.deepEqual((err as YError).params, ['myService']); - return true; - }, - ); + try { + const fn = async () => undefined; + fn[SPECIAL_PROPS.NAME] = 'myService'; + fn[SPECIAL_PROPS.TYPE] = 'service'; + fn[SPECIAL_PROPS.VALUE] = 42; + $.register(fn); + + throw new YError('E_UNEXPECTED_SUCCESS'); + } catch (err) { + expect((err as YError).code).toEqual( + 'E_BAD_VALUED_NON_CONSTANT_INITIALIZER', + ); + expect((err as YError).params).toEqual(['myService']); + } }); test('should fail with special autoload initializer that is not a singleton', () => { - assert.throws( - () => { - $.register( - initializer( - { - name: '$autoload', - type: 'provider', - }, - async () => ({ service: () => undefined }), - ), - ); - }, - (err) => { - assert.deepEqual((err as YError).code, 'E_BAD_AUTOLOADER'); - assert.deepEqual((err as YError).params, [false]); - return true; - }, - ); + try { + $.register( + initializer( + { + name: '$autoload', + type: 'provider', + }, + async () => ({ service: () => undefined }), + ), + ); + + throw new YError('E_UNEXPECTED_SUCCESS'); + } catch (err) { + expect((err as YError).code).toEqual('E_BAD_AUTOLOADER'); + expect((err as YError).params).toEqual([false]); + } }); }); @@ -481,121 +462,96 @@ describe('Knifecycle', () => { }); test('should fail with direct circular dependencies', () => { - assert.throws( - () => { - $.register(provider(hashProvider, 'hash', ['hash'])); - }, - (err) => { - assert.deepEqual((err as YError).code, 'E_CIRCULAR_DEPENDENCY'); - assert.deepEqual((err as YError).params, ['hash']); - return true; - }, - ); + try { + $.register(provider(hashProvider, 'hash', ['hash'])); + + throw new YError('E_UNEXPECTED_SUCCESS'); + } catch (err) { + expect((err as YError).code).toEqual('E_CIRCULAR_DEPENDENCY'); + expect((err as YError).params).toEqual(['hash']); + } }); test('should fail with direct circular dependencies on mapped services', () => { - assert.throws( - () => { - $.register(provider(hashProvider, 'hash', ['hash>lol'])); - }, - (err) => { - assert.deepEqual((err as YError).code, 'E_CIRCULAR_DEPENDENCY'); - assert.deepEqual((err as YError).params, ['hash']); - return true; - }, - ); + try { + $.register(provider(hashProvider, 'hash', ['hash>lol'])); + + throw new YError('E_UNEXPECTED_SUCCESS'); + } catch (err) { + expect((err as YError).code).toEqual('E_CIRCULAR_DEPENDENCY'); + expect((err as YError).params).toEqual(['hash']); + } }); test('should fail with circular dependencies', () => { - assert.throws( - () => { - $.register(provider(inject(['hash3'], hashProvider), 'hash')); - $.register(provider(inject(['hash'], hashProvider), 'hash1')); - $.register(provider(inject(['hash1'], hashProvider), 'hash2')); - $.register(provider(inject(['hash'], hashProvider), 'hash3')); - }, - (err) => { - assert.deepEqual((err as YError).code, 'E_CIRCULAR_DEPENDENCY'); - assert.deepEqual((err as YError).params, ['hash3', 'hash', 'hash3']); - return true; - }, - ); + try { + $.register(provider(inject(['hash3'], hashProvider), 'hash')); + $.register(provider(inject(['hash'], hashProvider), 'hash1')); + $.register(provider(inject(['hash1'], hashProvider), 'hash2')); + $.register(provider(inject(['hash'], hashProvider), 'hash3')); + throw new YError('E_UNEXPECTED_SUCCESS'); + } catch (err) { + expect((err as YError).code).toEqual('E_CIRCULAR_DEPENDENCY'); + expect((err as YError).params).toEqual(['hash3', 'hash', 'hash3']); + } }); test('should fail with deeper circular dependencies', () => { - assert.throws( - () => { - $.register(provider(inject(['hash1'], hashProvider), 'hash')); - $.register(provider(inject(['hash2'], hashProvider), 'hash1')); - $.register(provider(inject(['hash3'], hashProvider), 'hash2')); - $.register(provider(inject(['hash'], hashProvider), 'hash3')); - }, - (err) => { - assert.deepEqual((err as YError).code, 'E_CIRCULAR_DEPENDENCY'); - assert.deepEqual((err as YError).params, [ - 'hash3', - 'hash', - 'hash1', - 'hash2', - 'hash3', - ]); - return true; - }, - ); + try { + $.register(provider(inject(['hash1'], hashProvider), 'hash')); + $.register(provider(inject(['hash2'], hashProvider), 'hash1')); + $.register(provider(inject(['hash3'], hashProvider), 'hash2')); + $.register(provider(inject(['hash'], hashProvider), 'hash3')); + throw new YError('E_UNEXPECTED_SUCCESS'); + } catch (err) { + expect((err as YError).code).toEqual('E_CIRCULAR_DEPENDENCY'); + expect((err as YError).params).toEqual([ + 'hash3', + 'hash', + 'hash1', + 'hash2', + 'hash3', + ]); + } }); test('should fail with circular dependencies on mapped services', () => { - assert.throws( - () => { - $.register(provider(inject(['hash3>aHash3'], hashProvider), 'hash')); - $.register(provider(inject(['hash>aHash'], hashProvider), 'hash1')); - $.register(provider(inject(['hash1>aHash1'], hashProvider), 'hash2')); - $.register(provider(inject(['hash>aHash'], hashProvider), 'hash3')); - }, - (err) => { - assert.deepEqual((err as YError).code, 'E_CIRCULAR_DEPENDENCY'); - assert.deepEqual((err as YError).params, [ - 'hash3', - 'hash>aHash', - 'hash3>aHash3', - ]); - return true; - }, - ); + try { + $.register(provider(inject(['hash3>aHash3'], hashProvider), 'hash')); + $.register(provider(inject(['hash>aHash'], hashProvider), 'hash1')); + $.register(provider(inject(['hash1>aHash1'], hashProvider), 'hash2')); + $.register(provider(inject(['hash>aHash'], hashProvider), 'hash3')); + throw new YError('E_UNEXPECTED_SUCCESS'); + } catch (err) { + expect((err as YError).code).toEqual('E_CIRCULAR_DEPENDENCY'); + expect((err as YError).params).toEqual([ + 'hash3', + 'hash>aHash', + 'hash3>aHash3', + ]); + } }); test('should fail with singleton depending on siloed services', () => { - assert.throws( - () => { - $.register(provider(hashProvider, 'hash', [], false)); - $.register(provider(hashProvider, 'hash1', ['hash'], true)); - }, - (err) => { - assert.deepEqual( - (err as YError).code, - 'E_BAD_SINGLETON_DEPENDENCIES', - ); - assert.deepEqual((err as YError).params, ['hash1', 'hash']); - return true; - }, - ); + try { + $.register(provider(hashProvider, 'hash', [], false)); + $.register(provider(hashProvider, 'hash1', ['hash'], true)); + throw new YError('E_UNEXPECTED_SUCCESS'); + } catch (err) { + expect((err as YError).code).toEqual('E_BAD_SINGLETON_DEPENDENCIES'); + expect((err as YError).params).toEqual(['hash1', 'hash']); + } }); test('should fail when setting siloed services depended on by a singleton', () => { - assert.throws( - () => { - $.register(provider(hashProvider, 'hash1', ['hash'], true)); - $.register(provider(hashProvider, 'hash', [], false)); - }, - (err) => { - assert.deepEqual( - (err as YError).code, - 'E_BAD_SINGLETON_DEPENDENCIES', - ); - assert.deepEqual((err as YError).params, ['hash1', 'hash']); - return true; - }, - ); + try { + $.register(provider(hashProvider, 'hash1', ['hash'], true)); + $.register(provider(hashProvider, 'hash', [], false)); + throw new YError('E_UNEXPECTED_SUCCESS'); + } catch (err) { + expect((err as YError).code).toEqual('E_BAD_SINGLETON_DEPENDENCIES'); + expect((err as YError).params).toEqual(['hash1', 'hash']); + } }); }); @@ -604,7 +560,7 @@ describe('Knifecycle', () => { test('with no dependencies', async () => { const dependencies = await $.run([]); - assert.deepEqual(dependencies, {}); + expect(dependencies).toEqual({}); }); test('with constant dependencies', async () => { @@ -613,8 +569,8 @@ describe('Knifecycle', () => { const dependencies = await $.run(['time', 'ENV']); - assert.deepEqual(Object.keys(dependencies), ['time', 'ENV']); - assert.deepEqual(dependencies, { + expect(Object.keys(dependencies)).toEqual(['time', 'ENV']); + expect(dependencies).toEqual({ ENV, time, }); @@ -632,8 +588,8 @@ describe('Knifecycle', () => { const dependencies = await $.run(['sample']); - assert.deepEqual(Object.keys(dependencies), ['sample']); - assert.deepEqual(dependencies, { + expect(Object.keys(dependencies)).toEqual(['sample']); + expect(dependencies).toEqual({ sample: 'function', }); }); @@ -646,8 +602,8 @@ describe('Knifecycle', () => { const dependencies = await $.run(['nullService']); - assert.deepEqual(Object.keys(dependencies), ['nullService']); - assert.deepEqual(dependencies, { + expect(Object.keys(dependencies)).toEqual(['nullService']); + expect(dependencies).toEqual({ nullService: null, }); }); @@ -660,8 +616,8 @@ describe('Knifecycle', () => { const dependencies = await $.run(['nullProvider']); - assert.deepEqual(Object.keys(dependencies), ['nullProvider']); - assert.deepEqual(dependencies, { + expect(Object.keys(dependencies)).toEqual(['nullProvider']); + expect(dependencies).toEqual({ nullProvider: null, }); }); @@ -678,11 +634,11 @@ describe('Knifecycle', () => { 'undefinedProvider', ]); - assert.deepEqual(Object.keys(dependencies), [ + expect(Object.keys(dependencies)).toEqual([ 'undefinedService', 'undefinedProvider', ]); - assert.deepEqual(dependencies, { + expect(dependencies).toEqual({ undefinedService: undefined, undefinedProvider: undefined, }); @@ -695,8 +651,8 @@ describe('Knifecycle', () => { const dependencies = await $.run(['time', 'hash']); - assert.deepEqual(Object.keys(dependencies), ['time', 'hash']); - assert.deepEqual(dependencies, { + expect(Object.keys(dependencies)).toEqual(['time', 'hash']); + expect(dependencies).toEqual({ hash: { ENV }, time, }); @@ -710,8 +666,8 @@ describe('Knifecycle', () => { const dependencies = await $.run(['time', 'hash']); - assert.deepEqual(Object.keys(dependencies), ['time', 'hash']); - assert.deepEqual(dependencies, { + expect(Object.keys(dependencies)).toEqual(['time', 'hash']); + expect(dependencies).toEqual({ hash: { ENV, DEBUG: {} }, time, }); @@ -724,8 +680,8 @@ describe('Knifecycle', () => { const dependencies = await $.run(['time', 'hash']); - assert.deepEqual(Object.keys(dependencies), ['time', 'hash']); - assert.deepEqual(dependencies, { + expect(Object.keys(dependencies)).toEqual(['time', 'hash']); + expect(dependencies).toEqual({ hash: { ENV, DEBUG: undefined }, time, }); @@ -743,11 +699,11 @@ describe('Knifecycle', () => { const dependencies = await $.run(['hash5', 'time']); - assert.deepEqual(Object.keys(dependencies), ['hash5', 'time']); + expect(Object.keys(dependencies)).toEqual(['hash5', 'time']); }); test('and instanciate services once', async () => { - const timeServiceStub = sinon.spy(timeService); + const timeServiceStub = jest.fn(timeService); $.register(constant('ENV', ENV)); $.register(service(timeServiceStub, 'time')); @@ -762,36 +718,38 @@ describe('Knifecycle', () => { 'time', ]); - assert.deepEqual(Object.keys(dependencies), [ + expect(Object.keys(dependencies)).toEqual([ 'hash', 'hash2', 'hash3', 'time', ]); - assert.deepEqual(timeServiceStub.args, [[{}]]); + expect(timeServiceStub.mock.calls).toEqual([[{}]]); }); test('and instanciate a single mapped service', async () => { - const providerStub = sinon.stub().returns( + const providerStub = jest.fn().mockReturnValue( Promise.resolve({ service: 'stub', }), ); - const providerStub2 = sinon.stub().returns( + const providerStub2 = jest.fn().mockReturnValue( Promise.resolve({ service: 'stub2', }), ); - $.register(provider(providerStub, 'mappedStub', ['stub2>mappedStub2'])); - $.register(provider(providerStub2, 'mappedStub2')); + $.register( + provider(providerStub as any, 'mappedStub', ['stub2>mappedStub2']), + ); + $.register(provider(providerStub2 as any, 'mappedStub2')); const dependencies = await $.run(['stub>mappedStub']); - assert.deepEqual(dependencies, { + expect(dependencies).toEqual({ stub: 'stub', }); - assert.deepEqual(providerStub.args, [ + expect(providerStub.mock.calls).toEqual([ [ { stub2: 'stub2', @@ -801,7 +759,7 @@ describe('Knifecycle', () => { }); test('and instanciate several services with mappings', async () => { - const timeServiceStub = sinon.spy(timeService); + const timeServiceStub = jest.fn(timeService); $.register(constant('ENV', ENV)); $.register(singleton(service(timeServiceStub, 'aTime'))); @@ -815,8 +773,8 @@ describe('Knifecycle', () => { 'time>aTime', ]); - assert.deepEqual(Object.keys(dependencies), ['hash2', 'hash3', 'time']); - assert.deepEqual(timeServiceStub.args, [[{}]]); + expect(Object.keys(dependencies)).toEqual(['hash2', 'hash3', 'time']); + expect(timeServiceStub.mock.calls).toEqual([[{}]]); }); }); @@ -828,8 +786,8 @@ describe('Knifecycle', () => { await $.run(['lol']); throw new Error('E_UNEXPECTED_SUCCESS'); } catch (err) { - assert.deepEqual((err as YError).code, 'E_BAD_SERVICE_PROMISE'); - assert.deepEqual((err as YError).params, ['lol']); + expect((err as YError).code).toEqual('E_BAD_SERVICE_PROMISE'); + expect((err as YError).params).toEqual(['lol']); } }); @@ -839,8 +797,8 @@ describe('Knifecycle', () => { await $.run(['lol']); throw new Error('E_UNEXPECTED_SUCCESS'); } catch (err) { - assert.deepEqual((err as YError).code, 'E_BAD_SERVICE_PROVIDER'); - assert.deepEqual((err as YError).params, ['lol']); + expect((err as YError).code).toEqual('E_BAD_SERVICE_PROVIDER'); + expect((err as YError).params).toEqual(['lol']); } }); @@ -850,8 +808,8 @@ describe('Knifecycle', () => { await $.run(['lol']); throw new Error('E_UNEXPECTED_SUCCESS'); } catch (err) { - assert.deepEqual((err as YError).code, 'E_BAD_SERVICE_PROVIDER'); - assert.deepEqual((err as YError).params, ['lol']); + expect((err as YError).code).toEqual('E_BAD_SERVICE_PROVIDER'); + expect((err as YError).params).toEqual(['lol']); } }); @@ -860,8 +818,8 @@ describe('Knifecycle', () => { await $.run(['lol']); throw new Error('E_UNEXPECTED_SUCCESS'); } catch (err) { - assert.deepEqual((err as YError).code, 'E_UNMATCHED_DEPENDENCY'); - assert.deepEqual((err as YError).params, ['__run__', 'lol']); + expect((err as YError).code).toEqual('E_UNMATCHED_DEPENDENCY'); + expect((err as YError).params).toEqual(['__run__', 'lol']); } }); @@ -875,8 +833,8 @@ describe('Knifecycle', () => { await $.run(['time', 'hash']); throw new Error('E_UNEXPECTED_SUCCESS'); } catch (err) { - assert.deepEqual((err as YError).code, 'E_UNMATCHED_DEPENDENCY'); - assert.deepEqual((err as YError).params, [ + expect((err as YError).code).toEqual('E_UNMATCHED_DEPENDENCY'); + expect((err as YError).params).toEqual([ '__run__', 'hash', 'hash2', @@ -919,8 +877,8 @@ describe('Knifecycle', () => { await $.run(['human']); throw new Error('E_UNEXPECTED_SUCCESS'); } catch (err) { - assert.deepEqual((err as YError).code, 'E_CIRCULAR_DEPENDENCY'); - assert.deepEqual((err as YError).params, [ + expect((err as YError).code).toEqual('E_CIRCULAR_DEPENDENCY'); + expect((err as YError).params).toEqual([ '__run__', 'human', 'tree', @@ -977,7 +935,7 @@ describe('Knifecycle', () => { await process.fatalErrorPromise; throw new Error('E_UNEXPECTED_SUCCESS'); } catch (err) { - assert.deepEqual((err as Error).message, 'E_DB_ERROR'); + expect((err as Error).message).toEqual('E_DB_ERROR'); } }); }); @@ -1008,8 +966,8 @@ describe('Knifecycle', () => { const dependencies = await $.run(['time', 'hash']); - assert.deepEqual(Object.keys(dependencies), ['time', 'hash']); - assert.deepEqual(dependencies, { + expect(Object.keys(dependencies)).toEqual(['time', 'hash']); + expect(dependencies).toEqual({ hash: { ENV: 'value_of:ENV', DEBUG: 'value_of:DEBUG' }, time: 'value_of:time', }); @@ -1047,8 +1005,8 @@ describe('Knifecycle', () => { const dependencies = await $.run(['time', 'hash']); - assert.deepEqual(Object.keys(dependencies), ['time', 'hash']); - assert.deepEqual(dependencies, { + expect(Object.keys(dependencies)).toEqual(['time', 'hash']); + expect(dependencies).toEqual({ hash: { ENV, DEBUG: 'THE_DEBUG:DEBUG' }, time, }); @@ -1089,7 +1047,7 @@ describe('Knifecycle', () => { const dependencies = await $.run(['hash5', 'time']); - assert.deepEqual(Object.keys(dependencies), ['hash5', 'time']); + expect(Object.keys(dependencies)).toEqual(['hash5', 'time']); }); test('with various dependencies', async () => { @@ -1126,7 +1084,7 @@ describe('Knifecycle', () => { const dependencies = await $.run(['hash', '?ENV']); - assert.deepEqual(Object.keys(dependencies), ['hash', 'ENV']); + expect(Object.keys(dependencies)).toEqual(['hash', 'ENV']); }); test('and instantiate services once', async () => { @@ -1150,7 +1108,7 @@ describe('Knifecycle', () => { }), ), ); - const timeServiceStub = sinon.spy(timeService); + const timeServiceStub = jest.fn(timeService); $.register(constant('ENV', ENV)); $.register(service(timeServiceStub, 'time')); @@ -1161,8 +1119,8 @@ describe('Knifecycle', () => { const dependencies = await $.run(['hash', 'hash_', 'hash3']); - assert.deepEqual(timeServiceStub.args, [[{}]]); - assert.deepEqual(Object.keys(dependencies), ['hash', 'hash_', 'hash3']); + expect(timeServiceStub.mock.calls).toEqual([[{}]]); + expect(Object.keys(dependencies)).toEqual(['hash', 'hash_', 'hash3']); }); test('with null service dependencies', async () => { @@ -1186,8 +1144,8 @@ describe('Knifecycle', () => { const dependencies = await $.run(['nullService']); - assert.deepEqual(Object.keys(dependencies), ['nullService']); - assert.deepEqual(dependencies, { + expect(Object.keys(dependencies)).toEqual(['nullService']); + expect(dependencies).toEqual({ nullService: null, }); }); @@ -1213,8 +1171,8 @@ describe('Knifecycle', () => { const dependencies = await $.run(['nullProvider']); - assert.deepEqual(Object.keys(dependencies), ['nullProvider']); - assert.deepEqual(dependencies, { + expect(Object.keys(dependencies)).toEqual(['nullProvider']); + expect(dependencies).toEqual({ nullProvider: null, }); }); @@ -1246,13 +1204,13 @@ describe('Knifecycle', () => { 'undefinedProvider', ]); - assert.deepEqual(Object.keys(dependencies), [ + expect(Object.keys(dependencies)).toEqual([ 'undefinedService', 'undefinedProvider', ]); - assert.deepEqual(dependencies, { + expect(dependencies).toEqual({ undefinedService: undefined, - undefinedProvider: null, + undefinedProvider: undefined, }); }); @@ -1281,7 +1239,7 @@ describe('Knifecycle', () => { const dependencies = await $.run(['test']); - assert.deepEqual(Object.keys(dependencies), ['test']); + expect(Object.keys(dependencies)).toEqual(['test']); }); test('when autoload depends on deeper optional and unexisting autoloaded dependencies', async () => { @@ -1324,7 +1282,7 @@ describe('Knifecycle', () => { const dependencies = await $.run(['test', 'log']); - assert.deepEqual(Object.keys(dependencies), ['test', 'log']); + expect(Object.keys(dependencies)).toEqual(['test', 'log']); }); }); @@ -1334,7 +1292,7 @@ describe('Knifecycle', () => { await $.run(['test']); throw new YError('E_UNEXPECTED_SUCCESS'); } catch (err) { - assert.equal((err as YError).code, 'E_UNMATCHED_DEPENDENCY'); + expect((err as YError).code).toEqual('E_UNMATCHED_DEPENDENCY'); } }); @@ -1357,16 +1315,14 @@ describe('Knifecycle', () => { await $.run(['test']); throw new YError('E_UNEXPECTED_SUCCESS'); } catch (err) { - assert.equal((err as YError).code, 'E_BAD_AUTOLOADED_INITIALIZER'); - assert.deepEqual((err as YError).params, ['test']); - assert.equal( - ((err as YError).wrappedErrors[0] as YError).code, + expect((err as YError).code).toEqual('E_BAD_AUTOLOADED_INITIALIZER'); + expect((err as YError).params).toEqual(['test']); + expect(((err as YError).wrappedErrors[0] as YError).code).toEqual( 'E_CANNOT_AUTOLOAD', ); - assert.deepEqual( - ((err as YError).wrappedErrors[0] as YError).params, - ['test'], - ); + expect(((err as YError).wrappedErrors[0] as YError).params).toEqual([ + 'test', + ]); } }); @@ -1415,16 +1371,16 @@ describe('Knifecycle', () => { await $.run(['test', 'log']); throw new YError('E_UNEXPECTED_SUCCESS'); } catch (err) { - assert.equal((err as YError).code, 'E_BAD_AUTOLOADED_INITIALIZER'); - assert.deepEqual((err as YError).params, ['parentService2']); - assert.equal( - ((err as YError).wrappedErrors[0] as YError).code, + expect((err as YError).code).toEqual('E_BAD_AUTOLOADED_INITIALIZER'); + expect((err as YError).params).toEqual(['parentService2']); + expect(((err as YError).wrappedErrors[0] as YError).code).toEqual( 'E_CIRCULAR_DEPENDENCY', ); - assert.deepEqual( - ((err as YError).wrappedErrors[0] as YError).params, - ['parentService2', 'parentService1', 'parentService2'], - ); + expect(((err as YError).wrappedErrors[0] as YError).params).toEqual([ + 'parentService2', + 'parentService1', + 'parentService2', + ]); } }); @@ -1445,16 +1401,15 @@ describe('Knifecycle', () => { await $.run(['test']); throw new YError('E_UNEXPECTED_SUCCESS'); } catch (err) { - assert.equal((err as YError).code, 'E_BAD_AUTOLOADED_INITIALIZER'); - assert.deepEqual((err as YError).params, ['test']); - assert.equal( - ((err as YError).wrappedErrors[0] as YError).code, + expect((err as YError).code).toEqual('E_BAD_AUTOLOADED_INITIALIZER'); + expect((err as YError).params).toEqual(['test']); + expect(((err as YError).wrappedErrors[0] as YError).code).toEqual( 'E_BAD_AUTOLOADER_RESULT', ); - assert.deepEqual( - ((err as YError).wrappedErrors[0] as YError).params, - ['test', 'not_an_initializer'], - ); + expect(((err as YError).wrappedErrors[0] as YError).params).toEqual([ + 'test', + 'not_an_initializer', + ]); } }); @@ -1478,16 +1433,15 @@ describe('Knifecycle', () => { await $.run(['test']); throw new YError('E_UNEXPECTED_SUCCESS'); } catch (err) { - assert.equal((err as YError).code, 'E_BAD_AUTOLOADED_INITIALIZER'); - assert.deepEqual((err as YError).params, ['test']); - assert.equal( - ((err as YError).wrappedErrors[0] as YError).code, + expect((err as YError).code).toEqual('E_BAD_AUTOLOADED_INITIALIZER'); + expect((err as YError).params).toEqual(['test']); + expect(((err as YError).wrappedErrors[0] as YError).code).toEqual( 'E_AUTOLOADED_INITIALIZER_MISMATCH', ); - assert.deepEqual( - ((err as YError).wrappedErrors[0] as YError).params, - ['test', undefined], - ); + expect(((err as YError).wrappedErrors[0] as YError).params).toEqual([ + 'test', + undefined, + ]); } }); @@ -1518,16 +1472,15 @@ describe('Knifecycle', () => { await $.run(['test']); throw new YError('E_UNEXPECTED_SUCCESS'); } catch (err) { - assert.equal((err as YError).code, 'E_BAD_AUTOLOADED_INITIALIZER'); - assert.deepEqual((err as YError).params, ['test']); - assert.equal( - ((err as YError).wrappedErrors[0] as YError).code, + expect((err as YError).code).toEqual('E_BAD_AUTOLOADED_INITIALIZER'); + expect((err as YError).params).toEqual(['test']); + expect(((err as YError).wrappedErrors[0] as YError).code).toEqual( 'E_AUTOLOADED_INITIALIZER_MISMATCH', ); - assert.deepEqual( - ((err as YError).wrappedErrors[0] as YError).params, - ['test', 'not-test'], - ); + expect(((err as YError).wrappedErrors[0] as YError).params).toEqual([ + 'test', + 'not-test', + ]); } }); @@ -1558,8 +1511,8 @@ describe('Knifecycle', () => { await $.run(['test']); throw new YError('E_UNEXPECTED_SUCCESS'); } catch (err) { - assert.equal((err as YError).code, 'E_UNMATCHED_DEPENDENCY'); - assert.deepEqual((err as YError).params, ['__run__', 'test']); + expect((err as YError).code).toEqual('E_UNMATCHED_DEPENDENCY'); + expect((err as YError).params).toEqual(['__run__', 'test']); } }); }); @@ -1572,15 +1525,11 @@ describe('Knifecycle', () => { $.register(provider(hashProvider, 'hash', ['ENV'])); const dependencies = await $.run(['time', 'hash', '$injector']); - assert.deepEqual(Object.keys(dependencies), [ - 'time', - 'hash', - '$injector', - ]); + expect(Object.keys(dependencies)).toEqual(['time', 'hash', '$injector']); const injectDependencies = await dependencies.$injector([]); - assert.deepEqual(Object.keys(injectDependencies), []); - assert.deepEqual(injectDependencies, {}); + expect(Object.keys(injectDependencies)).toEqual([]); + expect(injectDependencies).toEqual({}); }); test('should work with same dependencies then the running silo', async () => { @@ -1589,15 +1538,11 @@ describe('Knifecycle', () => { $.register(provider(hashProvider, 'hash', ['ENV'])); const dependencies = await $.run(['time', 'hash', '$injector']); - assert.deepEqual(Object.keys(dependencies), [ - 'time', - 'hash', - '$injector', - ]); + expect(Object.keys(dependencies)).toEqual(['time', 'hash', '$injector']); const injectDependencies = await dependencies.$injector(['time', 'hash']); - assert.deepEqual(Object.keys(injectDependencies), ['time', 'hash']); - assert.deepEqual(injectDependencies, { + expect(Object.keys(injectDependencies)).toEqual(['time', 'hash']); + expect(injectDependencies).toEqual({ hash: { ENV }, time, }); @@ -1609,18 +1554,14 @@ describe('Knifecycle', () => { $.register(provider(hashProvider, 'hash', ['ENV'])); const dependencies = await $.run(['time', 'hash', '$injector']); - assert.deepEqual(Object.keys(dependencies), [ - 'time', - 'hash', - '$injector', - ]); + expect(Object.keys(dependencies)).toEqual(['time', 'hash', '$injector']); const injectDependencies = await dependencies.$injector([ 'aTime>time', 'aHash>hash', ]); - assert.deepEqual(Object.keys(injectDependencies), ['aTime', 'aHash']); - assert.deepEqual(injectDependencies, { + expect(Object.keys(injectDependencies)).toEqual(['aTime', 'aHash']); + expect(injectDependencies).toEqual({ aHash: { ENV }, aTime: time, }); @@ -1632,11 +1573,11 @@ describe('Knifecycle', () => { $.register(provider(hashProvider, 'hash', ['ENV'])); const dependencies = await $.run(['time', '$injector']); - assert.deepEqual(Object.keys(dependencies), ['time', '$injector']); + expect(Object.keys(dependencies)).toEqual(['time', '$injector']); const injectDependencies = await dependencies.$injector(['time', 'hash']); - assert.deepEqual(Object.keys(injectDependencies), ['time', 'hash']); - assert.deepEqual(injectDependencies, { + expect(Object.keys(injectDependencies)).toEqual(['time', 'hash']); + expect(injectDependencies).toEqual({ hash: { ENV }, time, }); @@ -1651,11 +1592,11 @@ describe('Knifecycle', () => { $.run(['hash']), ]); - assert.notEqual(hash, sameHash); + expect(hash).not.toBe(sameHash); const { hash: yaSameHash } = await $.run(['hash']); - assert.notEqual(hash, yaSameHash); + expect(hash).not.toBe(yaSameHash); }); test('should reuse dependencies when declared as singletons', async () => { @@ -1670,18 +1611,18 @@ describe('Knifecycle', () => { $.run(['hash2']), $.run(['hash2']), ]); - assert.equal(hash, sameHash); - assert.equal(hash2, sameHash2); + expect(hash).toEqual(sameHash); + expect(hash2).toEqual(sameHash2); const { hash: yaSameHash } = await $.run(['hash']); - assert.equal(hash, yaSameHash); + expect(hash).toEqual(yaSameHash); }); }); describe('destroy', () => { test('should work even with one silo and no dependencies', async () => { - assert.equal(typeof $.destroy, 'function'); + expect(typeof $.destroy).toEqual('function'); const dependencies = await $.run(['$instance']); await dependencies.$instance.destroy(); @@ -1700,7 +1641,7 @@ describe('Knifecycle', () => { $.run(['ENV', 'hash', 'hash2']), ]); - assert.equal(typeof dependencies.$instance.destroy, 'function'); + expect(typeof dependencies.$instance.destroy).toEqual('function'); await $.destroy(); }); @@ -1752,7 +1693,7 @@ describe('Knifecycle', () => { const dependencies = await $.run(['$instance']); - assert.equal(typeof dependencies.$instance.destroy, 'function'); + expect(typeof dependencies.$instance.destroy).toEqual('function'); await dependencies.$instance.destroy(); @@ -1760,7 +1701,7 @@ describe('Knifecycle', () => { await $.run(['ENV', 'hash', 'hash1']); throw new YError('E_UNEXPECTED_SUCCESS'); } catch (err) { - assert.equal((err as YError).code, 'E_INSTANCE_DESTROYED'); + expect((err as YError).code).toEqual('E_INSTANCE_DESTROYED'); } }); }); @@ -1768,7 +1709,7 @@ describe('Knifecycle', () => { describe('$dispose', () => { test('should work with no dependencies', async () => { const dependencies = await $.run(['$dispose']); - assert.equal(typeof dependencies.$dispose, 'function'); + expect(typeof dependencies.$dispose).toEqual('function'); return dependencies.$dispose(); }); @@ -1778,7 +1719,7 @@ describe('Knifecycle', () => { $.register(constant('time', time)); const dependencies = await $.run(['time', 'ENV', '$dispose']); - assert.deepEqual(Object.keys(dependencies), ['time', 'ENV', '$dispose']); + expect(Object.keys(dependencies)).toEqual(['time', 'ENV', '$dispose']); await dependencies.$dispose(); }); @@ -1789,7 +1730,7 @@ describe('Knifecycle', () => { $.register(provider(hashProvider, 'hash', ['ENV'])); const dependencies = await $.run(['time', 'hash', '$dispose']); - assert.deepEqual(Object.keys(dependencies), ['time', 'hash', '$dispose']); + expect(Object.keys(dependencies)).toEqual(['time', 'hash', '$dispose']); await dependencies.$dispose(); }); @@ -1800,7 +1741,7 @@ describe('Knifecycle', () => { const shutdownCallPromise = new Promise((resolve) => { shutdownCallResolve = resolve; }); - const shutdownStub = sinon.spy(() => { + const shutdownStub = jest.fn(() => { shutdownCallResolve(); return new Promise((resolve) => { shutdownResolve = resolve; @@ -1824,7 +1765,7 @@ describe('Knifecycle', () => { shutdownResolve, }, dispose: shutdownStub, - }), + }) as any, 'shutdownChecker', ['hash4'], ), @@ -1836,7 +1777,7 @@ describe('Knifecycle', () => { '$dispose', 'shutdownChecker', ]); - assert.deepEqual(Object.keys(dependencies), [ + expect(Object.keys(dependencies)).toEqual([ 'hash5', 'time', '$dispose', @@ -1844,7 +1785,7 @@ describe('Knifecycle', () => { ]); const finalPromise = shutdownCallPromise.then(() => { - assert.deepEqual(shutdownStub.args, [[]]); + expect(shutdownStub.mock.calls).toEqual([[]]); shutdownResolve(); }); await dependencies.$dispose(); @@ -1857,7 +1798,7 @@ describe('Knifecycle', () => { const shutdownCallPromise = new Promise((resolve) => { shutdownCallResolve = resolve; }); - const shutdownStub = sinon.spy(() => { + const shutdownStub = jest.fn(() => { shutdownCallResolve(); return new Promise((resolve) => { shutdownResolve = resolve; @@ -1875,7 +1816,7 @@ describe('Knifecycle', () => { shutdownResolve, }, dispose: shutdownStub, - }), + }) as any, 'shutdownChecker', ['hash'], ), @@ -1889,7 +1830,7 @@ describe('Knifecycle', () => { '$dispose', 'shutdownChecker', ]); - assert.deepEqual(Object.keys(dependencies), [ + expect(Object.keys(dependencies)).toEqual([ 'hash1', 'hash2', '$dispose', @@ -1897,7 +1838,7 @@ describe('Knifecycle', () => { ]); const finalPromise = shutdownCallPromise.then(() => { - assert.deepEqual(shutdownStub.args, [[]]); + expect(shutdownStub.mock.calls).toEqual([[]]); shutdownResolve(); }); @@ -1906,7 +1847,7 @@ describe('Knifecycle', () => { }); test('should delay service shutdown to their deeper dependencies', async () => { - const servicesShutdownCalls = sinon.spy(() => Promise.resolve()); + const servicesShutdownCalls = jest.fn(() => Promise.resolve()); $.register( provider( @@ -1942,10 +1883,10 @@ describe('Knifecycle', () => { ); const dependencies = await $.run(['hash2', '$dispose']); - assert.deepEqual(Object.keys(dependencies), ['hash2', '$dispose']); + expect(Object.keys(dependencies)).toEqual(['hash2', '$dispose']); await dependencies.$dispose(); - assert.deepEqual(servicesShutdownCalls.args, [ + expect(servicesShutdownCalls.mock.calls).toEqual([ ['hash2'], ['hash1'], ['hash'], @@ -1960,12 +1901,12 @@ describe('Knifecycle', () => { const { hash } = await $.run(['time', 'hash']); const dependencies = await $.run(['time', 'hash', '$dispose']); - assert.equal(dependencies.hash, hash); + expect(dependencies.hash).toEqual(hash); await dependencies.$dispose(); const newDependencies = await $.run(['time', 'hash']); - assert.equal(newDependencies.hash, hash); + expect(newDependencies.hash).toEqual(hash); }); test('should shutdown singleton dependencies if not used elsewhere', async () => { @@ -1978,7 +1919,8 @@ describe('Knifecycle', () => { await $dispose(); const dependencies = await $.run(['time', 'hash']); - assert.notEqual(dependencies.hash, hash); + + expect(dependencies.hash).not.toBe(hash); }); }); @@ -1986,7 +1928,7 @@ describe('Knifecycle', () => { test('should print nothing when no dependency', () => { $.register(constant('ENV', ENV)); $.register(constant('time', time)); - assert.equal($.toMermaidGraph(), ''); + expect($.toMermaidGraph()).toEqual(''); }); test('should print a dependency graph', () => { @@ -1998,8 +1940,7 @@ describe('Knifecycle', () => { $.register(provider(hashProvider, 'hash3', ['hash2'])); $.register(provider(hashProvider, 'hash4', ['hash3'])); $.register(provider(hashProvider, 'hash5', ['hash4'])); - assert.equal( - $.toMermaidGraph(), + expect($.toMermaidGraph()).toEqual( 'graph TD\n' + ' hash-->ENV\n' + ' hash1-->hash\n' + @@ -2019,7 +1960,7 @@ describe('Knifecycle', () => { $.register(provider(hashProvider, 'hash3', ['hash2'])); $.register(provider(hashProvider, 'hash4', ['hash3'])); $.register(provider(hashProvider, 'hash5', ['hash4'])); - assert.equal( + expect( $.toMermaidGraph({ shapes: [ { @@ -2036,6 +1977,7 @@ describe('Knifecycle', () => { }, ], }), + ).toEqual( 'graph TD\n' + ' hash[hash]-->ENV{ENV}\n' + ' hash1((1))-->hash[hash]\n' + @@ -2055,7 +1997,7 @@ describe('Knifecycle', () => { $.register(provider(hashProvider, 'hash3', ['hash2'])); $.register(provider(hashProvider, 'hash4', ['hash3'])); $.register(provider(hashProvider, 'hash5', ['hash4'])); - assert.equal( + expect( $.toMermaidGraph({ classes: { exotic: 'fill:#f9f,stroke:#333,stroke-width:4px;', @@ -2085,6 +2027,7 @@ describe('Knifecycle', () => { }, ], }), + ).toEqual( 'graph TD\n' + ' hash[hash]-->ENV{ENV}\n' + ' hash1((1))-->hash[hash]\n' + diff --git a/src/index.ts b/src/index.ts index e5c74fd..246c161 100644 --- a/src/index.ts +++ b/src/index.ts @@ -53,7 +53,7 @@ import type { Provider, Dependencies, DependencyDeclaration, - ExtraInformations, + ExtraInformation, ParsedDependencyDeclaration, ConstantProperties, ConstantInitializer, @@ -85,7 +85,7 @@ export type { Provider, Dependencies, DependencyDeclaration, - ExtraInformations, + ExtraInformation, ParsedDependencyDeclaration, ConstantProperties, ConstantInitializer, diff --git a/src/sequence.test.ts b/src/sequence.test.ts index c09785d..32a6050 100644 --- a/src/sequence.test.ts +++ b/src/sequence.test.ts @@ -1,5 +1,4 @@ -import { describe, test } from '@jest/globals'; -import assert from 'assert'; +import { describe, test, expect } from '@jest/globals'; import { buildInitializationSequence } from './sequence.js'; describe('buildInitializationSequence()', () => { @@ -8,7 +7,7 @@ describe('buildInitializationSequence()', () => { __name: 'lol', }; - assert.deepEqual(buildInitializationSequence(tree), [['lol']]); + expect(buildInitializationSequence(tree)).toEqual([['lol']]); }); test('should work with multi-level trees', () => { @@ -58,7 +57,7 @@ describe('buildInitializationSequence()', () => { ], }; - assert.deepEqual(buildInitializationSequence(tree), [ + expect(buildInitializationSequence(tree)).toEqual([ ['lol 1.1.1', 'lol 1.2', 'lol 2.1', 'lol 3.1.1'], ['lol 1.1', 'lol 2', 'lol 3.1'], ['lol 1', 'lol 3'], @@ -142,7 +141,7 @@ describe('buildInitializationSequence()', () => { ], }; - assert.deepEqual(buildInitializationSequence(tree), [ + expect(buildInitializationSequence(tree)).toEqual([ ['lol 1.1.1', 'lol 1.2', 'lol 2.1'], ['lol 1.1', 'lol 2'], ['lol 3.1'], diff --git a/src/util.test.ts b/src/util.test.ts index 79d3054..c4325fa 100644 --- a/src/util.test.ts +++ b/src/util.test.ts @@ -1,8 +1,6 @@ /* eslint-disable @typescript-eslint/no-unused-vars */ /* eslint-disable @typescript-eslint/no-explicit-any */ -import { describe, test } from '@jest/globals'; -import assert from 'assert'; -import sinon from 'sinon'; +import { describe, test, expect, jest } from '@jest/globals'; import { reuseSpecialProps, wrapInitializer, @@ -31,6 +29,7 @@ import { } from './util.js'; import type { Provider } from './util.js'; import type { Dependencies, ServiceInitializer } from './index.js'; +import { YError } from 'yerror'; async function aProviderInitializer() { return { @@ -62,27 +61,27 @@ describe('reuseSpecialProps', () => { const newFn = reuseSpecialProps(from, to); - assert.notEqual(newFn, to); - assert.equal((newFn as any).$name, from.$name); - assert.equal((newFn as any).$type, from.$type); - assert.notEqual((newFn as any).$inject, from.$inject); - assert.deepEqual((newFn as any).$inject, from.$inject); - assert.equal((newFn as any).$singleton, from.$singleton); - assert.notEqual((newFn as any).$extra, from.$extra); - assert.deepEqual((newFn as any).$extra, from.$extra); + expect(newFn).not.toEqual(to); + expect((newFn as any).$name).toEqual(from.$name); + expect((newFn as any).$type).toEqual(from.$type); + expect((newFn as any).$inject).not.toBe(from.$inject); + expect((newFn as any).$inject).toEqual(from.$inject); + expect((newFn as any).$singleton).toEqual(from.$singleton); + expect((newFn as any).$extra).not.toBe(from.$extra); + expect((newFn as any).$extra).toEqual(from.$extra); const newFn2 = reuseSpecialProps(from, to, { $name: 'yolo', }); - assert.notEqual(newFn2, to); - assert.equal((newFn2 as any).$name, 'yolo'); - assert.equal((newFn2 as any).$type, from.$type); - assert.notEqual((newFn2 as any).$inject, from.$inject); - assert.deepEqual((newFn2 as any).$inject, from.$inject); - assert.equal((newFn2 as any).$singleton, from.$singleton); - assert.notEqual((newFn as any).$extra, from.$extra); - assert.deepEqual((newFn as any).$extra, from.$extra); + expect(newFn2).not.toEqual(to); + expect((newFn2 as any).$name).toEqual('yolo'); + expect((newFn2 as any).$type).toEqual(from.$type); + expect((newFn2 as any).$inject).not.toBe(from.$inject); + expect((newFn2 as any).$inject).toEqual(from.$inject); + expect((newFn2 as any).$singleton).toEqual(from.$singleton); + expect((newFn as any).$extra).not.toBe(from.$extra); + expect((newFn as any).$extra).toEqual(from.$extra); }); }); @@ -92,7 +91,7 @@ describe('wrapInitializer', () => { return () => 'test'; } - const log = sinon.stub(); + const log = jest.fn(); const newInitializer = wrapInitializer( async ({ log }: { log: any }, service: () => string) => { log('Wrapping...'); @@ -110,9 +109,9 @@ describe('wrapInitializer', () => { ); const newService = await newInitializer({ log }); - assert.equal(newService(), 'test-wrapped'); - assert.deepEqual(log.args, [['Wrapping...']]); - assert.deepEqual(newInitializer[SPECIAL_PROPS.INJECT], ['log', '?test']); + expect(newService()).toEqual('test-wrapped'); + expect(log.mock.calls).toEqual([['Wrapping...']]); + expect(newInitializer[SPECIAL_PROPS.INJECT]).toEqual(['log', '?test']); }); test('should work with a provider initialzer', async () => { @@ -120,7 +119,7 @@ describe('wrapInitializer', () => { return { service: () => 'test' }; } - const log = sinon.stub(); + const log = jest.fn(); const baseProviderInitializer = provider( baseInitializer, 'baseInitializer', @@ -142,9 +141,9 @@ describe('wrapInitializer', () => { ); const newService = await newInitializer({ log }); - assert.equal(newService.service(), 'test-wrapped'); - assert.deepEqual(log.args, [['Wrapping...']]); - assert.deepEqual(newInitializer[SPECIAL_PROPS.INJECT], ['log', '?test']); + expect(newService.service()).toEqual('test-wrapped'); + expect(log.mock.calls).toEqual([['Wrapping...']]); + expect(newInitializer[SPECIAL_PROPS.INJECT]).toEqual(['log', '?test']); }); }); @@ -156,9 +155,9 @@ describe('inject', () => { provider(aProviderInitializer, 'aProvider'), ); - assert.notEqual(newInitializer, aProviderInitializer); - assert.notEqual(newInitializer[SPECIAL_PROPS.INJECT], dependencies); - assert.deepEqual(newInitializer[SPECIAL_PROPS.INJECT], dependencies); + expect(newInitializer).not.toEqual(aProviderInitializer); + expect(newInitializer[SPECIAL_PROPS.INJECT]).not.toBe(dependencies); + expect(newInitializer[SPECIAL_PROPS.INJECT]).toEqual(dependencies); }); test('should allow to decorate an initializer builder with dependencies', () => { @@ -168,9 +167,9 @@ describe('inject', () => { aProviderInitializer, ); - assert.notEqual(newInitializer, aProviderInitializer); - assert.notEqual(newInitializer[SPECIAL_PROPS.INJECT], dependencies); - assert.deepEqual(newInitializer[SPECIAL_PROPS.INJECT], dependencies); + expect(newInitializer).not.toEqual(aProviderInitializer); + expect(newInitializer[SPECIAL_PROPS.INJECT]).not.toBe(dependencies); + expect(newInitializer[SPECIAL_PROPS.INJECT]).toEqual(dependencies); }); test('should allow to decorate an initializer with dependencies', () => { @@ -180,9 +179,9 @@ describe('inject', () => { service(aServiceInitializer, 'aService'), ); - assert.notEqual(newInitializer, aServiceInitializer); - assert.notEqual(newInitializer[SPECIAL_PROPS.INJECT], dependencies); - assert.deepEqual(newInitializer[SPECIAL_PROPS.INJECT], dependencies); + expect(newInitializer).not.toEqual(aServiceInitializer); + expect(newInitializer[SPECIAL_PROPS.INJECT]).not.toBe(dependencies); + expect(newInitializer[SPECIAL_PROPS.INJECT]).toEqual(dependencies); }); test('should allow to decorate an initializer builder with dependencies', () => { @@ -192,22 +191,22 @@ describe('inject', () => { aServiceInitializer, ); - assert.notEqual(newInitializer, aServiceInitializer); - assert.notEqual(newInitializer[SPECIAL_PROPS.INJECT], dependencies); - assert.deepEqual(newInitializer[SPECIAL_PROPS.INJECT], dependencies); + expect(newInitializer).not.toEqual(aServiceInitializer); + expect(newInitializer[SPECIAL_PROPS.INJECT]).not.toBe(dependencies); + expect(newInitializer[SPECIAL_PROPS.INJECT]).toEqual(dependencies); }); test('should allow to decorate an initializer with mapped dependencies', () => { const dependencies = ['ANOTHER_ENV>ENV']; const newInitializer = inject(dependencies, aProviderInitializer); - assert.notEqual(newInitializer, aProviderInitializer); - assert.notEqual(newInitializer[SPECIAL_PROPS.INJECT], dependencies); - assert.deepEqual(newInitializer[SPECIAL_PROPS.INJECT], dependencies); + expect(newInitializer).not.toEqual(aProviderInitializer); + expect(newInitializer[SPECIAL_PROPS.INJECT]).not.toBe(dependencies); + expect(newInitializer[SPECIAL_PROPS.INJECT]).toEqual(dependencies); }); test('should fail with a constant', () => { - assert.throws(() => { + try { inject( ['test'], constant('test', 'test') as unknown as ServiceInitializer< @@ -215,7 +214,10 @@ describe('inject', () => { unknown >, ); - }, /E_BAD_INJECT_IN_CONSTANT/); + throw new YError('E_UNEXPECTED_SUCCESS'); + } catch (err) { + expect((err as YError).code).toEqual('E_BAD_INJECT_IN_CONSTANT'); + } }); }); describe('useInject', () => { @@ -226,12 +228,10 @@ describe('useInject', () => { const toInitializer = inject(toDependencies, aProviderInitializer); const newInitializer = useInject(fromInitializer, toInitializer); - assert.notEqual(newInitializer, aProviderInitializer); - assert.notEqual(newInitializer[SPECIAL_PROPS.INJECT], fromDependencies); - assert.notEqual(newInitializer[SPECIAL_PROPS.INJECT], toDependencies); - assert.deepEqual(newInitializer[SPECIAL_PROPS.INJECT], [ - ...fromDependencies, - ]); + expect(newInitializer).not.toEqual(aProviderInitializer); + expect(newInitializer[SPECIAL_PROPS.INJECT]).not.toBe(fromDependencies); + expect(newInitializer[SPECIAL_PROPS.INJECT]).not.toEqual(toDependencies); + expect(newInitializer[SPECIAL_PROPS.INJECT]).toEqual([...fromDependencies]); }); }); @@ -249,10 +249,10 @@ describe('mergeInject', () => { const toInitializer = inject(toDependencies, aProviderInitializer); const newInitializer = mergeInject(fromInitializer, toInitializer); - assert.notEqual(newInitializer, aProviderInitializer); - assert.notEqual(newInitializer[SPECIAL_PROPS.INJECT], fromDependencies); - assert.notEqual(newInitializer[SPECIAL_PROPS.INJECT], toDependencies); - assert.deepEqual(newInitializer[SPECIAL_PROPS.INJECT], [ + expect(newInitializer).not.toEqual(aProviderInitializer); + expect(newInitializer[SPECIAL_PROPS.INJECT]).not.toBe(fromDependencies); + expect(newInitializer[SPECIAL_PROPS.INJECT]).not.toEqual(toDependencies); + expect(newInitializer[SPECIAL_PROPS.INJECT]).toEqual([ ...toDependencies, ...fromDependencies, ]); @@ -273,9 +273,9 @@ describe('unInject', () => { const initializer = inject(dependencies, baseProvider); const newInitializer = unInject(removedDependencies, initializer); - assert.notEqual(newInitializer, baseProvider); - assert.notEqual(newInitializer[SPECIAL_PROPS.INJECT], dependencies); - assert.deepEqual(newInitializer[SPECIAL_PROPS.INJECT], leftDependencies); + expect(newInitializer).not.toEqual(baseProvider); + expect(newInitializer[SPECIAL_PROPS.INJECT]).not.toBe(dependencies); + expect(newInitializer[SPECIAL_PROPS.INJECT]).toEqual(leftDependencies); }); test('should allow to remove dependencies', () => { @@ -291,9 +291,9 @@ describe('unInject', () => { const initializer = inject(dependencies, baseProvider); const newInitializer = unInject(removedDependencies, initializer); - assert.notEqual(newInitializer, baseProvider); - assert.notEqual(newInitializer[SPECIAL_PROPS.INJECT], dependencies); - assert.deepEqual(newInitializer[SPECIAL_PROPS.INJECT], leftDependencies); + expect(newInitializer).not.toEqual(baseProvider); + expect(newInitializer[SPECIAL_PROPS.INJECT]).not.toEqual(dependencies); + expect(newInitializer[SPECIAL_PROPS.INJECT]).toEqual(leftDependencies); }); test('should allow to remove mapped dependencies', () => { @@ -309,9 +309,9 @@ describe('unInject', () => { const initializer = inject(dependencies, baseProvider); const newInitializer = unInject(removedDependencies, initializer); - assert.notEqual(newInitializer, baseProvider); - assert.notEqual(newInitializer[SPECIAL_PROPS.INJECT], dependencies); - assert.deepEqual(newInitializer[SPECIAL_PROPS.INJECT], leftDependencies); + expect(newInitializer).not.toEqual(baseProvider); + expect(newInitializer[SPECIAL_PROPS.INJECT]).not.toEqual(dependencies); + expect(newInitializer[SPECIAL_PROPS.INJECT]).toEqual(leftDependencies); }); }); @@ -326,9 +326,9 @@ describe('autoInject', () => { const dependencies = ['ENV', 'mysql']; const newInitializer = autoInject(baseProvider); - assert.notEqual(newInitializer, baseProvider); - assert.notEqual(newInitializer[SPECIAL_PROPS.INJECT], dependencies); - assert.deepEqual(newInitializer[SPECIAL_PROPS.INJECT], dependencies); + expect(newInitializer).not.toEqual(baseProvider); + expect(newInitializer[SPECIAL_PROPS.INJECT]).not.toBe(dependencies); + expect(newInitializer[SPECIAL_PROPS.INJECT]).toEqual(dependencies); }); test('should allow to decorate an initializer with a function name', () => { @@ -341,9 +341,9 @@ describe('autoInject', () => { const dependencies = ['ENV', 'mysql']; const newInitializer = autoInject(baseProvider); - assert.notEqual(newInitializer, baseProvider); - assert.notEqual(newInitializer[SPECIAL_PROPS.INJECT], dependencies); - assert.deepEqual(newInitializer[SPECIAL_PROPS.INJECT], dependencies); + expect(newInitializer).not.toEqual(baseProvider); + expect(newInitializer[SPECIAL_PROPS.INJECT]).not.toBe(dependencies); + expect(newInitializer[SPECIAL_PROPS.INJECT]).toEqual(dependencies); }); test('should allow to decorate an initializer with optional dependencies', () => { @@ -358,9 +358,9 @@ describe('autoInject', () => { const dependencies = ['ENV', '?log', '?debug']; const newInitializer = autoInject(baseProvider); - assert.notEqual(newInitializer, baseProvider); - assert.notEqual(newInitializer[SPECIAL_PROPS.INJECT], dependencies); - assert.deepEqual(newInitializer[SPECIAL_PROPS.INJECT], dependencies); + expect(newInitializer).not.toEqual(baseProvider); + expect(newInitializer[SPECIAL_PROPS.INJECT]).not.toBe(dependencies); + expect(newInitializer[SPECIAL_PROPS.INJECT]).toEqual(dependencies); }); test('should allow to decorate an initializer with several arguments', () => { @@ -375,9 +375,9 @@ describe('autoInject', () => { const dependencies = ['ENV', '?log', '?debug']; const newInitializer = autoInject(baseProvider); - assert.notEqual(newInitializer, baseProvider); - assert.notEqual(newInitializer[SPECIAL_PROPS.INJECT], dependencies); - assert.deepEqual(newInitializer[SPECIAL_PROPS.INJECT], dependencies); + expect(newInitializer).not.toEqual(baseProvider); + expect(newInitializer[SPECIAL_PROPS.INJECT]).not.toBe(dependencies); + expect(newInitializer[SPECIAL_PROPS.INJECT]).toEqual(dependencies); }); test('should allow to decorate an initializer with complex arguments', () => { @@ -392,31 +392,40 @@ describe('autoInject', () => { const dependencies = ['ENV', '?log', '?debug']; const newInitializer = autoInject(baseProvider); - assert.notEqual(newInitializer, baseProvider); - assert.notEqual(newInitializer[SPECIAL_PROPS.INJECT], dependencies); - assert.deepEqual(newInitializer[SPECIAL_PROPS.INJECT], dependencies); + expect(newInitializer).not.toEqual(baseProvider); + expect(newInitializer[SPECIAL_PROPS.INJECT]).not.toBe(dependencies); + expect(newInitializer[SPECIAL_PROPS.INJECT]).toEqual(dependencies); }); test('should fail with non async initializers', () => { - assert.throws(() => { + try { autoInject((({ foo: bar = { bar: 'foo' } }) => { return bar; }) as any); - }, /E_NON_ASYNC_INITIALIZER/); + throw new YError('E_UNEXPECTED_SUCCESS'); + } catch (err) { + expect((err as YError).code).toEqual('E_NON_ASYNC_INITIALIZER'); + } }); test('should fail with too complex injections', () => { - assert.throws(() => { + try { autoInject(async ({ foo: bar = { bar: 'foo' } }) => { return bar; }); - }, /E_AUTO_INJECTION_FAILURE/); + throw new YError('E_UNEXPECTED_SUCCESS'); + } catch (err) { + expect((err as YError).code).toEqual('E_AUTO_INJECTION_FAILURE'); + } }); test('should fail with no injections', () => { - assert.throws(() => { + try { autoInject(async () => undefined); - }, /E_AUTO_INJECTION_FAILURE/); + throw new YError('E_UNEXPECTED_SUCCESS'); + } catch (err) { + expect((err as YError).code).toEqual('E_AUTO_INJECTION_FAILURE'); + } }); }); @@ -427,15 +436,15 @@ describe('alsoInject', () => { inject(['TEST'], aProviderInitializer), ); - assert.notEqual(newInitializer, aProviderInitializer); - assert.deepEqual(newInitializer[SPECIAL_PROPS.INJECT], ['TEST', 'ENV']); + expect(newInitializer).not.toEqual(aProviderInitializer); + expect(newInitializer[SPECIAL_PROPS.INJECT]).toEqual(['TEST', 'ENV']); }); test('should allow to decorate an initializer with dependencies', () => { const newInitializer = alsoInject(['ENV'], aProviderInitializer); - assert.notEqual(newInitializer, aProviderInitializer); - assert.deepEqual(newInitializer[SPECIAL_PROPS.INJECT], ['ENV']); + expect(newInitializer).not.toEqual(aProviderInitializer); + expect(newInitializer[SPECIAL_PROPS.INJECT]).toEqual(['ENV']); }); test('should dedupe dependencies', () => { @@ -445,8 +454,8 @@ describe('alsoInject', () => { alsoInject(['ENV', 'NODE_ENV', '?TEST', '?TEST2', 'mysql'], baseProvider), ); - assert.notEqual(newInitializer, baseProvider); - assert.deepEqual(newInitializer[SPECIAL_PROPS.INJECT], [ + expect(newInitializer).not.toEqual(baseProvider); + expect(newInitializer[SPECIAL_PROPS.INJECT]).toEqual([ 'mysql', 'ENV', 'NODE_ENV', @@ -463,8 +472,8 @@ describe('alsoInject', () => { alsoInject(['ENV', '?TEST3'], baseProvider), ); - assert.notEqual(newInitializer, baseProvider); - assert.deepEqual(newInitializer[SPECIAL_PROPS.INJECT], [ + expect(newInitializer).not.toEqual(baseProvider); + expect(newInitializer[SPECIAL_PROPS.INJECT]).toEqual([ '?TEST', '?TEST3', 'ENV', @@ -476,8 +485,8 @@ describe('alsoInject', () => { const baseProvider = inject(['mysql', '?sftp'], aProviderInitializer); const newInitializer = alsoInject(['db>mysql', '?ftp>sftp'], baseProvider); - assert.notEqual(newInitializer, baseProvider); - assert.deepEqual(newInitializer[SPECIAL_PROPS.INJECT], [ + expect(newInitializer).not.toEqual(baseProvider); + expect(newInitializer[SPECIAL_PROPS.INJECT]).toEqual([ 'mysql', '?sftp', 'db>mysql', @@ -495,8 +504,8 @@ describe('alsoInject', () => { ), ); - assert.notEqual(newInitializer, aProviderInitializer); - assert.deepEqual(newInitializer[SPECIAL_PROPS.INJECT], [ + expect(newInitializer).not.toEqual(aProviderInitializer); + expect(newInitializer[SPECIAL_PROPS.INJECT]).toEqual([ 'ENV', 'NODE_ENV', '?TEST', @@ -515,8 +524,8 @@ describe('alsoInject', () => { ), ); - assert.notEqual(newInitializer, aProviderInitializer); - assert.deepEqual(newInitializer[SPECIAL_PROPS.INJECT], [ + expect(newInitializer).not.toEqual(aProviderInitializer); + expect(newInitializer[SPECIAL_PROPS.INJECT]).toEqual([ 'ENV', 'NODE_ENV', '?TEST', @@ -528,7 +537,7 @@ describe('alsoInject', () => { describe('parseInjections', () => { test('should work with TypeScript dependencies', () => { - assert.deepEqual( + expect( parseInjections(`async function initNexmo({ ENV, NEXMO, @@ -538,15 +547,14 @@ describe('parseInjections', () => { NEXMO: any; log: Function; }): Promise {}`), - ['ENV', 'NEXMO', '?log'], - ); + ).toEqual(['ENV', 'NEXMO', '?log']); }); test('should allow to decorate an initializer with dependencies', () => { const newInitializer = alsoInject(['ENV'], aProviderInitializer); - assert.notEqual(newInitializer, aProviderInitializer); - assert.deepEqual(newInitializer[SPECIAL_PROPS.INJECT], ['ENV']); + expect(newInitializer).not.toEqual(aProviderInitializer); + expect(newInitializer[SPECIAL_PROPS.INJECT]).toEqual(['ENV']); }); }); @@ -558,10 +566,10 @@ describe('singleton', () => { singleton(aProviderInitializer, true), ); - assert.notEqual(newInitializer, aProviderInitializer); - assert.notEqual(newInitializer[SPECIAL_PROPS.INJECT], dependencies); - assert.deepEqual(newInitializer[SPECIAL_PROPS.INJECT], dependencies); - assert.equal(newInitializer[SPECIAL_PROPS.SINGLETON], true); + expect(newInitializer).not.toEqual(aProviderInitializer); + expect(newInitializer[SPECIAL_PROPS.INJECT]).not.toBe(dependencies); + expect(newInitializer[SPECIAL_PROPS.INJECT]).toEqual(dependencies); + expect(newInitializer[SPECIAL_PROPS.SINGLETON]).toEqual(true); }); test('should allow to be used several times', () => { @@ -571,10 +579,10 @@ describe('singleton', () => { singleton(singleton(aProviderInitializer), false), ); - assert.notEqual(newInitializer, aProviderInitializer); - assert.notEqual(newInitializer[SPECIAL_PROPS.INJECT], dependencies); - assert.deepEqual(newInitializer[SPECIAL_PROPS.INJECT], dependencies); - assert.equal(newInitializer[SPECIAL_PROPS.SINGLETON], false); + expect(newInitializer).not.toEqual(aProviderInitializer); + expect(newInitializer[SPECIAL_PROPS.INJECT]).not.toBe(dependencies); + expect(newInitializer[SPECIAL_PROPS.INJECT]).toEqual(dependencies); + expect(newInitializer[SPECIAL_PROPS.SINGLETON]).toEqual(false); }); }); @@ -587,10 +595,10 @@ describe('name', () => { name(baseName, aProviderInitializer), ); - assert.notEqual(newInitializer, aProviderInitializer); - assert.notEqual(newInitializer[SPECIAL_PROPS.INJECT], dependencies); - assert.deepEqual(newInitializer[SPECIAL_PROPS.INJECT], dependencies); - assert.equal(newInitializer[SPECIAL_PROPS.NAME], baseName); + expect(newInitializer).not.toEqual(aProviderInitializer); + expect(newInitializer[SPECIAL_PROPS.INJECT]).not.toBe(dependencies); + expect(newInitializer[SPECIAL_PROPS.INJECT]).toEqual(dependencies); + expect(newInitializer[SPECIAL_PROPS.NAME]).toEqual(baseName); }); }); @@ -605,10 +613,10 @@ describe('autoName', () => { }), ); - assert.notEqual(newInitializer, aProviderInitializer); - assert.notEqual(newInitializer[SPECIAL_PROPS.INJECT], dependencies); - assert.deepEqual(newInitializer[SPECIAL_PROPS.INJECT], dependencies); - assert.equal(newInitializer[SPECIAL_PROPS.NAME], baseName); + expect(newInitializer).not.toEqual(aProviderInitializer); + expect(newInitializer[SPECIAL_PROPS.INJECT]).not.toBe(dependencies); + expect(newInitializer[SPECIAL_PROPS.INJECT]).toEqual(dependencies); + expect(newInitializer[SPECIAL_PROPS.NAME]).toEqual(baseName); }); test('should allow to decorate an initializer with its init like function name', () => { @@ -621,10 +629,10 @@ describe('autoName', () => { }), ); - assert.notEqual(newInitializer, aProviderInitializer); - assert.notEqual(newInitializer[SPECIAL_PROPS.INJECT], dependencies); - assert.deepEqual(newInitializer[SPECIAL_PROPS.INJECT], dependencies); - assert.equal(newInitializer[SPECIAL_PROPS.NAME], baseName); + expect(newInitializer).not.toEqual(aProviderInitializer); + expect(newInitializer[SPECIAL_PROPS.INJECT]).not.toBe(dependencies); + expect(newInitializer[SPECIAL_PROPS.INJECT]).toEqual(dependencies); + expect(newInitializer[SPECIAL_PROPS.NAME]).toEqual(baseName); }); test('should allow to decorate an initializer with its initialize like function name', () => { @@ -637,10 +645,10 @@ describe('autoName', () => { }), ); - assert.notEqual(newInitializer, aProviderInitializer); - assert.notEqual(newInitializer[SPECIAL_PROPS.INJECT], dependencies); - assert.deepEqual(newInitializer[SPECIAL_PROPS.INJECT], dependencies); - assert.equal(newInitializer[SPECIAL_PROPS.NAME], baseName); + expect(newInitializer).not.toEqual(aProviderInitializer); + expect(newInitializer[SPECIAL_PROPS.INJECT]).not.toBe(dependencies); + expect(newInitializer[SPECIAL_PROPS.INJECT]).toEqual(dependencies); + expect(newInitializer[SPECIAL_PROPS.NAME]).toEqual(baseName); }); test('should allow to decorate a bounded initializer', () => { @@ -655,17 +663,20 @@ describe('autoName', () => { ), ); - assert.notEqual(newInitializer, aProviderInitializer); - assert.notEqual(newInitializer[SPECIAL_PROPS.INJECT], dependencies); - assert.deepEqual(newInitializer[SPECIAL_PROPS.INJECT], dependencies); - assert.equal(newInitializer[SPECIAL_PROPS.SINGLETON], true); - assert.equal(newInitializer[SPECIAL_PROPS.NAME], baseName); + expect(newInitializer).not.toEqual(aProviderInitializer); + expect(newInitializer[SPECIAL_PROPS.INJECT]).not.toBe(dependencies); + expect(newInitializer[SPECIAL_PROPS.INJECT]).toEqual(dependencies); + expect(newInitializer[SPECIAL_PROPS.SINGLETON]).toEqual(true); + expect(newInitializer[SPECIAL_PROPS.NAME]).toEqual(baseName); }); test('should fail with anonymous functions', () => { - assert.throws(() => { + try { autoName(async () => undefined); - }, /E_AUTO_NAMING_FAILURE/); + throw new YError('E_UNEXPECTED_SUCCESS'); + } catch (err) { + expect((err as YError).code).toEqual('E_AUTO_NAMING_FAILURE'); + } }); }); @@ -674,18 +685,18 @@ describe('extra', () => { const extraInformations = { httpHandler: true }; const newInitializer = extra(extraInformations, aProviderInitializer); - assert.notEqual(newInitializer, aProviderInitializer); - assert.notEqual(newInitializer[SPECIAL_PROPS.EXTRA], extraInformations); - assert.deepEqual(newInitializer[SPECIAL_PROPS.EXTRA], extraInformations); + expect(newInitializer).not.toEqual(aProviderInitializer); + expect(newInitializer[SPECIAL_PROPS.EXTRA]).not.toBe(extraInformations); + expect(newInitializer[SPECIAL_PROPS.EXTRA]).toEqual(extraInformations); }); test('should allow to decorate an initializer with extra infos', () => { const extraInformations = { httpHandler: true }; const newInitializer = extra(extraInformations, aProviderInitializer, true); - assert.notEqual(newInitializer, aProviderInitializer); - assert.notEqual(newInitializer[SPECIAL_PROPS.EXTRA], extraInformations); - assert.deepEqual(newInitializer[SPECIAL_PROPS.EXTRA], extraInformations); + expect(newInitializer).not.toEqual(aProviderInitializer); + expect(newInitializer[SPECIAL_PROPS.EXTRA]).not.toBe(extraInformations); + expect(newInitializer[SPECIAL_PROPS.EXTRA]).toEqual(extraInformations); }); test('should allow to decorate an initializer with additional extra infos', () => { @@ -697,11 +708,15 @@ describe('extra', () => { true, ); - assert.notEqual(newInitializer, aProviderInitializer); - assert.notEqual(newInitializer[SPECIAL_PROPS.EXTRA], baseExtraInformations); - assert.notEqual(newInitializer[SPECIAL_PROPS.EXTRA], baseExtraInformations); - assert.deepEqual(newInitializer[SPECIAL_PROPS.EXTRA], { - ...baseExtraInformations, + expect(newInitializer).not.toEqual(aProviderInitializer); + expect(newInitializer[SPECIAL_PROPS.EXTRA]).not.toBe( + baseExtraInformations, + ); + expect(newInitializer[SPECIAL_PROPS.EXTRA]).not.toEqual( + additionalExtraInformations, + ); + expect(newInitializer[SPECIAL_PROPS.EXTRA]).toEqual({ + ...additionalExtraInformations, ...baseExtraInformations, }); }); @@ -717,11 +732,11 @@ describe('type', () => { name(baseName, type(baseType, aProviderInitializer)), ); - assert.notEqual(newInitializer, aProviderInitializer); - assert.notEqual(newInitializer[SPECIAL_PROPS.INJECT], dependencies); - assert.deepEqual(newInitializer[SPECIAL_PROPS.INJECT], dependencies); - assert.equal(newInitializer[SPECIAL_PROPS.NAME], baseName); - assert.equal(newInitializer[SPECIAL_PROPS.TYPE], baseType); + expect(newInitializer).not.toEqual(aProviderInitializer); + expect(newInitializer[SPECIAL_PROPS.INJECT]).not.toBe(dependencies); + expect(newInitializer[SPECIAL_PROPS.INJECT]).toEqual(dependencies); + expect(newInitializer[SPECIAL_PROPS.NAME]).toEqual(baseName); + expect(newInitializer[SPECIAL_PROPS.TYPE]).toEqual(baseType); }); }); @@ -740,16 +755,16 @@ describe('initializer', () => { aServiceInitializer, ); - assert.notEqual(newInitializer, aProviderInitializer); - assert.notEqual(newInitializer[SPECIAL_PROPS.INJECT], dependencies); - assert.deepEqual(newInitializer[SPECIAL_PROPS.INJECT], dependencies); - assert.equal(newInitializer[SPECIAL_PROPS.SINGLETON], true); - assert.equal(newInitializer[SPECIAL_PROPS.NAME], baseName); - assert.equal(newInitializer[SPECIAL_PROPS.TYPE], baseType); + expect(newInitializer).not.toEqual(aProviderInitializer); + expect(newInitializer[SPECIAL_PROPS.INJECT]).not.toBe(dependencies); + expect(newInitializer[SPECIAL_PROPS.INJECT]).toEqual(dependencies); + expect(newInitializer[SPECIAL_PROPS.SINGLETON]).toEqual(true); + expect(newInitializer[SPECIAL_PROPS.NAME]).toEqual(baseName); + expect(newInitializer[SPECIAL_PROPS.TYPE]).toEqual(baseType); }); test('should fail with bad properties', () => { - assert.throws(() => { + try { initializer( { name: 'yolo', @@ -757,7 +772,10 @@ describe('initializer', () => { } as any, async () => undefined, ); - }, /E_BAD_PROPERTY/); + throw new YError('E_UNEXPECTED_SUCCESS'); + } catch (err) { + expect((err as YError).code).toEqual('E_BAD_PROPERTY'); + } }); }); @@ -767,18 +785,21 @@ describe('constant', () => { const baseValue = 42; const constantInitializer = constant(baseName, baseValue); - assert.equal(constantInitializer[SPECIAL_PROPS.NAME], baseName); - assert.equal(constantInitializer[SPECIAL_PROPS.TYPE], 'constant'); - assert.equal(constantInitializer[SPECIAL_PROPS.VALUE], baseValue); + expect(constantInitializer[SPECIAL_PROPS.NAME]).toEqual(baseName); + expect(constantInitializer[SPECIAL_PROPS.TYPE]).toEqual('constant'); + expect(constantInitializer[SPECIAL_PROPS.VALUE]).toEqual(baseValue); }); test('should fail with dependencies since it makes no sense', () => { - assert.throws(() => { + try { constant( 'time', inject(['hash3'], async () => undefined), ); - }, /E_CONSTANT_INJECTION/); + throw new YError('E_UNEXPECTED_SUCCESS'); + } catch (err) { + expect((err as YError).code).toEqual('E_CONSTANT_INJECTION'); + } }); }); @@ -797,13 +818,13 @@ describe('service', () => { extraData, ); - assert.notEqual(newInitializer, aProviderInitializer); - assert.notEqual(newInitializer[SPECIAL_PROPS.INJECT], dependencies); - assert.deepEqual(newInitializer[SPECIAL_PROPS.INJECT], dependencies); - assert.equal(newInitializer[SPECIAL_PROPS.SINGLETON], true); - assert.deepEqual(newInitializer[SPECIAL_PROPS.EXTRA], extraData); - assert.equal(newInitializer[SPECIAL_PROPS.NAME], baseName); - assert.equal(newInitializer[SPECIAL_PROPS.TYPE], baseType); + expect(newInitializer).not.toEqual(aProviderInitializer); + expect(newInitializer[SPECIAL_PROPS.INJECT]).not.toBe(dependencies); + expect(newInitializer[SPECIAL_PROPS.INJECT]).toEqual(dependencies); + expect(newInitializer[SPECIAL_PROPS.SINGLETON]).toEqual(true); + expect(newInitializer[SPECIAL_PROPS.EXTRA]).toEqual(extraData); + expect(newInitializer[SPECIAL_PROPS.NAME]).toEqual(baseName); + expect(newInitializer[SPECIAL_PROPS.TYPE]).toEqual(baseType); }); test('should allow to create an initializer from a generic service builder', async () => { @@ -820,19 +841,22 @@ describe('service', () => { extraData, ); - assert.notEqual(newInitializer, aProviderInitializer); - assert.notEqual(newInitializer[SPECIAL_PROPS.INJECT], dependencies); - assert.deepEqual(newInitializer[SPECIAL_PROPS.INJECT], dependencies); - assert.equal(newInitializer[SPECIAL_PROPS.SINGLETON], true); - assert.deepEqual(newInitializer[SPECIAL_PROPS.EXTRA], extraData); - assert.equal(newInitializer[SPECIAL_PROPS.NAME], baseName); - assert.equal(newInitializer[SPECIAL_PROPS.TYPE], baseType); + expect(newInitializer).not.toEqual(aProviderInitializer); + expect(newInitializer[SPECIAL_PROPS.INJECT]).not.toBe(dependencies); + expect(newInitializer[SPECIAL_PROPS.INJECT]).toEqual(dependencies); + expect(newInitializer[SPECIAL_PROPS.SINGLETON]).toEqual(true); + expect(newInitializer[SPECIAL_PROPS.EXTRA]).toEqual(extraData); + expect(newInitializer[SPECIAL_PROPS.NAME]).toEqual(baseName); + expect(newInitializer[SPECIAL_PROPS.TYPE]).toEqual(baseType); }); test('should fail with no service builder', () => { - assert.throws(() => { + try { service(undefined as any); - }, /E_NO_SERVICE_BUILDER/); + throw new YError('E_UNEXPECTED_SUCCESS'); + } catch (err) { + expect((err as YError).code).toEqual('E_NO_SERVICE_BUILDER'); + } }); }); @@ -843,10 +867,10 @@ describe('autoService', () => { }; const newInitializer = autoService(baseServiceBuilder); - assert.notEqual(newInitializer, baseServiceBuilder); - assert.deepEqual(newInitializer[SPECIAL_PROPS.INJECT], ['ENV']); - assert.equal(newInitializer[SPECIAL_PROPS.NAME], 'mySQL'); - assert.equal(newInitializer[SPECIAL_PROPS.TYPE], 'service'); + expect(newInitializer).not.toEqual(baseServiceBuilder); + expect(newInitializer[SPECIAL_PROPS.INJECT]).toEqual(['ENV']); + expect(newInitializer[SPECIAL_PROPS.NAME]).toEqual('mySQL'); + expect(newInitializer[SPECIAL_PROPS.TYPE]).toEqual('service'); }); test('should detect the service details even with no dependencies', () => { @@ -855,10 +879,10 @@ describe('autoService', () => { }; const newInitializer = autoService(baseServiceBuilder); - assert.notEqual(newInitializer, baseServiceBuilder); - assert.deepEqual(newInitializer[SPECIAL_PROPS.INJECT], []); - assert.equal(newInitializer[SPECIAL_PROPS.NAME], 'mySQL'); - assert.equal(newInitializer[SPECIAL_PROPS.TYPE], 'service'); + expect(newInitializer).not.toEqual(baseServiceBuilder); + expect(newInitializer[SPECIAL_PROPS.INJECT]).toEqual([]); + expect(newInitializer[SPECIAL_PROPS.NAME]).toEqual('mySQL'); + expect(newInitializer[SPECIAL_PROPS.TYPE]).toEqual('service'); }); }); @@ -877,13 +901,13 @@ describe('provider', () => { extraData, ); - assert.notEqual(newInitializer, aProviderInitializer); - assert.notEqual(newInitializer[SPECIAL_PROPS.INJECT], dependencies); - assert.deepEqual(newInitializer[SPECIAL_PROPS.INJECT], dependencies); - assert.equal(newInitializer[SPECIAL_PROPS.SINGLETON], true); - assert.deepEqual(newInitializer[SPECIAL_PROPS.EXTRA], extraData); - assert.equal(newInitializer[SPECIAL_PROPS.NAME], baseName); - assert.equal(newInitializer[SPECIAL_PROPS.TYPE], baseType); + expect(newInitializer).not.toEqual(aProviderInitializer); + expect(newInitializer[SPECIAL_PROPS.INJECT]).not.toBe(dependencies); + expect(newInitializer[SPECIAL_PROPS.INJECT]).toEqual(dependencies); + expect(newInitializer[SPECIAL_PROPS.SINGLETON]).toEqual(true); + expect(newInitializer[SPECIAL_PROPS.EXTRA]).toEqual(extraData); + expect(newInitializer[SPECIAL_PROPS.NAME]).toEqual(baseName); + expect(newInitializer[SPECIAL_PROPS.TYPE]).toEqual(baseType); }); test('should allow to create an initializer from a provider builder', async () => { @@ -901,19 +925,22 @@ describe('provider', () => { ), ); - assert.notEqual(newInitializer, aProviderInitializer); - assert.notEqual(newInitializer[SPECIAL_PROPS.INJECT], dependencies); - assert.deepEqual(newInitializer[SPECIAL_PROPS.INJECT], dependencies); - assert.equal(newInitializer[SPECIAL_PROPS.SINGLETON], true); - assert.deepEqual(newInitializer[SPECIAL_PROPS.EXTRA], extraData); - assert.equal(newInitializer[SPECIAL_PROPS.NAME], baseName); - assert.equal(newInitializer[SPECIAL_PROPS.TYPE], baseType); + expect(newInitializer).not.toEqual(aProviderInitializer); + expect(newInitializer[SPECIAL_PROPS.INJECT]).not.toBe(dependencies); + expect(newInitializer[SPECIAL_PROPS.INJECT]).toEqual(dependencies); + expect(newInitializer[SPECIAL_PROPS.SINGLETON]).toEqual(true); + expect(newInitializer[SPECIAL_PROPS.EXTRA]).toEqual(extraData); + expect(newInitializer[SPECIAL_PROPS.NAME]).toEqual(baseName); + expect(newInitializer[SPECIAL_PROPS.TYPE]).toEqual(baseType); }); test('should fail with no provider builder', () => { - assert.throws(() => { + try { provider(undefined as any); - }, /E_NO_PROVIDER_BUILDER/); + throw new YError('E_UNEXPECTED_SUCCESS'); + } catch (err) { + expect((err as YError).code).toEqual('E_NO_PROVIDER_BUILDER'); + } }); }); @@ -928,10 +955,10 @@ describe('autoProvider', () => { }; const newInitializer = autoProvider(baseInitializer); - assert.notEqual(newInitializer, baseInitializer); - assert.deepEqual(newInitializer[SPECIAL_PROPS.INJECT], ['ENV']); - assert.equal(newInitializer[SPECIAL_PROPS.NAME], 'mySQL'); - assert.equal(newInitializer[SPECIAL_PROPS.TYPE], 'provider'); + expect(newInitializer).not.toEqual(baseInitializer); + expect(newInitializer[SPECIAL_PROPS.INJECT]).toEqual(['ENV']); + expect(newInitializer[SPECIAL_PROPS.NAME]).toEqual('mySQL'); + expect(newInitializer[SPECIAL_PROPS.TYPE]).toEqual('provider'); }); test('should detect the provider details even with no dependencies', () => { @@ -940,10 +967,10 @@ describe('autoProvider', () => { }; const newInitializer = autoProvider(baseInitializer); - assert.notEqual(newInitializer, baseInitializer); - assert.deepEqual(newInitializer[SPECIAL_PROPS.INJECT], []); - assert.equal(newInitializer[SPECIAL_PROPS.NAME], 'mySQL'); - assert.equal(newInitializer[SPECIAL_PROPS.TYPE], 'provider'); + expect(newInitializer).not.toEqual(baseInitializer); + expect(newInitializer[SPECIAL_PROPS.INJECT]).toEqual([]); + expect(newInitializer[SPECIAL_PROPS.NAME]).toEqual('mySQL'); + expect(newInitializer[SPECIAL_PROPS.TYPE]).toEqual('provider'); }); }); @@ -957,12 +984,12 @@ describe('handler', () => { }; const theInitializer = handler(sampleHandler, baseName, injectedServices); - assert.deepEqual((theInitializer as any).$name, baseName); - assert.deepEqual((theInitializer as any).$inject, injectedServices); + expect((theInitializer as any).$name).toEqual(baseName); + expect((theInitializer as any).$inject).toEqual(injectedServices); const theHandler = await theInitializer(services); const result = await theHandler('test'); - assert.deepEqual(result, { + expect(result).toEqual({ deps: services, args: ['test'], }); @@ -973,9 +1000,12 @@ describe('handler', () => { }); test('should fail with no name', () => { - assert.throws(() => { + try { handler(async () => undefined); - }, /E_NO_HANDLER_NAME/); + throw new YError('E_UNEXPECTED_SUCCESS'); + } catch (err) { + expect((err as YError).code).toEqual('E_NO_HANDLER_NAME'); + } }); }); @@ -987,12 +1017,13 @@ describe('autoHandler', () => { }; const theInitializer = autoHandler(sampleHandler); - assert.deepEqual((theInitializer as any).$name, sampleHandler.name); - assert.deepEqual((theInitializer as any).$inject, ['kikooo', 'lol']); + expect((theInitializer as any).$name).toEqual(sampleHandler.name); + expect((theInitializer as any).$inject).toEqual(['kikooo', 'lol']); const theHandler = await theInitializer(services); const result = await theHandler('test'); - assert.deepEqual(result, { + + expect(result).toEqual({ deps: services, args: ['test'], }); @@ -1009,12 +1040,13 @@ describe('autoHandler', () => { }; const theInitializer = autoHandler(sampleHandler); - assert.deepEqual((theInitializer as any).$name, sampleHandler.name); - assert.deepEqual((theInitializer as any).$inject, ['kikooo', 'lol']); + expect((theInitializer as any).$name).toEqual(sampleHandler.name); + expect((theInitializer as any).$inject).toEqual(['kikooo', 'lol']); const theHandler = await theInitializer(services); const result = await theHandler('test'); - assert.deepEqual(result, { + + expect(result).toEqual({ deps: services, args: ['test'], }); @@ -1025,15 +1057,18 @@ describe('autoHandler', () => { }); test('should fail for anonymous functions', () => { - assert.throws(() => { + try { autoHandler(async () => undefined); - }, /E_AUTO_NAMING_FAILURE/); + throw new YError('E_UNEXPECTED_SUCCESS'); + } catch (err) { + expect((err as YError).code).toEqual('E_AUTO_NAMING_FAILURE'); + } }); }); describe('parseDependencyDeclaration', () => { test('should work', () => { - assert.deepEqual(parseDependencyDeclaration('db>pgsql'), { + expect(parseDependencyDeclaration('db>pgsql')).toEqual({ serviceName: 'db', mappedName: 'pgsql', optional: false, @@ -1041,7 +1076,7 @@ describe('parseDependencyDeclaration', () => { }); test('should work with unmapped names', () => { - assert.deepEqual(parseDependencyDeclaration('?pgsql'), { + expect(parseDependencyDeclaration('?pgsql')).toEqual({ serviceName: 'pgsql', mappedName: 'pgsql', optional: true, diff --git a/src/util.ts b/src/util.ts index b09cbb4..58a336a 100644 --- a/src/util.ts +++ b/src/util.ts @@ -19,11 +19,11 @@ export const AUTOLOAD = '$autoload'; referred to as another initializer dependency. - type: an initializer can be of three types at the moment (constant, service or provider). The initializer annotations - varies accordsing to those types as we'll see later on. + varies according to those types as we'll see later on. - injected dependencies: an array of dependencies declarations that - declares which initializer htis initializer depends on. Constants + declares which initializer this initializer depends on. Constants logically cannot have dependencies. -- options: various options like for exemple, if the initializer +- options: various options like for example, if the initializer implements the singleton pattern or not. - value: only used for constant, this property allows to know the value the initializer resolves to without actually executing it. @@ -55,7 +55,7 @@ export type Provider = { export type Dependencies = { [name: string]: S }; export type DependencyName = string; export type DependencyDeclaration = string; -export type ExtraInformations = any; +export type ExtraInformation = any; export type ParsedDependencyDeclaration = { serviceName: string; mappedName: string; @@ -82,7 +82,7 @@ export type ProviderProperties = { $name: DependencyName; $inject?: DependencyDeclaration[]; $singleton?: boolean; - $extra?: ExtraInformations; + $extra?: ExtraInformation; }; export type ProviderInitializer = | ((dependencies: D) => Promise>) @@ -92,7 +92,7 @@ export type ProviderInputProperties = { name: DependencyName; inject?: DependencyDeclaration[]; singleton?: boolean; - extra?: ExtraInformations; + extra?: ExtraInformation; }; export type ServiceInitializerBuilder< @@ -104,7 +104,7 @@ export type ServiceProperties = { $name: DependencyName; $inject?: DependencyDeclaration[]; $singleton?: boolean; - $extra?: ExtraInformations; + $extra?: ExtraInformation; }; export type ServiceInitializer = | ((dependencies: D) => Promise) @@ -114,7 +114,7 @@ export type ServiceInputProperties = { name: DependencyName; inject?: DependencyDeclaration[]; singleton?: boolean; - extra?: ExtraInformations; + extra?: ExtraInformation; }; export type InitializerProperties = @@ -348,7 +348,7 @@ export function constant( * @param {Boolean} [singleton] * Whether the service is a singleton or not * @param {any} [extra] - * Eventual extra informations + * Eventual extra information * @return {Function} * Returns a new initializer * @example @@ -372,7 +372,7 @@ export function service, S>( name?: DependencyName, dependencies?: DependencyDeclaration[], singleton?: boolean, - extra?: ExtraInformations, + extra?: ExtraInformation, ): ServiceInitializer { if (!serviceBuilder) { throw new YError('E_NO_SERVICE_BUILDER'); @@ -430,7 +430,7 @@ export function autoService, S>( * @param {Boolean} [singleton] * Whether the service is a singleton or not * @param {any} [extra] - * Eventual extra informations + * Eventual extra information * @return {Function} * Returns a new provider initializer * @example @@ -471,7 +471,7 @@ export function provider, S>( name?: DependencyName, dependencies?: DependencyDeclaration[], singleton?: boolean, - extra?: ExtraInformations, + extra?: ExtraInformation, ): ProviderInitializer { if (!providerBuilder) { throw new YError('E_NO_PROVIDER_BUILDER'); @@ -946,12 +946,12 @@ export function alsoInject< /** * Decorator creating a new initializer with some - * extra informations appended to it. It is just + * extra information appended to it. It is just * a way for user to store some additional - * informations but has no interaction with the + * information but has no interaction with the * Knifecycle internals. - * @param {Object} extraInformations - * An object containing those extra informations. + * @param {Object} extraInformation + * An object containing those extra information. * @param {Function} initializer * The initializer to tweak * @param {Boolean} [merge=false] @@ -972,25 +972,25 @@ export function alsoInject< */ export function extra, S>( - extraInformations: ExtraInformations, + extraInformation: ExtraInformation, initializer: ProviderInitializer, merge?: boolean, ): ProviderInitializer; export function extra, S>( - extraInformations: ExtraInformations, + extraInformation: ExtraInformation, initializer: ProviderInitializerBuilder, merge?: boolean, ): ProviderInitializerBuilder; export function extra, S>( - extraInformations: ExtraInformations, + extraInformation: ExtraInformation, initializer: ServiceInitializer, ): ServiceInitializer; export function extra, S>( - extraInformations: ExtraInformations, + extraInformation: ExtraInformation, initializer: ServiceInitializerBuilder, ): ServiceInitializerBuilder; export function extra, S>( - extraInformations: ExtraInformations, + extraInformation: ExtraInformation, initializer: | ProviderInitializerBuilder | ServiceInitializerBuilder, @@ -1003,13 +1003,13 @@ export function extra, S>( [SPECIAL_PROPS.EXTRA]: merge ? Object.assign( initializer[SPECIAL_PROPS.EXTRA] || {}, - extraInformations, + extraInformation, ) - : extraInformations, + : extraInformation, }, ); - debug('Wrapped an initializer with extra informations:', extraInformations); + debug('Wrapped an initializer with extra information:', extraInformation); return uniqueInitializer; } @@ -1305,7 +1305,7 @@ export function handler< name?: ServiceName, dependencies?: DependencyDeclaration[], singleton?: boolean, - extra?: ExtraInformations, + extra?: ExtraInformation, ): ServiceInitializer Promise> { name = name || handlerFunction[SPECIAL_PROPS.NAME]; dependencies = dependencies || handlerFunction[SPECIAL_PROPS.INJECT] || [];