Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: await uncaught promises in tests #582

Merged
merged 1 commit into from
Dec 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions packages/execution/test/ExecutionManager.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ describe('ExecutionManager', () =>
{
const promise = executionManager.addSegment({} as Segment);

expect(promise).rejects.toEqual(new InvalidSegment());
await expect(promise).rejects.toEqual(new InvalidSegment());
});
});

Expand All @@ -35,16 +35,16 @@ describe('ExecutionManager', () =>

const response = await executionManager.run(request);

expect(response.result).toBe('public');
await expect(response.result).toBe('public');
});

it('should not run a non-existing procedure', () =>
it('should not run a non-existing procedure', async () =>
{
const request = new Request('nonExisting', Version.DEFAULT, new Map(), new Map(), RunModes.NORMAL);

const promise = executionManager.run(request);

expect(promise).rejects.toEqual(new ProcedureNotFound('nonExisting'));
await expect(promise).rejects.toEqual(new ProcedureNotFound('nonExisting'));
});

it('should not run a non-existing implementation', async () =>
Expand All @@ -53,7 +53,7 @@ describe('ExecutionManager', () =>

const promise = executionManager.run(request);

expect(promise).rejects.toEqual(new ImplementationNotFound('versioned', Version.DEFAULT.toString()));
await expect(promise).rejects.toEqual(new ImplementationNotFound('versioned', Version.DEFAULT.toString()));
});

it('should perform a dry-run', async () =>
Expand All @@ -62,7 +62,7 @@ describe('ExecutionManager', () =>

const response = await executionManager.run(request);

expect(response.result).toBeUndefined();
await expect(response.result).toBeUndefined();
});
});
});
4 changes: 2 additions & 2 deletions packages/serialization/test/Serializer.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ describe('Serializer', () =>
{
const serialize = async () => typeSerializer.serialize(true);

expect(serialize).rejects.toStrictEqual(new NoSerializerFound('boolean'));
await expect(serialize).rejects.toStrictEqual(new NoSerializerFound('boolean'));
});
});

Expand All @@ -59,7 +59,7 @@ describe('Serializer', () =>
{
const deserialize = async () => typeSerializer.deserialize(true);

expect(deserialize).rejects.toStrictEqual(new NoDeserializerFound('boolean'));
await expect(deserialize).rejects.toStrictEqual(new NoDeserializerFound('boolean'));
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,14 @@ describe('serializers/BigIntSerializer', () =>
{
const resultValidBigInt = await serializer.deserialize(BIG_INTEGERS.VALID_SERIALIZED);

expect(resultValidBigInt).toStrictEqual(BIG_INTEGERS.VALID);
await expect(resultValidBigInt).toStrictEqual(BIG_INTEGERS.VALID);
});

it('should not deserialize a big int with an invalid big int string', async () =>
{
const deserialize = async () => serializer.deserialize(BIG_INTEGERS.INVALID_BIGINT_STRING);

expect(deserialize).rejects.toStrictEqual(new InvalidBigIntString('1.3'));
await expect(deserialize).rejects.toStrictEqual(new InvalidBigIntString('1.3'));
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -98,14 +98,14 @@ describe('serializers/ClassSerializer', () =>
{
const deserialize = async () => serializer.deserialize(CLASSES.INVALID_SERIALIZED);

expect(deserialize).rejects.toStrictEqual(new ClassNotFound('Invalid'));
await expect(deserialize).rejects.toStrictEqual(new ClassNotFound('Invalid'));
});

it('should not deserialize non-function instances', async () =>
{
const deserialize = async () => serializer.deserialize(CLASSES.UNSERIALIZABLE);

expect(deserialize).rejects.toStrictEqual(new InvalidClass('Infinity'));
await expect(deserialize).rejects.toStrictEqual(new InvalidClass('Infinity'));
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ describe('serializers/DateSerializer', () =>
{
const deserialize = async () => serializer.deserialize(DATES.INVALID_DATE_STRING);

expect(deserialize).rejects.toStrictEqual(new InvalidDateString('hello'));
await expect(deserialize).rejects.toStrictEqual(new InvalidDateString('hello'));
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,14 @@ describe('serializers/RegExpSerializer', () =>
{
const deserialize = async () => serializer.deserialize(REGULAR_EXPRESSIONS.INVALID_SOURCE_SERIALIZED);

expect(deserialize).rejects.toStrictEqual(new InvalidRegExp('sel/\\', 'g'));
await expect(deserialize).rejects.toStrictEqual(new InvalidRegExp('sel/\\', 'g'));
});

it('should not deserialize a regular expression with invalid flag', async () =>
{
const deserialize = async () => serializer.deserialize(REGULAR_EXPRESSIONS.INVALID_FLAG_SERIALIZED);

expect(deserialize).rejects.toStrictEqual(new InvalidRegExp('w+', true));
await expect(deserialize).rejects.toStrictEqual(new InvalidRegExp('\\w+', true));
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ describe('serializers/UrlSerializer', () =>
{
const deserialize = async () => serializer.deserialize(URLS.INVALID_URL_STRING);

expect(deserialize).rejects.toStrictEqual(new InvalidUrlString('example'));
await expect(deserialize).rejects.toStrictEqual(new InvalidUrlString('example'));
});
});
});
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@

const validRegExp = new RegExp('w+', 'gi');
const validRegExp = /\w+/gi;

const serializedValidRegExp = { serialized: true, name: 'RegExp', source: 'w+', flags: 'gi' };
const serializedValidRegExp = { serialized: true, name: 'RegExp', source: '\\w+', flags: 'gi' };

const nonObject = 42;
const nonRegExp = new Map();
const notSerialized = { name: 'RegExp', source: 'w+', flags: 'gi' };
const invalidName = { serialized: true, name: 'Map', source: 'w+', flags: 'gi' };
const notSerialized = { name: 'RegExp', source: '\\w+', flags: 'gi' };
const invalidName = { serialized: true, name: 'Map', source: '\\w+', flags: 'gi' };
const invalidRegExpSource = { serialized: true, name: 'RegExp', source: true, flags: 'g' };
const invalidRegExpFlag = { serialized: true, name: 'RegExp', source: 'w+', flags: true };
const invalidRegExpFlag = { serialized: true, name: 'RegExp', source: '\\w+', flags: true };
const serializedInvalidRegExpSource = { serialized: true, name: 'RegExp', source: 'sel/\\', flags: 'g' };
const serializedInvalidRegExpFlag = { serialized: true, name: 'RegExp', source: 'w+', flags: 'true' };
const serializedInvalidRegExpFlag = { serialized: true, name: 'RegExp', source: '\\w+', flags: 'true' };

export const REGULAR_EXPRESSIONS =
{
Expand Down
2 changes: 1 addition & 1 deletion packages/services/src/gateway/errors/UnknownWorker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { ServerError } from '@jitar/errors';

export default class UnknownWorker extends ServerError
{
#id: string;
readonly #id: string;

constructor(id: string)
{
Expand Down
16 changes: 8 additions & 8 deletions packages/services/test/gateway/LocalGateway.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,32 +16,32 @@ describe('gateway/LocalGateway', () =>
{
describe('.addWorker(worker, trustKey?)', () =>
{
it('should add a worker without a trust key to a public gateway', () =>
it('should add a worker without a trust key to a public gateway', async () =>
{
const promise = publicGateway.addWorker(emptyWorker);

expect(promise).resolves.toBeDefined();
await expect(promise).resolves.toBeDefined();
});

it('should add a worker with a valid trust key to a protected gateway', () =>
it('should add a worker with a valid trust key to a protected gateway', async () =>
{
const promise = protectedGateway.addWorker(trustedWorker);

expect(promise).resolves.toBeDefined();
await expect(promise).resolves.toBeDefined();
});

it('should not add a worker with an invalid trust key to a protected gateway', () =>
it('should not add a worker with an invalid trust key to a protected gateway', async () =>
{
const promise = protectedGateway.addWorker(untrustedWorker);

expect(promise).rejects.toEqual(new InvalidTrustKey());
await expect(promise).rejects.toEqual(new InvalidTrustKey());
});

it('should not add a worker with a missing trust key to a protected gateway', () =>
it('should not add a worker with a missing trust key to a protected gateway', async () =>
{
const promise = protectedGateway.addWorker(emptyWorker);

expect(promise).rejects.toEqual(new InvalidTrustKey());
await expect(promise).rejects.toEqual(new InvalidTrustKey());
});
});
});
2 changes: 1 addition & 1 deletion packages/services/test/gateway/WorkerBalancer.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ describe('services/WorkerBalancer', () =>
const request = new Request('nonExisting', Version.DEFAULT, new Map(), new Map(), RunModes.NORMAL);
const promise = emptyBalancer.run(request);

expect(promise).rejects.toEqual(new NoWorkerAvailable('nonExisting'));
await expect(promise).rejects.toEqual(new NoWorkerAvailable('nonExisting'));
});
});
});
8 changes: 4 additions & 4 deletions packages/services/test/gateway/WorkerManager.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,22 +77,22 @@ describe('gateway/WorkerManager', () =>

describe('.run(request)', () =>
{
it('should run an existing procedure', () =>
it('should run an existing procedure', async () =>
{
const request = new Request('first', Version.DEFAULT, new Map(), new Map(), RunModes.NORMAL);

const promise = filledManager.run(request);

expect(promise).resolves.toEqual(new Response(StatusCodes.OK, 'test'));
await expect(promise).resolves.toEqual(new Response(StatusCodes.OK, 'test'));
});

it('should not run a non-existing procedure', () =>
it('should not run a non-existing procedure', async () =>
{
const request = new Request('nonExisting', Version.DEFAULT, new Map(), new Map(), RunModes.NORMAL);

const promise = filledManager.run(request);

expect(promise).rejects.toEqual(new ProcedureNotFound('nonExisting'));
await expect(promise).rejects.toEqual(new ProcedureNotFound('nonExisting'));
});
});
});
12 changes: 6 additions & 6 deletions packages/services/test/repository/LocalRepository.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,25 @@ describe('repository/LocalRepository', () =>
{
describe('.provide(filename)', () =>
{
it('should provide a existing file', () =>
it('should provide a existing file', async () =>
{
const promise = fileRepository.provide(FILENAMES.PNG);

expect(promise).resolves.toEqual(FILES.PNG);
await expect(promise).resolves.toEqual(FILES.PNG);
});

it('should not provide a non-existing file', () =>
it('should not provide a non-existing file', async () =>
{
const promise = fileRepository.provide(FILENAMES.TXT);

expect(promise).rejects.toEqual(new FileNotFound(FILENAMES.TXT));
await expect(promise).rejects.toEqual(new FileNotFound(FILENAMES.TXT));
});

it('should provide index file when file not found', () =>
it('should provide index file when file not found', async () =>
{
const promise = webRepository.provide(FILENAMES.TXT);

expect(promise).resolves.toEqual(FILES.HTML);
await expect(promise).resolves.toEqual(FILES.HTML);
});
});
});
6 changes: 3 additions & 3 deletions packages/services/test/worker/LocalWorker.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ describe('worker/LocalWorker', () =>

const promise = protectedWorker.run(request);

expect(promise).rejects.toEqual(new ProcedureNotFound('nonExisting'));
await expect(promise).rejects.toEqual(new ProcedureNotFound('nonExisting'));
});

it('should not run a protected procedure with invalid trust key', async () =>
Expand All @@ -50,7 +50,7 @@ describe('worker/LocalWorker', () =>

const promise = protectedWorker.run(request);

expect(promise).rejects.toEqual(new RequestNotTrusted());
await expect(promise).rejects.toEqual(new RequestNotTrusted());
});

it('should not run a protected procedure without trust key', async () =>
Expand All @@ -59,7 +59,7 @@ describe('worker/LocalWorker', () =>

const promise = protectedWorker.run(request);

expect(promise).rejects.toEqual(new RequestNotTrusted());
await expect(promise).rejects.toEqual(new RequestNotTrusted());
});

// TODO: Add tests for remote execution
Expand Down
Loading