Skip to content

Commit 033054d

Browse files
committed
fix: unit test for migration to vitest
1 parent 4aef2c6 commit 033054d

File tree

2 files changed

+24
-30
lines changed

2 files changed

+24
-30
lines changed

test/grpc_acs.spec.ts

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import {} from 'mocha';
1+
import { } from 'mocha';
22
import should from 'should';
33
import { marshallProtobufAny } from '../src/utilts.js';
44
import { Worker } from '../src/worker.js';
55
import { Topic } from '@restorecommerce/kafka-client';
6-
import {
6+
import {
77
JobServiceDefinition as SchedulingServiceDefinition,
88
JobServiceClient as SchedulingServiceClient,
99
JobOptions_Priority,
@@ -92,12 +92,13 @@ interface MethodWithOutput {
9292
output: any;
9393
};
9494

95-
const PROTO_PATH = 'io/restorecommerce/access_control.proto';
95+
const PROTO_PATH = './io/restorecommerce/access_control.proto';
96+
const PROTO_ROOT = './test/protos';
9697
const PKG_NAME = 'io.restorecommerce.access_control';
9798
const SERVICE_NAME = 'AccessControlService';
9899
const pkgDef: grpc.GrpcObject = grpc.loadPackageDefinition(
99100
proto_loader.loadSync(PROTO_PATH, {
100-
includeDirs: ['node_modules/@restorecommerce/protos'],
101+
includeDirs: PROTO_ROOT ? [PROTO_ROOT] : [],
101102
keepCase: true,
102103
longs: String,
103104
enums: String,
@@ -210,7 +211,6 @@ describe(`testing scheduling-srv ${testSuffix}: gRPC`, () => {
210211
let grpcSchedulingSrv: SchedulingServiceClient;
211212

212213
beforeAll(async function (): Promise<any> {
213-
this.timeout(40000);
214214
worker = new Worker();
215215
cfg.set('events:kafka:groupId', testSuffix + 'grpc');
216216
await worker.start(cfg);
@@ -236,9 +236,11 @@ describe(`testing scheduling-srv ${testSuffix}: gRPC`, () => {
236236
method: 'WhatIsAllowed',
237237
output: jobPolicySetRQ
238238
},
239-
{ method: 'IsAllowed',
240-
output: { decision: Effect.PERMIT } }
241-
]
239+
{
240+
method: 'IsAllowed',
241+
output: { decision: Effect.PERMIT }
242+
}
243+
]
242244
);
243245

244246
// start mock ids-srv needed for findByToken response and return subject
@@ -279,7 +281,7 @@ describe(`testing scheduling-srv ${testSuffix}: gRPC`, () => {
279281
}
280282

281283
payloadShouldBeEmpty(await grpcSchedulingSrv.read(JobReadRequest.fromPartial({ subject }), {}), false);
282-
});
284+
}, 40000);
283285
beforeEach(async () => {
284286
for (const event of ['jobsCreated', 'jobsDeleted']) {
285287
await jobEvents.on(event, () => { });
@@ -293,7 +295,6 @@ describe(`testing scheduling-srv ${testSuffix}: gRPC`, () => {
293295
]);
294296
});
295297
afterAll(async function (): Promise<any> {
296-
this.timeout(20000);
297298
await Promise.allSettled([
298299
stopACSGrpcMockServer(),
299300
stopIDSGrpcMockServer(),
@@ -303,9 +304,8 @@ describe(`testing scheduling-srv ${testSuffix}: gRPC`, () => {
303304
await worker.schedulingService.clear(),
304305
]);
305306
await worker.stop();
306-
});
307-
describe(`create a one-time job ${testSuffix}`, function postJob(): void {
308-
this.timeout(30000);
307+
}, 20000);
308+
describe(`create a one-time job ${testSuffix}`, { timeout: 30000 }, () => {
309309
it(`should create a new job and execute it immediately ${testSuffix}`, async () => {
310310
const w = await runWorker('test-job', 1, cfg, logger, worker.events, async (job) => {
311311
validateScheduledJob(job, 'ONCE', logger);
@@ -462,8 +462,7 @@ describe(`testing scheduling-srv ${testSuffix}: gRPC`, () => {
462462
// createResponse.operation_status!.message!.should.equal('success');
463463
// });
464464
});
465-
describe(`should create a recurring job ${testSuffix}`, function (): void {
466-
this.timeout(8000);
465+
describe(`should create a recurring job ${testSuffix}`, { timeout: 8000 }, function (): void {
467466
it(`should create a recurring job and delete it after some executions ${testSuffix}`, async () => {
468467
let jobExecs = 0;
469468
const w = await runWorker('test-job', 1, cfg, logger, worker.events, async (job) => {
@@ -583,8 +582,7 @@ describe(`testing scheduling-srv ${testSuffix}: gRPC`, () => {
583582
result!.operation_status!.message!.should.equal('success');
584583
});
585584
});
586-
describe(`managing jobs ${testSuffix}`, function (): void {
587-
this.timeout(10000);
585+
describe(`managing jobs ${testSuffix}`, { timeout: 10000 }, function (): void {
588586
it('should schedule some jobs for tomorrow', async () => {
589587
const data = {
590588
timezone: 'Europe/Berlin',

test/kafka_acs.spec.ts

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {} from 'mocha';
1+
import { } from 'mocha';
22
import should from 'should';
33
import * as _ from 'lodash-es';
44

@@ -83,12 +83,13 @@ interface MethodWithOutput {
8383
output: any;
8484
};
8585

86-
const PROTO_PATH = 'io/restorecommerce/access_control.proto';
86+
const PROTO_PATH = './io/restorecommerce/access_control.proto';
87+
const PROTO_ROOT = './test/protos';
8788
const PKG_NAME = 'io.restorecommerce.access_control';
8889
const SERVICE_NAME = 'AccessControlService';
8990
const pkgDef: grpc.GrpcObject = grpc.loadPackageDefinition(
9091
proto_loader.loadSync(PROTO_PATH, {
91-
includeDirs: ['node_modules/@restorecommerce/protos'],
92+
includeDirs: PROTO_ROOT ? [PROTO_ROOT] : [],
9293
keepCase: true,
9394
longs: String,
9495
enums: String,
@@ -186,7 +187,6 @@ describe(`testing scheduling-srv ${testSuffix}: Kafka`, async () => {
186187
let jobTopic: Topic;
187188
let schedulingService: SchedulingService;
188189
beforeAll(async function (): Promise<any> {
189-
this.timeout(12000);
190190
worker = new Worker();
191191

192192
cfg.set('events:kafka:groupId', testSuffix + 'kafka');
@@ -251,7 +251,7 @@ describe(`testing scheduling-srv ${testSuffix}: Kafka`, async () => {
251251
}
252252

253253
payloadShouldBeEmpty(await schedulingService.read(JobReadRequest.fromPartial({ subject }), {}));
254-
});
254+
}, 12000);
255255
beforeEach(async () => {
256256
for (let event of ['jobsCreated', 'jobsDeleted']) {
257257
await jobTopic.on(event, () => { });
@@ -265,7 +265,6 @@ describe(`testing scheduling-srv ${testSuffix}: Kafka`, async () => {
265265
]);
266266
});
267267
afterAll(async function (): Promise<any> {
268-
this.timeout(20000);
269268
await Promise.allSettled([
270269
stopACSGrpcMockServer(),
271270
stopIDSGrpcMockServer(),
@@ -275,9 +274,8 @@ describe(`testing scheduling-srv ${testSuffix}: Kafka`, async () => {
275274
worker.schedulingService.clear(),
276275
]);
277276
await worker.stop();
278-
});
279-
describe('create a one-time job', function postJob(): void {
280-
this.timeout(15000);
277+
}, 20000);
278+
describe('create a one-time job', { timeout: 15000 }, function postJob(): void {
281279
it('should create a new job and execute it immediately', async () => {
282280
const w = await runWorker('test-job', 1, cfg, logger, worker.events, async (job) => {
283281
validateScheduledJob(job, 'ONCE', logger);
@@ -393,8 +391,7 @@ describe(`testing scheduling-srv ${testSuffix}: Kafka`, async () => {
393391
});
394392
});
395393

396-
describe('creating a recurring job', function (): void {
397-
this.timeout(15000);
394+
describe('creating a recurring job', { timeout: 15000 }, function (): void {
398395
it('should create a recurring job and delete it after some executions', async () => {
399396
let jobExecs = 0;
400397
const w = await runWorker('test-job', 1, cfg, logger, worker.events, async (job) => {
@@ -464,8 +461,7 @@ describe(`testing scheduling-srv ${testSuffix}: Kafka`, async () => {
464461
});
465462
});
466463

467-
describe('managing jobs', function (): void {
468-
this.timeout(15000);
464+
describe('managing jobs', { timeout: 15000 }, function (): void {
469465
it('should schedule some jobs for tomorrow', async () => {
470466
const data = {
471467
timezone: 'Europe/Berlin',

0 commit comments

Comments
 (0)