Skip to content

Commit fcb4c6a

Browse files
committed
Used Emmett testing instead of node:assert
1 parent 250d05c commit fcb4c6a

File tree

15 files changed

+169
-148
lines changed

15 files changed

+169
-148
lines changed

src/docs/snippets/gettingStarted/webApi/simpleApi.int.spec.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import {
2+
assertEqual,
23
assertMatches,
4+
assertOk,
35
getInMemoryEventStore,
46
type EventStore,
57
} from '@event-driven-io/emmett';
68
import { getApplication } from '@event-driven-io/emmett-expressjs';
7-
89
import { type Application } from 'express';
9-
import assert from 'node:assert/strict';
1010
import { randomUUID } from 'node:crypto';
1111
import { beforeEach, describe, it } from 'node:test';
1212
import request from 'supertest';
@@ -78,7 +78,7 @@ void describe('Simple Api from getting started', () => {
7878
await request(app)
7979
.delete(`/clients/${clientId}/shopping-carts/current`)
8080
.expect((response) => {
81-
assert.equal(response.statusCode, 403);
81+
assertEqual(response.statusCode, 403);
8282
});
8383

8484
const shoppingCartId = getShoppingCartId(clientId);
@@ -87,8 +87,8 @@ void describe('Simple Api from getting started', () => {
8787
getShoppingCartId(clientId),
8888
);
8989

90-
assert.ok(result);
91-
assert.equal(result.events.length, 4);
90+
assertOk(result);
91+
assertEqual(result.events.length, 4);
9292

9393
assertMatches(result?.events, [
9494
{

src/packages/emmett-expressjs/src/e2e/decider/applicationLogicWithOC.int.spec.ts

+8-6
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import {
2+
assertEqual,
3+
assertFails,
24
assertMatches,
5+
assertOk,
36
getInMemoryEventStore,
47
type EventStore,
58
} from '@event-driven-io/emmett';
69
import { type Application } from 'express';
7-
import assert from 'node:assert/strict';
810
import { randomUUID } from 'node:crypto';
911
import { beforeEach, describe, it } from 'node:test';
1012
import request from 'supertest';
@@ -42,9 +44,9 @@ void describe('Application logic with optimistic concurrency', () => {
4244
const current = createResponse.body;
4345

4446
if (!current.id) {
45-
assert.fail();
47+
assertFails();
4648
}
47-
assert.ok(current.id);
49+
assertOk(current.id);
4850

4951
const shoppingCartId = current.id;
5052

@@ -122,7 +124,7 @@ void describe('Application logic with optimistic concurrency', () => {
122124
.delete(`/clients/${clientId}/shopping-carts/${shoppingCartId}`)
123125
.set(HeaderNames.IF_MATCH, toWeakETag(currentRevision))
124126
.expect((response) => {
125-
assert.equal(response.statusCode, 403);
127+
assertEqual(response.statusCode, 403);
126128
assertMatches(response.body, {
127129
detail: ShoppingCartErrors.CART_IS_ALREADY_CLOSED,
128130
});
@@ -131,8 +133,8 @@ void describe('Application logic with optimistic concurrency', () => {
131133
const result =
132134
await eventStore.readStream<ShoppingCartEvent>(shoppingCartId);
133135

134-
assert.ok(result);
135-
assert.equal(result.events.length, Number(currentRevision));
136+
assertOk(result);
137+
assertEqual(result.events.length, Number(currentRevision));
136138

137139
assertMatches(result?.events, [
138140
{

src/packages/emmett-expressjs/src/e2e/testing.ts

+7-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1-
import { assertUnsignedBigInt } from '@event-driven-io/emmett';
2-
import assert from 'node:assert/strict';
1+
import {
2+
assertMatches,
3+
assertOk,
4+
assertUnsignedBigInt,
5+
} from '@event-driven-io/emmett';
36
import { Test, type Response } from 'supertest';
47
import { getWeakETagValue, type ETag } from '../etag';
58

@@ -15,8 +18,8 @@ export const expectNextRevisionInResponseEtag = <RequestBody>(
1518
response: TestResponse<RequestBody>,
1619
) => {
1720
const eTagValue = response.headers['etag'];
18-
assert.ok(eTagValue);
19-
assert.match(eTagValue, /W\/"\d+.*"/);
21+
assertOk(eTagValue);
22+
assertMatches(eTagValue, /W\/"\d+.*"/);
2023

2124
const eTag = getWeakETagValue(eTagValue as ETag);
2225

src/packages/emmett-expressjs/src/testing/apiSpecification.ts

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import {
2+
assertEqual,
3+
assertFails,
24
assertMatches,
35
type DefaultStreamVersionType,
46
type Event,
57
type EventStore,
68
} from '@event-driven-io/emmett';
79
import { type Application } from 'express';
810
import type { ProblemDocument } from 'http-problem-details';
9-
import assert from 'node:assert/strict';
1011
import type { Response, Test } from 'supertest';
1112
import supertest from 'supertest';
1213
import type TestAgent from 'supertest/lib/agent';
@@ -57,7 +58,7 @@ export const expectResponse =
5758
) =>
5859
(response: Response): void => {
5960
const { body, headers } = options ?? {};
60-
assert.equal(response.statusCode, statusCode);
61+
assertEqual(response.statusCode, statusCode);
6162
if (body) assertMatches(response.body, body);
6263
if (headers) assertMatches(response.headers, headers);
6364
};
@@ -115,14 +116,14 @@ export const ApiSpecification = {
115116
if (typeof verify === 'function') {
116117
const succeeded = verify(response);
117118

118-
if (succeeded === false) assert.fail();
119+
if (succeeded === false) assertFails();
119120
} else if (Array.isArray(verify)) {
120121
const [first, ...rest] = verify;
121122

122123
if (typeof first === 'function') {
123124
const succeeded = first(response);
124125

125-
if (succeeded === false) assert.fail();
126+
if (succeeded === false) assertFails();
126127
}
127128

128129
const events = typeof first === 'function' ? rest : verify;

src/packages/emmett-fastify/src/e2e/decider/applicationLogicWithOC.int.spec.ts

+12-10
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import {
2+
assertEqual,
3+
assertFails,
24
assertMatches,
5+
assertOk,
36
getInMemoryEventStore,
47
type EventStore,
58
} from '@event-driven-io/emmett';
69
import { type FastifyInstance } from 'fastify';
7-
import assert from 'node:assert/strict';
810
import { randomUUID } from 'node:crypto';
911
import { beforeEach, describe, it } from 'node:test';
1012
import { getApplication } from '../..';
@@ -34,9 +36,9 @@ void describe('Application logic with optimistic concurrency using Fastify', ()
3436

3537
const current = createResponse.json<{ id: string }>();
3638
if (!current?.id) {
37-
assert.fail();
39+
assertFails();
3840
}
39-
assert.ok(current.id);
41+
assertOk(current.id);
4042

4143
const shoppingCartId = current.id;
4244
///////////////////////////////////////////////////
@@ -51,7 +53,7 @@ void describe('Application logic with optimistic concurrency using Fastify', ()
5153
url: `/clients/${clientId}/shopping-carts/${shoppingCartId}/product-items`,
5254
body: twoPairsOfShoes,
5355
});
54-
assert.equal(response.statusCode, 204);
56+
assertEqual(response.statusCode, 204);
5557

5658
///////////////////////////////////////////////////
5759
// 3. Add T-Shirt
@@ -67,7 +69,7 @@ void describe('Application logic with optimistic concurrency using Fastify', ()
6769
body: tShirt,
6870
});
6971

70-
assert.equal(response.statusCode, 204);
72+
assertEqual(response.statusCode, 204);
7173

7274
///////////////////////////////////////////////////
7375
// 4. Remove pair of shoes
@@ -82,7 +84,7 @@ void describe('Application logic with optimistic concurrency using Fastify', ()
8284
method: 'DELETE',
8385
url: `/clients/${clientId}/shopping-carts/${shoppingCartId}/product-items?productId=${pairOfShoes.productId}&quantity=${pairOfShoes.quantity}&unitPrice=${pairOfShoes.unitPrice}`,
8486
});
85-
assert.equal(response.statusCode, 204);
87+
assertEqual(response.statusCode, 204);
8688

8789
///////////////////////////////////////////////////
8890
// 5. Confirm cart
@@ -93,7 +95,7 @@ void describe('Application logic with optimistic concurrency using Fastify', ()
9395
url: `/clients/${clientId}/shopping-carts/${shoppingCartId}/confirm`,
9496
});
9597

96-
assert.equal(response.statusCode, 204);
98+
assertEqual(response.statusCode, 204);
9799

98100
///////////////////////////////////////////////////
99101
// 6. Try Cancel Cart
@@ -103,15 +105,15 @@ void describe('Application logic with optimistic concurrency using Fastify', ()
103105
url: `/clients/${clientId}/shopping-carts/${shoppingCartId}`,
104106
});
105107

106-
assert.equal(response.statusCode, 403);
108+
assertEqual(response.statusCode, 403);
107109
assertMatches(response.json(), {
108110
detail: ShoppingCartErrors.CART_IS_ALREADY_CLOSED,
109111
});
110112
const result =
111113
await eventStore.readStream<ShoppingCartEvent>(shoppingCartId);
112114

113-
assert.ok(result);
114-
assert.equal(result.events.length, Number(5));
115+
assertOk(result);
116+
assertEqual(result.events.length, Number(5));
115117

116118
assertMatches(result?.events, [
117119
{

src/packages/emmett-fastify/src/e2e/testing.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1+
import { assertMatches, assertOk } from '@event-driven-io/emmett';
12
import type { Response } from 'light-my-request';
2-
import assert from 'node:assert/strict';
33
import type { Test } from 'supertest';
44

55
export type TestResponse<RequestBody> = Omit<
@@ -14,8 +14,8 @@ export const expectNextRevisionInResponseEtag = <RequestBody>(
1414
response: TestResponse<RequestBody>,
1515
) => {
1616
const eTagValue = response.headers['etag'];
17-
assert.ok(eTagValue);
18-
assert.match(eTagValue, /W\/"\d+.*"/);
17+
assertOk(eTagValue);
18+
assertMatches(eTagValue, /W\/"\d+.*"/);
1919
};
2020

2121
export const runTwice = (test: () => Promise<Response>) => {

src/packages/emmett-testcontainers/src/eventStore/eventStoreDBContainer.e2e.spec.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import { jsonEvent } from '@eventstore/db-client';
2-
import assert from 'node:assert/strict';
32
import { randomUUID } from 'node:crypto';
43
import { after, beforeEach, describe, it } from 'node:test';
54
import {
65
EventStoreDBContainer,
76
StartedEventStoreDBContainer,
87
} from './eventStoreDBContainer';
8+
import { assertOk } from '@event-driven-io/emmett';
99

1010
void describe('EventStoreDBContainer', () => {
1111
let container: StartedEventStoreDBContainer;
@@ -22,7 +22,7 @@ void describe('EventStoreDBContainer', () => {
2222
jsonEvent({ type: 'test-event', data: { test: 'test' } }),
2323
);
2424

25-
assert.ok(result.success);
25+
assertOk(result.success);
2626
});
2727

2828
after(async () => {

src/packages/emmett/src/commandHandling/handleCommand.unit.spec.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import assert from 'node:assert';
21
import { randomUUID } from 'node:crypto';
32
import { describe, it } from 'node:test';
43
import { getInMemoryEventStore } from '../eventStore';
4+
import { assertDeepEqual, assertEqual } from '../testing';
55
import { type Event } from '../typing';
66
import { CommandHandler } from './handleCommand';
77

@@ -106,11 +106,11 @@ void describe('Command Handler', () => {
106106
(state) => addProductItem(command, state),
107107
);
108108

109-
assert.deepEqual(newState, {
109+
assertDeepEqual(newState, {
110110
productItems: [productItem],
111111
totalAmount: productItem.price * productItem.quantity,
112112
});
113-
assert.equal(nextExpectedStreamVersion, 1);
113+
assertEqual(nextExpectedStreamVersion, 1n);
114114
});
115115

116116
void it('When called successfuly returns new state for multiple returned events', async () => {
@@ -132,11 +132,11 @@ void describe('Command Handler', () => {
132132
(state) => addProductItemWithDiscount(command, state),
133133
);
134134

135-
assert.deepEqual(newState, {
135+
assertDeepEqual(newState, {
136136
productItems: [productItem],
137137
totalAmount:
138138
productItem.price * productItem.quantity * (1 - defaultDiscount),
139139
});
140-
assert.equal(nextExpectedStreamVersion, 2);
140+
assertEqual(nextExpectedStreamVersion, 2n);
141141
});
142142
});

src/packages/emmett/src/eventStore/expectedVersion.unit.spec.ts

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import assert from 'node:assert/strict';
21
import { describe, it } from 'node:test';
2+
import { assertEqual, assertOk } from '../testing';
33
import {
44
NO_CONCURRENCY_CHECK,
55
STREAM_DOES_NOT_EXIST,
@@ -12,21 +12,21 @@ void describe('matchesExpectedVersion', () => {
1212
const allCurrentVersions = [undefined, 0, -1, 1, 100, 'random', ''];
1313

1414
for (const currentStreamVersion of allCurrentVersions) {
15-
assert.ok(
15+
assertOk(
1616
matchesExpectedVersion(currentStreamVersion, NO_CONCURRENCY_CHECK),
1717
);
1818
}
1919
});
2020

2121
void it('When STREAM_DOES_NOT_EXIST provided returns `true` for current equals `undefined`', () => {
22-
assert.ok(matchesExpectedVersion(undefined, STREAM_DOES_NOT_EXIST));
22+
assertOk(matchesExpectedVersion(undefined, STREAM_DOES_NOT_EXIST));
2323
});
2424

2525
void it('When STREAM_DOES_NOT_EXIST provided returns `false` for current different than `undefined`', () => {
2626
const definedStreamVersion = [0, -1, 1, 100, 'random', ''];
2727

2828
for (const currentStreamVersion of definedStreamVersion) {
29-
assert.equal(
29+
assertEqual(
3030
matchesExpectedVersion(currentStreamVersion, STREAM_DOES_NOT_EXIST),
3131
false,
3232
);
@@ -37,19 +37,19 @@ void describe('matchesExpectedVersion', () => {
3737
const definedStreamVersion = [0, -1, 1, 100, 'random', ''];
3838

3939
for (const currentStreamVersion of definedStreamVersion) {
40-
assert.ok(matchesExpectedVersion(currentStreamVersion, STREAM_EXISTS));
40+
assertOk(matchesExpectedVersion(currentStreamVersion, STREAM_EXISTS));
4141
}
4242
});
4343

4444
void it('When STREAM_EXISTS provided returns `false` for current equals `undefined`', () => {
45-
assert.equal(matchesExpectedVersion(undefined, STREAM_EXISTS), false);
45+
assertEqual(matchesExpectedVersion(undefined, STREAM_EXISTS), false);
4646
});
4747

4848
void it('When value provided returns `true` for current matching expected value', () => {
4949
const definedStreamVersion = [0, -1, 1, 100, 'random', ''];
5050

5151
for (const streamVersion of definedStreamVersion) {
52-
assert.ok(matchesExpectedVersion(streamVersion, streamVersion));
52+
assertOk(matchesExpectedVersion(streamVersion, streamVersion));
5353
}
5454
});
5555

@@ -64,7 +64,7 @@ void describe('matchesExpectedVersion', () => {
6464
];
6565

6666
for (const streamVersion of definedStreamVersion) {
67-
assert.equal(
67+
assertEqual(
6868
matchesExpectedVersion(streamVersion.current, streamVersion.expected),
6969
false,
7070
);

0 commit comments

Comments
 (0)