Skip to content

Commit

Permalink
Made event store features tests internal not to expose node packages …
Browse files Browse the repository at this point in the history
…in bundled Emmett code

The issue is that `esbuild` (for `commonjs`) stripes the 'node:' prefix for targets different from the node (or using node earlier than 14) as they cannot handle packages with prefix like `node:test`. See more in:
evanw/esbuild@6b4f970

`Tsup` that I'm using for bundling also seems not to be handling that fully as it's built on top of `esbuild`: egoist/tsup#1003

As there's no dependency to `test` package, then bundled code fails to load in commonjs environment. One solution is to add dependency to shim, as @alex-laycalvert suggested in #60. But I'm reluctant to do it, as I don't want to target older node environments than Node LTS version (currently >= 20.11.1). I also don't want to add dependency on the unmaintained shim package with potential vulnerabilities.

I could try to change tsconfig target from ESNext to Node, but at the moment I don't want to have this limitation, as I'd like to have the main Emmett package working both with backend and frontend.

The change removes the event store matrix tests, as they don't need to be exposed now. They're still available as js map files to make internal referencing work correctly.

This change should be seen more as a fix rather than solving the root cause. I need to think longer on alternative solutions like having internal project for testing event stores and not having this test at all.

Fixes #59,
Closes #60

Besides that, following the boy scout rule I removed the `no-floating-promise` ingores as I found the way of handling them using `void` keyword before describes and it. And that Fixes #16

@alex-laycalvert @thiagomini @mkubasz FYI
  • Loading branch information
oskardudycz committed Apr 28, 2024
1 parent 68610f1 commit 61f33c5
Show file tree
Hide file tree
Showing 30 changed files with 94 additions and 105 deletions.
15 changes: 7 additions & 8 deletions src/docs/snippets/gettingStarted/businessLogic.unit.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable @typescript-eslint/no-floating-promises */
import { describe, it } from 'node:test';
import { decide } from './businessLogic';
import { evolve, getInitialState } from './shoppingCart';
Expand All @@ -14,9 +13,9 @@ const given = DeciderSpecification.for({
initialState: getInitialState,
});

describe('ShoppingCart', () => {
describe('When empty', () => {
it('should add product item', () => {
void describe('ShoppingCart', () => {
void describe('When empty', () => {
void it('should add product item', () => {
given([])
.when({
type: 'AddProductItemToShoppingCart',
Expand All @@ -39,8 +38,8 @@ describe('ShoppingCart', () => {
});
});

describe('When opened', () => {
it('should confirm', () => {
void describe('When opened', () => {
void it('should confirm', () => {
given({
type: 'ProductItemAddedToShoppingCart',
data: {
Expand Down Expand Up @@ -68,8 +67,8 @@ describe('ShoppingCart', () => {
});
});

describe('When confirmed', () => {
it('should not add products', () => {
void describe('When confirmed', () => {
void it('should not add products', () => {
given([
{
type: 'ProductItemAddedToShoppingCart',
Expand Down
9 changes: 4 additions & 5 deletions src/docs/snippets/gettingStarted/webApi/apiBDD.e2e.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable @typescript-eslint/no-floating-promises */
import { after, before, beforeEach, describe, it } from 'node:test';
import type { PricedProductItem } from '../events';
import { ShoppingCartStatus } from './shoppingCart';
Expand All @@ -18,7 +17,7 @@ import {
} from '@event-driven-io/emmett-testcontainers';
import { randomUUID } from 'node:crypto';

describe('ShoppingCart E2E', () => {
void describe('ShoppingCart E2E', () => {
const unitPrice = 100;
let clientId: string;
let shoppingCartId: string;
Expand Down Expand Up @@ -52,8 +51,8 @@ describe('ShoppingCart E2E', () => {
return esdbContainer.stop();
});

describe('When opened with product item', () => {
it('should confirm', () => {
void describe('When opened with product item', () => {
void it('should confirm', () => {
return given((request) =>
request
.post(`/clients/${clientId}/shopping-carts/current/product-items`)
Expand All @@ -65,7 +64,7 @@ describe('ShoppingCart E2E', () => {
.then([expectResponse(204)]);
});

it('should return details', () => {
void it('should return details', () => {
return given((request) =>
request
.post(`/clients/${clientId}/shopping-carts/current/product-items`)
Expand Down
15 changes: 7 additions & 8 deletions src/docs/snippets/gettingStarted/webApi/apiBDD.int.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable @typescript-eslint/no-floating-promises */
import { beforeEach, describe, it } from 'node:test';
import type { PricedProductItem, ShoppingCartEvent } from '../events';
import { shoppingCartApi } from './simpleApi';
Expand All @@ -17,7 +16,7 @@ import {
} from '@event-driven-io/emmett-expressjs';
import { randomUUID } from 'node:crypto';

describe('ShoppingCart', () => {
void describe('ShoppingCart', () => {
let clientId: string;
let shoppingCartId: string;

Expand All @@ -26,8 +25,8 @@ describe('ShoppingCart', () => {
shoppingCartId = `shopping_cart:${clientId}:current`;
});

describe('When empty', () => {
it('should add product item', () => {
void describe('When empty', () => {
void it('should add product item', () => {
return given()
.when((request) =>
request
Expand All @@ -49,8 +48,8 @@ describe('ShoppingCart', () => {
});
});

describe('When opened with product item', () => {
it('should confirm', () => {
void describe('When opened with product item', () => {
void it('should confirm', () => {
return given(
existingStream(shoppingCartId, [
{
Expand Down Expand Up @@ -81,8 +80,8 @@ describe('ShoppingCart', () => {
});
});

describe('When confirmed', () => {
it('should not add products', () => {
void describe('When confirmed', () => {
void it('should not add products', () => {
return given(
existingStream(shoppingCartId, [
{
Expand Down
3 changes: 1 addition & 2 deletions src/docs/snippets/gettingStarted/webApi/apiBDDE2EGiven.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable @typescript-eslint/no-floating-promises */
/* eslint-disable @typescript-eslint/no-unused-vars */
import { after, before, describe } from 'node:test';
import { shoppingCartApi } from './simpleApi';
Expand All @@ -13,7 +12,7 @@ import {
} from '@event-driven-io/emmett-testcontainers';

let esdbContainer: StartedEventStoreDBContainer;
describe('ShoppingCart E2E', () => {
void describe('ShoppingCart E2E', () => {
// Set up a container before all tests
before(async () => {
esdbContainer = await new EventStoreDBContainer().start();
Expand Down
5 changes: 2 additions & 3 deletions src/docs/snippets/gettingStarted/webApi/apiBDDE2ETest.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable @typescript-eslint/no-floating-promises */
import { type EventStore } from '@event-driven-io/emmett';
import {
ApiE2ESpecification,
Expand Down Expand Up @@ -43,8 +42,8 @@ import { getEventStoreDBEventStore } from '@event-driven-io/emmett-esdb';
import { expectResponse } from '@event-driven-io/emmett-expressjs';
import type { StartedEventStoreDBContainer } from '@event-driven-io/emmett-testcontainers';

describe('When opened with product item', () => {
it('should confirm', () => {
void describe('When opened with product item', () => {
void it('should confirm', () => {
return given((request) =>
request
.post(`/clients/${clientId}/shopping-carts/current/product-items`)
Expand Down
5 changes: 2 additions & 3 deletions src/docs/snippets/gettingStarted/webApi/apiBDDIntTest.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable @typescript-eslint/no-floating-promises */
import {
getInMemoryEventStore,
type EventStore,
Expand Down Expand Up @@ -49,8 +48,8 @@ import {
expectResponse,
} from '@event-driven-io/emmett-expressjs';

describe('When opened with product item', () => {
it('should confirm', () => {
void describe('When opened with product item', () => {
void it('should confirm', () => {
return given(
existingStream(shoppingCartId, [
{
Expand Down
5 changes: 2 additions & 3 deletions src/docs/snippets/gettingStarted/webApi/simpleApi.int.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable @typescript-eslint/no-floating-promises */
import {
assertMatches,
getInMemoryEventStore,
Expand All @@ -18,7 +17,7 @@ const getUnitPrice = (_productId: string) => {
return Promise.resolve(100);
};

describe('Simple Api from getting started', () => {
void describe('Simple Api from getting started', () => {
let app: Application;
let eventStore: EventStore;

Expand All @@ -29,7 +28,7 @@ describe('Simple Api from getting started', () => {
});
});

it('Should handle requests correctly', async () => {
void it('Should handle requests correctly', async () => {
const clientId = randomUUID();
///////////////////////////////////////////////////
// 1. Add Two Pair of Shoes
Expand Down
29 changes: 16 additions & 13 deletions src/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@event-driven-io/core",
"version": "0.7.0",
"version": "0.7.1",
"description": "Emmett - Event Sourcing development made simple",
"engines": {
"node": ">=20.11.1"
Expand Down Expand Up @@ -61,7 +61,6 @@
],
"devDependencies": {
"@faker-js/faker": "8.4.1",
"@types/node": "20.11.30",
"@typescript-eslint/eslint-plugin": "7.4.0",
"@typescript-eslint/parser": "7.4.0",
"eslint": "8.57.0",
Expand All @@ -78,6 +77,7 @@
"vitepress": "1.0.1"
},
"peerDependencies": {
"@types/node": "20.11.30",
"@types/express": "4.17.21",
"@types/supertest": "6.0.2",
"supertest": "6.3.4"
Expand Down
4 changes: 2 additions & 2 deletions src/packages/emmett-esdb/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@event-driven-io/emmett-esdb",
"version": "0.7.0",
"version": "0.7.1",
"description": "Emmett - EventStoreDB - Event Sourcing development made simple",
"scripts": {
"build": "tsup",
Expand Down Expand Up @@ -50,7 +50,7 @@
"@event-driven-io/emmett-testcontainers": "^0.5.0"
},
"peerDependencies": {
"@event-driven-io/emmett": "0.7.0",
"@event-driven-io/emmett": "0.7.1",
"@eventstore/db-client": "^6.1.0"
}
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
/* eslint-disable @typescript-eslint/no-floating-promises */
import {
testAggregateStream,
type EventStoreFactory,
} from '@event-driven-io/emmett';
import {
EventStoreDBContainer,
StartedEventStoreDBContainer,
} from '@event-driven-io/emmett-testcontainers';
import { describe } from 'node:test';
import {
testAggregateStream,
type EventStoreFactory,
} from '../../../emmett/src/testing/features';
import { getEventStoreDBEventStore } from './eventstoreDBEventStore';

describe('EventStoreDBEventStore', async () => {
void describe('EventStoreDBEventStore', async () => {
let esdbContainer: StartedEventStoreDBContainer;

const eventStoreFactory: EventStoreFactory = async () => {
Expand Down
2 changes: 1 addition & 1 deletion src/packages/emmett-esdb/tsup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export default defineConfig({
watch: env === 'development',
target: 'esnext',
outDir: 'dist', //env === 'production' ? 'dist' : 'lib',
entry: ['src/**/*.ts', '!src/**/*.spec.ts'], //include all files under src but not specs
entry: ['src/**/*.ts', '!src/**/*.spec.ts', '!src/**/*.internal.ts'], //include all files under src but not specs
sourcemap: true,
tsconfig: 'tsconfig.build.json', // workaround for https://github.com/egoist/tsup/issues/571#issuecomment-1760052931
});
4 changes: 2 additions & 2 deletions src/packages/emmett-expressjs/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@event-driven-io/emmett-expressjs",
"version": "0.7.0",
"version": "0.7.1",
"description": "Emmett - Event Sourcing development made simple",
"scripts": {
"build": "tsup",
Expand Down Expand Up @@ -48,7 +48,7 @@
"dependencies": {},
"devDependencies": {},
"peerDependencies": {
"@event-driven-io/emmett": "0.7.0",
"@event-driven-io/emmett": "0.7.1",
"@types/express": "4.17.21",
"@types/supertest": "6.0.2",
"express": "4.19.2",
Expand Down
Loading

0 comments on commit 61f33c5

Please sign in to comment.