Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
shlomiassaf committed May 5, 2024
1 parent 8101605 commit 73d6181
Show file tree
Hide file tree
Showing 29 changed files with 189 additions and 93 deletions.
2 changes: 1 addition & 1 deletion apps/nx-api-extractor-e2e/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module.exports = {
displayName: 'nx-api-extractor-e2e',
preset: '../../jest.preset.js',
transform: {
'^.+\\.[tj]sx?$': ['ts-jest', { tsConfig: '<rootDir>/tsconfig.spec.json' }]
'^.+\\.[tj]sx?$': [ 'ts-jest', { tsconfig: '<rootDir>/tsconfig.spec.json' } ]
},
moduleFileExtensions: ['ts', 'js', 'html'],
coverageDirectory: '../../coverage/apps/nx-api-extractor-e2e',
Expand Down
2 changes: 1 addition & 1 deletion apps/nx-build-pipe-e2e/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module.exports = {
displayName: 'nx-build-pipe-e2e',
preset: '../../jest.preset.js',
transform: {
'^.+\\.[tj]sx?$': ['ts-jest', { tsConfig: '<rootDir>/tsconfig.spec.json' }]
'^.+\\.[tj]sx?$': ['ts-jest', { tsconfig: '<rootDir>/tsconfig.spec.json' }]
},
moduleFileExtensions: ['ts', 'js', 'html'],
coverageDirectory: '../../coverage/apps/nx-build-pipe-e2e',
Expand Down
2 changes: 1 addition & 1 deletion libs/decorate/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module.exports = {
setupFiles: ['./jest-setup.ts'],
testEnvironment: 'node',
transform: {
'^.+\\.[tj]sx?$': ['ts-jest', { tsConfig: '<rootDir>/tsconfig.spec.json' }]
'^.+\\.[tj]sx?$': ['ts-jest', { tsconfig: '<rootDir>/tsconfig.spec.json' }]
},
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx'],
coverageDirectory: '../../coverage/libs/decorate',
Expand Down
2 changes: 1 addition & 1 deletion libs/goosetyped/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module.exports = {
displayName: 'goosetyped',
setupFiles: ['./jest-setup.ts'],
transform: {
'^.+\\.[tj]sx?$': ['ts-jest', { tsConfig: '<rootDir>/tsconfig.spec.json' }]
'^.+\\.[tj]sx?$': ['ts-jest', { tsconfig: '<rootDir>/tsconfig.spec.json' }]
},
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx'],
coverageDirectory: '../../coverage/libs/goosetyped',
Expand Down
2 changes: 1 addition & 1 deletion libs/goosetyped/jest.config.livedb.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module.exports = {
preset: '../../jest.preset.js',
setupFiles: ['./jest-setup.ts'],
transform: {
'^.+\\.[tj]sx?$': ['ts-jest', { tsConfig: '<rootDir>/tsconfig.spec.json' }]
'^.+\\.[tj]sx?$': ['ts-jest', { tsconfig: '<rootDir>/tsconfig.spec.json' }]
},
testEnvironment: 'node',
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ describe('goosetyped', () => {

it('should throw if there is no mongo type match', () => {
expect(() => getMongoType({ tsType: String }, undefined))
.toThrowError('Invalid type definition, could not find a valid type which maps to a Schema or SchemaType');
.toThrow('Invalid type definition, could not find a valid type which maps to a Schema or SchemaType');
expect(() => getMongoType({ tsType: String }, { tsType: String }))
.toThrowError('Invalid type definition, could not find a valid type which maps to a Schema or SchemaType');
.toThrow('Invalid type definition, could not find a valid type which maps to a Schema or SchemaType');
});

it('should resolve the main mongo type from a single-item reflected and user resolved types', () => {
Expand Down Expand Up @@ -59,7 +59,7 @@ describe('goosetyped', () => {
},
};
expect(() => getMongoType(containerResolvedType, { tsType: String, type: undefined }))
.toThrowError('Invalid type configuration, container type requires an explicity type definition');
.toThrow('Invalid type configuration, container type requires an explicity type definition');
});

it('should set the default option on the final schema', () => {
Expand Down
9 changes: 5 additions & 4 deletions libs/nesbus/jest.config.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
module.exports = {
displayName: 'nesbus',
maxWorkers: '1',
setupFiles: ['./jest-setup.ts'],
preset: '../../jest.preset.js',
transform: {
'^.+\\.[tj]sx?$': ['ts-jest', { tsConfig: '<rootDir>/tsconfig.spec.json' }]
'^.+\\.[tj]sx?$': ['ts-jest', { tsconfig: '<rootDir>/tsconfig.spec.json' }]
},
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx'],
testPathIgnorePatterns : [
Expand All @@ -15,9 +16,9 @@ module.exports = {
'<rootDir>/tests/__env',
],
coverageDirectory: '../../coverage/libs/nesbus',
testEnvironment: '<rootDir>/tests/__env/utils/service-bus-env-setup/jest-service-bus-test-environment',
testEnvironment: '<rootDir>/tests/__env/utils/service-bus-env-setup/init-runtime',
testEnvironmentOptions: {
envSetup: false,
envTeardown: false,
envSetup: true,
envTeardown: true,
},
};
24 changes: 12 additions & 12 deletions libs/nesbus/src/lib/atom-adapter/management-client-atom-adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,51 +25,51 @@ export class SbManagementClientAtomAdapter implements SbManagementClientAdapter
}

async getQueue(queueName: string) {
return this.managementClient.getQueueDetails(queueName);
return await this.managementClient.getQueueDetails(queueName);
}
async upsertQueue(queueName: string, queue: SbQueue, isNew: boolean) {
return isNew
? this.managementClient.createQueue(queueName, queue)
: this.managementClient.updateQueue(queueName, queue)
? await this.managementClient.createQueue(queueName, queue)
: await this.managementClient.updateQueue(queueName, queue)
;
}
async deleteQueue(queueName: string) {
await this.managementClient.deleteQueue(queueName);
}

async getTopic(topicName: string) {
return this.managementClient.getTopicDetails(topicName);
return await this.managementClient.getTopicDetails(topicName);
}
async upsertTopic(topicName: string, topic: SbTopic, isNew: boolean) {
return isNew
? this.managementClient.createTopic(topicName, topic)
: this.managementClient.updateTopic(topicName, topic)
? await this.managementClient.createTopic(topicName, topic)
: await this.managementClient.updateTopic(topicName, topic)
;
}
async deleteTopic(topicName: string) {
await this.managementClient.deleteTopic(topicName);
}

async getSubscription(topicName: string, subscriptionName: string) {
return this.managementClient.getSubscriptionDetails(topicName, subscriptionName);
return await this.managementClient.getSubscriptionDetails(topicName, subscriptionName);
}
async upsertSubscription(topicName: string, subscriptionName: string, subscription: SbSubscription, isNew: boolean) {
return isNew
? this.managementClient.createSubscription(topicName, subscriptionName, subscription)
: this.managementClient.updateSubscription(topicName, subscriptionName, subscription)
? await this.managementClient.createSubscription(topicName, subscriptionName, subscription)
: await this.managementClient.updateSubscription(topicName, subscriptionName, subscription)
;
}
async deleteSubscription(topicName: string, subscriptionName: string) {
await this.managementClient.deleteSubscription(topicName, subscriptionName);
}

async getRule(topicName: string, subscriptionName: string, ruleName: string) {
return this.managementClient.getRuleDetails(topicName, subscriptionName, ruleName);
return await this.managementClient.getRuleDetails(topicName, subscriptionName, ruleName);
}
async upsertRule(topicName: string, subscriptionName: string, ruleName: string, rule: SbRule, isNew: boolean) {
return isNew
? this.managementClient.createRule(topicName, subscriptionName, ruleName, rule)
: this.managementClient.updateRule(topicName, subscriptionName, ruleName, rule)
? await this.managementClient.createRule(topicName, subscriptionName, ruleName, rule)
: await this.managementClient.updateRule(topicName, subscriptionName, ruleName, rule)
;
}
async deleteRule(topicName: string, subscriptionName: string, ruleName: string) {
Expand Down
2 changes: 1 addition & 1 deletion libs/nesbus/src/lib/management/configurator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ export class SbConfigurator {
}
async deleteSubscription(topicName: string, subscriptionName: string) {
await this.managementClient.deleteSubscription(topicName, subscriptionName);
this.sbLogger.log(`Subscription ${topicName}-${subscriptionName} de;ete.`);
this.sbLogger.log(`Subscription ${topicName}-${subscriptionName} delete.`);
}

async verifyRule(topicName: string, subscriptionName: string, provision: SbRuleEntityProvision): Promise<SbRule> {
Expand Down
1 change: 0 additions & 1 deletion libs/nesbus/tests/__env/utils/module.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { isFunction } from 'util';
import { Test, TestingModule } from '@nestjs/testing';
import { createSbServer, SbModuleRegisterOptions } from '@pebula/nesbus';

Expand Down
10 changes: 7 additions & 3 deletions libs/nesbus/tests/__env/utils/service-bus-env-setup/env-setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export async function run() {

const entities = [...Object.values(EMITTERS), ...Object.values(SUBSCRIBERS)] as Array<SbSubscriberMetadataOptions | SbEmitterMetadataOptions>;
const phase1: Array<Promise<any>> = [];
const phase2: Array<Promise<any>> = [];
const phase2: Array<() => Promise<any>> = [];
for (const c of entities) {
if (c.testEnvSetup && c.testEnvSetup.setup) {
switch (c.testEnvSetup.entity) {
Expand All @@ -31,16 +31,20 @@ export async function run() {
phase1.push(configurator.verifyTopic(c.name, 'verifyCreate'));
break;
case 'subscription':
phase2.push(configurator.verifySubscription((c as SbSubscriptionMetadataOptions).topicName, c.name, 'verifyCreate'));
phase2.push(() => configurator.verifySubscription((c as SbSubscriptionMetadataOptions).topicName, c.name, 'verifyCreate'));
break;
}
}
}

if (phase1.length) {
serverOptions.logger.log('Verifying Topics & Queues');
await Promise.all(phase1);
}

if (phase2.length) {
await Promise.all(phase2);
serverOptions.logger.log('Verifying Subscriptions');
await Promise.all(phase2.map(f => f()));
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const path = require('path');
const tsNode = require('ts-node');
const tsTransformPaths = require('typescript-transform-paths');

tsNode.register({
project: path.join(__dirname, 'tsconfig.json')
});

tsTransformPaths.register();

module.exports = require('./jest-service-bus-test-environment').JestServiceBusTestEnvironment;

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { JestEnvironmentConfig, EnvironmentContext } from '@jest/environment';
import JestEnvironmentNode from 'jest-environment-node';

export class JestServiceBusTestEnvironment extends JestEnvironmentNode {
private sbEnvConfig: { envSetup?: boolean; envTeardown?: boolean; };

constructor(config: JestEnvironmentConfig, context: EnvironmentContext) {
super(config, context);
this.sbEnvConfig = config.projectConfig?.testEnvironmentOptions ?? {} as any;
}

async setup() {
await super.setup();
if (this.sbEnvConfig.envSetup) {
await require('./env-setup').run();
}
}

async teardown() {
await super.teardown();
if (this.sbEnvConfig.envTeardown) {
await require('./env-teardown').run();
}
}
}
20 changes: 20 additions & 0 deletions libs/nesbus/tests/__env/utils/service-bus-env-setup/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"extends": "../../../../../../tsconfig.base.json",
"compilerOptions": {
"module": "commonjs",
"outDir": "../../../../../../dist/out-tsc",
"declaration": true,
"types": ["node"],
"plugins": [
{ "transform": "typescript-transform-paths" },
{ "transform": "typescript-transform-paths", "afterDeclarations": true }
]
},
"ts-node": {
"transpileOnly": true,
"logError": true,
"ignoreDiagnostics": [7006, 2683]
},
"exclude": ["**/*.spec.ts", "tests/**/*.*", "benchmarks/**/*.*"],
"include": ["**/*.ts"]
}
3 changes: 2 additions & 1 deletion libs/nesbus/tests/tests/app.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,9 @@ describe('@pebula/nesbus', () => {
let errorHandler: TestErrorHandler;
let msgStore: MessageStorage;

jest.setTimeout(10000 * 30);

beforeAll(async () => {
jest.setTimeout(10000 * 30);

app = await TestModuleFactory.create()
.addServiceBusModule([{ provide: SbErrorHandler, useClass: TestErrorHandler }])
Expand Down
4 changes: 2 additions & 2 deletions libs/nesbus/tests/tests/errors.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ describe('@pebula/nesbus', () => {

it('should throw invalidOrMissingConfiguration', () => {
const createClient = () => SbResourceManager.get().createClient({ name: 'UNIT_TEST' });
expect(createClient).toThrowError(E.invalidOrMissingConfiguration(
expect(createClient).toThrow(E.invalidOrMissingConfiguration(
'SbClientOptions.client',
'Connection credentials are missing and no matching server found for the identity',
));
Expand All @@ -37,7 +37,7 @@ describe('@pebula/nesbus', () => {
it('throw resourceAlreadyExists', () => {
const createClient = () => SbResourceManager.get().createClient(createSbClientOptions('UNIT_TEST'));
createClient();
expect(createClient).toThrowError(E.resourceAlreadyExists('client', 'UNIT_TEST'));
expect(createClient).toThrow(E.resourceAlreadyExists('client', 'UNIT_TEST'));
});

it('invalid handler type', async () => {
Expand Down
3 changes: 2 additions & 1 deletion libs/nesbus/tests/tests/management/configurator.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ describe('@pebula/nesbus', () => {
return tmp;
}

jest.setTimeout(10000 * 30);

beforeAll(() => {
jest.setTimeout(10000 * 30);

const config = new ConfigService();

Expand Down
2 changes: 1 addition & 1 deletion libs/nx-api-extractor/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module.exports = {
displayName: 'nx-api-extractor',
preset: '../../jest.preset.js',
transform: {
'^.+\\.[tj]sx?$': ['ts-jest', { tsConfig: '<rootDir>/tsconfig.spec.json' }]
'^.+\\.[tj]sx?$': ['ts-jest', { tsconfig: '<rootDir>/tsconfig.spec.json' }]
},
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx'],
coverageDirectory: '../../coverage/libs/nx-api-extractor',
Expand Down
2 changes: 1 addition & 1 deletion libs/nx-build-pipe/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module.exports = {
displayName: 'nx-build-pipe',
preset: '../../jest.preset.js',
transform: {
'^.+\\.[tj]sx?$': ['ts-jest', { tsConfig: '<rootDir>/tsconfig.spec.json' }]
'^.+\\.[tj]sx?$': ['ts-jest', { tsconfig: '<rootDir>/tsconfig.spec.json' }]
},
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx'],
coverageDirectory: '../../coverage/libs/nx-build-pipe',
Expand Down
2 changes: 1 addition & 1 deletion libs/tom/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module.exports = {
displayName: 'tom',
preset: '../../jest.preset.js',
transform: {
'^.+\\.[tj]sx?$': ['ts-jest', { tsConfig: '<rootDir>/tsconfig.spec.json' }]
'^.+\\.[tj]sx?$': ['ts-jest', { tsconfig: '<rootDir>/tsconfig.spec.json' }]
},
testEnvironment: 'node',
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx'],
Expand Down
6 changes: 3 additions & 3 deletions libs/tom/mapping/define-class-mapping.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ describe('map-schema', () => {

it('should not warn if mapping is not sealed and expectImmediateSeal is not set', (cb) => {
expect.assertions(2);
spyOn(console, 'warn');
jest.spyOn(console, 'warn');

class C1 {}
class C2 {}
Expand All @@ -57,8 +57,8 @@ describe('map-schema', () => {
}, 10);
});

it('should warn if mapping is not sealed and expectImmediateSeal is set', async (cb) => {
spyOn(console, 'warn');
it('should warn if mapping is not sealed and expectImmediateSeal is set', (cb) => {
jest.spyOn(console, 'warn');

class C1 {}
class C2 {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ describe('map-schema', () => {

it('should not warn if mapping is not sealed and expectImmediateSeal is not set', (cb) => {
expect.assertions(2);
spyOn(console, 'warn');
jest.spyOn(console, 'warn');

new ClassMappingSchemaFactory(C1, C2);
expect(mapRegistry.has(C1, C2)).toBe(false);
Expand All @@ -76,8 +76,8 @@ describe('map-schema', () => {
}, 10);
});

it('should warn if mapping is not sealed and expectImmediateSeal is not set', async (cb) => {
spyOn(console, 'warn');
it('should warn if mapping is not sealed and expectImmediateSeal is not set', (cb) => {
jest.spyOn(console, 'warn');

new ClassMappingSchemaFactory(C1, C2, { expectImmediateSeal: true });
expect(mapRegistry.has(C1, C2)).toBe(false);
Expand Down

0 comments on commit 73d6181

Please sign in to comment.