chore: jest test environment set to "node"
MODIFY
jest.config.js
jest.config.js
@@ -4,6 +4,7 @@ const config = {
transform: {
'^.+\\.tsx?$': 'ts-jest'
},
+ testEnvironment: 'node',
testRegex: 'spec\.ts$',
coverageDirectory: './coverage/',
coveragePathIgnorePatterns: [

MODIFY
packages/@integration/src/messaging/client.ts
packages/@integration/src/messaging/client.ts
@@ -19,6 +19,9 @@ const client = messagingClient({
host: 'amqp://localhost:5672',
queue: 'test_queue',
queueOptions: { durable: false },
+ timeout: isTestEnv()
+ ? 500
+ : 30 * 1000,
},
});

MODIFY
packages/@integration/src/messaging/server.ts
packages/@integration/src/messaging/server.ts
@@ -9,9 +9,8 @@ import { IO } from 'fp-ts/lib/IO';
const fib = (n: number): number =>
(n === 0 || n === 1) ? n : fib(n - 1) + fib(n - 2);
-const fibonacci$: MsgEffect = event$ => {
-
- return event$.pipe(
+const fibonacci$: MsgEffect = event$ =>
+ event$.pipe(
matchEvent('FIB'),
use(eventValidator$(t.number)),
mergeMap(event => of(event).pipe(
@@ -21,36 +20,28 @@ const fibonacci$: MsgEffect = event$ => {
catchError(error => of(reply(event)({ type: 'FIB_ERROR', error: { name: error.name, message: error.message } }))),
)),
);
-};
-
-const buffer$: MsgEffect = event$ => {
- return event$.pipe(
+const buffer$: MsgEffect = event$ =>
+ event$.pipe(
matchEvent('BUFFER'),
bufferCount(2),
mapTo({ type: 'BUFFER_RESULT' }),
);
-};
-
-const timeout$: MsgEffect = event$ => {
- return event$.pipe(
+const timeout$: MsgEffect = event$ =>
+ event$.pipe(
matchEvent('TIMEOUT'),
mergeMap(event => of(event).pipe(
delay(180 * 1000),
mapTo(reply(event)({ type: 'TIMEOUT_RESULT' })),
)),
);
-};
-const error$: MsgEffect = event$ => {
-
- return event$.pipe(
+const error$: MsgEffect = event$ =>
+ event$.pipe(
matchEvent('ERROR'),
tap(() => { throw new Error('test_error'); }),
);
-};
-
export const microservice = createMicroservice({
transport: Transport.AMQP,
@@ -58,6 +49,9 @@ export const microservice = createMicroservice({
host: 'amqp://localhost:5672',
queue: 'test_queue',
queueOptions: { durable: false },
+ timeout: isTestEnv()
+ ? 500
+ : 30 * 1000
},
listener: messagingListener({
effects: [fibonacci$, buffer$, timeout$, error$],

MODIFY
packages/messaging/src/server/specs/messaging.server.amqp.spec.ts
packages/messaging/src/server/specs/messaging.server.amqp.spec.ts
@@ -12,6 +12,7 @@ const createOptions = (config: { expectAck?: boolean; queue?: string } = {}): Am
queue: config.queue || 'test_queue_server',
expectAck: config.expectAck,
queueOptions: { durable: false },
+ timeout: 500,
});
describe('messagingServer::AMQP', () => {
@@ -40,6 +41,7 @@ describe('messagingServer::AMQP', () => {
expect(parsedResult1).toEqual({ type: 'RPC_TEST_RESULT', payload: 11 });
await microservice.close();
+ await client.close();
});
test('handles published event', async done => {
@@ -47,7 +49,11 @@ describe('messagingServer::AMQP', () => {
eventSubject.subscribe(event => {
expect(event).toEqual({ type: 'EVENT_TEST_RESPONSE', payload: 2 });
- setTimeout(() => microservice.close().then(done), 1000);
+ setTimeout(async () => {
+ await microservice.close();
+ await client.close();
+ done();
+ }, 1000);
});
const event$: MsgEffect = event$ =>
@@ -72,7 +78,11 @@ describe('messagingServer::AMQP', () => {
eventSubject.subscribe(event => {
expect(event).toEqual({ type: 'EVENT_TEST_RESPONSE', payload: 2 });
- setTimeout(() => microservice.close().then(done), 1000);
+ setTimeout(async () => {
+ await microservice.close();
+ await client.close();
+ done();
+ }, 1000);
});
const event$: MsgEffect = (event$, { client }) =>
@@ -107,7 +117,11 @@ describe('messagingServer::AMQP', () => {
expect(data[0][1]).toEqual(error);
expect(data[1][0]).toEqual(event2);
expect(data[1][1]).toBeUndefined();
- setTimeout(() => microservice.close().then(done), 1000);
+ setTimeout(async () => {
+ await microservice.close();
+ await client.close();
+ done();
+ }, 1000);
});
const event1$: MsgEffect = event$ =>

MODIFY
packages/middleware-io/test/io-ws.integration.spec.ts
packages/middleware-io/test/io-ws.integration.spec.ts
@@ -17,14 +17,14 @@ describe('@marblejs/middleware-io - WebSocket integration', () => {
// when
const app = await createWebSocketServer({ options: { server }, listener });
- await app();
+ const webSocketServer = await app();
targetClient.once('open', () => targetClient.send(event));
// then
targetClient.once('message', message => {
expect(message).toEqual(event);
- done();
+ webSocketServer.close(done);
});
});
@@ -45,7 +45,7 @@ describe('@marblejs/middleware-io - WebSocket integration', () => {
// when
const app = await createWebSocketServer({ options: { server }, listener });
- await app();
+ const webSocketServer = await app();
targetClient.once('open', () => targetClient.send(event));
@@ -53,7 +53,7 @@ describe('@marblejs/middleware-io - WebSocket integration', () => {
targetClient.once('message', message => {
const parsedMessage = JSON.parse(message);
expect(parsedMessage).toEqual(expectedError);
- done();
+ webSocketServer.close(done);
});
});
});

MODIFY
packages/middleware-logger/src/logger.handler.ts
packages/middleware-logger/src/logger.handler.ts
@@ -24,6 +24,6 @@ export const loggerHandler = (opts: LoggerOptions, logger: Logger) => (stamp: Ti
const log = logger({ tag: LoggerTag.HTTP, type: 'RequestLogger', message, level });
return log();
- })
+ }),
);
}

MODIFY
packages/middleware-logger/src/spec/logger.middleware.spec.ts
packages/middleware-logger/src/spec/logger.middleware.spec.ts
@@ -9,7 +9,7 @@ describe('logger$', () => {
beforeEach(() => {
const client = jest.fn() as any as HttpServer;
- logger = jest.fn() as any as Logger;
+ logger = jest.fn(() => jest.fn());
const boundLogger = bindTo(LoggerToken)(() => logger);
const context = register(boundLogger)(createContext());

MODIFY
packages/websockets/src/server/specs/websocket.server.spec.ts
packages/websockets/src/server/specs/websocket.server.spec.ts
@@ -25,14 +25,14 @@ describe('WebSocket server', () => {
// when
const app = await createWebSocketServer({ options: { server }, listener });
- await app();
+ const webSocketServer = await app();
targetClient.once('open', () => targetClient.send(event));
// then
targetClient.once('message', message => {
expect(message).toEqual(event);
- done();
+ webSocketServer.close(done);
});
});
@@ -48,7 +48,7 @@ describe('WebSocket server', () => {
// when
const app = await createWebSocketServer({ options: { server }, listener });
- await app();
+ const webSocketServer = await app();
targetClient.on('open', () => targetClient.send(JSON.stringify(event)));
@@ -59,7 +59,7 @@ describe('WebSocket server', () => {
forkJoin(client1$, client2$).subscribe(([ message1, message2 ]: [any, any]) => {
expect(JSON.parse(message1.data)).toEqual(expect.objectContaining(event));
expect(JSON.parse(message2.data)).toEqual(expect.objectContaining(event));
- done();
+ webSocketServer.close(done);
});
});
@@ -86,7 +86,7 @@ describe('WebSocket server', () => {
// then
targetClient.once('message', message => {
expect(message).toEqual(event);
- done();
+ webSocketServer.close(done);
});
});
@@ -107,14 +107,14 @@ describe('WebSocket server', () => {
// when
const app = await createWebSocketServer({ options: { server }, listener })
- await app();
+ const webSocketServer = await app();
targetClient.once('open', () => targetClient.send(incomingEvent));
// then
targetClient.once('message', message => {
expect(message).toEqual(outgoingEvent);
- done();
+ webSocketServer.close(done);
});
});
@@ -131,7 +131,7 @@ describe('WebSocket server', () => {
// when
const app = await createWebSocketServer({ options: { server }, listener });
- await app();
+ const webSocketServer = await app();
targetClient.once('open', () => {
targetClient.send(incomingEvent);
@@ -144,7 +144,7 @@ describe('WebSocket server', () => {
.subscribe((messages: any[]) => {
expect(messages[0].data).toEqual(outgoingEvent);
expect(messages[1].data).toEqual(outgoingEvent);
- done();
+ webSocketServer.close(done);
});
});
@@ -164,7 +164,7 @@ describe('WebSocket server', () => {
// when
const app = await createWebSocketServer({ options: { server }, listener });
- await app();
+ const webSocketServer = await app();
targetClient.once('open', () => {
targetClient.send(incomingEvent);
@@ -177,7 +177,7 @@ describe('WebSocket server', () => {
.subscribe((messages: any[]) => {
expect(messages[0].data).toEqual(outgoingEvent);
expect(messages[1].data).toEqual(outgoingEvent);
- done();
+ webSocketServer.close(done);
});
});
@@ -191,7 +191,7 @@ describe('WebSocket server', () => {
// when
const app = await createWebSocketServer({ options: { server }, connection$, listener });
- await app();
+ const webSocketServer = await app();
// then
merge(
@@ -199,7 +199,7 @@ describe('WebSocket server', () => {
fromEvent(targetClient2, 'open'),
)
.pipe(take(2), toArray())
- .subscribe(() => done());
+ .subscribe(() => webSocketServer.close(done));
});
test('triggers connection error', async done => {
@@ -213,7 +213,7 @@ describe('WebSocket server', () => {
// when
const app = await createWebSocketServer({ options: { server }, connection$, listener });
- await app();
+ const webSocketServer = await app();
// then
merge(
@@ -227,7 +227,7 @@ describe('WebSocket server', () => {
expect(data[1][1].statusCode).toEqual(error.status);
expect(data[0][1].statusMessage).toEqual(error.message);
expect(data[1][1].statusMessage).toEqual(error.message);
- done();
+ webSocketServer.close(done);
},
);
});
@@ -259,7 +259,7 @@ describe('WebSocket server', () => {
// when
const app = await createWebSocketServer({ options: { server }, listener });
- await app();
+ const webSocketServer = await app();
targetClient.once('open', () => {
targetClient.send(Buffer.from(message));
@@ -268,7 +268,7 @@ describe('WebSocket server', () => {
// then
targetClient.once('message', (incomingMessage: Buffer) => {
expect(incomingMessage.toString('utf8')).toEqual(message);
- done();
+ webSocketServer.close(done);
});
});
});

chore: jest test environment set to "node"