Skip to content

Commit

Permalink
style(tests): format with Prettier
Browse files Browse the repository at this point in the history
Preemptive Prettier scan to avoid CI.
  • Loading branch information
freshgum-bubbles committed Nov 29, 2023
1 parent 7328b2e commit 68ca53f
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 34 deletions.
22 changes: 11 additions & 11 deletions test/contrib/es/es-service.spec.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
import { Container } from "internal:typedi";
import { createFakeClassDecoratorContext } from "./utils/fake-context.util";
import { ESService } from "internal:typedi/contrib/es/es-service.decorator.mjs";
import { Container } from 'internal:typedi';
import { createFakeClassDecoratorContext } from './utils/fake-context.util';
import { ESService } from 'internal:typedi/contrib/es/es-service.decorator.mjs';

// Due to the testing structure, we can't actually use ES Decorators
// here. Instead, we have to pretend we're using them, by manually
// passing descriptors and functions to them.
// P.S. The actual conformance testing goes on in <test/decorators/Service.spec.ts>
// This suite just tests parts of required ESService-specific testing.
describe('ESService', () => {
beforeEach(() => Container.reset({ strategy: 'resetValue' }));
beforeEach(() => Container.reset({ strategy: 'resetValue' }));

// Note: in <test/contrib/es/utils/es-service-decorator-wrapper.util.ts>, we already test
// if the implementation accepts valid invocations with valid ClassDecoratorContext objects.
it('should fail if not passed a ClassDecoratorContext', () => {
class MyService { }
// Note: in <test/contrib/es/utils/es-service-decorator-wrapper.util.ts>, we already test
// if the implementation accepts valid invocations with valid ClassDecoratorContext objects.
it('should fail if not passed a ClassDecoratorContext', () => {
class MyService {}

const context = createFakeClassDecoratorContext(MyService);
expect(() => ESService([ ])(class { }, context)).not.toThrow();
});
const context = createFakeClassDecoratorContext(MyService);
expect(() => ESService([])(class {}, context)).not.toThrow();
});
});
18 changes: 8 additions & 10 deletions test/contrib/es/test-utils/es-service-decorator-wrapper.util.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

import { ServiceOptions, AnyServiceDependency, Service, Constructable } from 'internal:typedi';
import { ESService } from 'internal:typedi/contrib/es/es-service.decorator.mjs';
import { createFakeClassDecoratorContext } from './fake-context.util';
Expand All @@ -10,16 +9,15 @@ function WrappedESServiceDecoratorImpl<T = unknown>(
optionsOrDependencies: Omit<ServiceOptions<T>, 'dependencies'> | ServiceOptions<T> | AnyServiceDependency[],
maybeDependencies?: AnyServiceDependency[]
): ClassDecorator {
return (targetConstructor) => {
const fakeContext: ClassDecoratorContext = createFakeClassDecoratorContext(targetConstructor);
return targetConstructor => {
const fakeContext: ClassDecoratorContext = createFakeClassDecoratorContext(targetConstructor);

// Note: These aren't guaranteed, just used to trick TypeScript into being quiet.
ESService<T>(
optionsOrDependencies as Omit<ServiceOptions<T>, 'dependencies'>,
maybeDependencies as AnyServiceDependency[]
)(targetConstructor as unknown as Constructable<T>, fakeContext);
}
// Note: These aren't guaranteed, just used to trick TypeScript into being quiet.
ESService<T>(
optionsOrDependencies as Omit<ServiceOptions<T>, 'dependencies'>,
maybeDependencies as AnyServiceDependency[]
)(targetConstructor as unknown as Constructable<T>, fakeContext);
};
}

export const WrappedESServiceDecorator = WrappedESServiceDecoratorImpl as typeof Service;

26 changes: 14 additions & 12 deletions test/contrib/es/test-utils/fake-context.util.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
export function createFakeClassDecoratorContext<TFunction extends Function>(targetConstructor: TFunction): ClassDecoratorContext<abstract new (...args: any) => any> {
return {
addInitializer(initializer) {
// We can't implement this, and it isn't used by ESService.
throw new Error('Not implemented.');
},
kind: 'class',
// TODO: Not sure what goes here, and it isn't used by ESService.
metadata: {},
name: targetConstructor.name
};
}
export function createFakeClassDecoratorContext<TFunction extends Function>(
targetConstructor: TFunction
): ClassDecoratorContext<abstract new (...args: any) => any> {
return {
addInitializer(initializer) {
// We can't implement this, and it isn't used by ESService.
throw new Error('Not implemented.');
},
kind: 'class',
// TODO: Not sure what goes here, and it isn't used by ESService.
metadata: {},
name: targetConstructor.name,
};
}
2 changes: 1 addition & 1 deletion test/decorators/Service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ interface DecoratorTestScenario {

const DECORATORS_TO_TEST: DecoratorTestScenario[] = [
{ decorator: Service, description: 'main, non-ES', name: 'Service' },
{ decorator: WrappedESServiceDecorator, description: 'contrib/es/ESService', name: 'ESService' }
{ decorator: WrappedESServiceDecorator, description: 'contrib/es/ESService', name: 'ESService' },
];

describe.each(DECORATORS_TO_TEST)('$name decorator ($description)', ({ decorator: Decorator }) => {
Expand Down

0 comments on commit 68ca53f

Please sign in to comment.