Skip to content

Commit

Permalink
feat: create e2e test setup function
Browse files Browse the repository at this point in the history
  • Loading branch information
typeWolffo committed Jul 15, 2024
1 parent 8f74c5e commit befc4c9
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,4 @@ import { validate as uuidValidate } from "uuid";

export function setupValidation() {
FormatRegistry.Set("uuid", (value) => uuidValidate(value));
FormatRegistry.Set("email", (value) => {
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
return emailRegex.test(value);
});
}
30 changes: 30 additions & 0 deletions examples/common_nestjs_remix/apps/api/test/create-e2e-test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { Provider, Type } from "@nestjs/common";
import { Test, TestingModule } from "@nestjs/testing";
import cookieParser from "cookie-parser";
import { AppModule } from "../src/app.module";
import { setupTestDatabase } from "./test-database";

export async function createE2ETest(customProviders: Provider[] = []) {
const { db } = await setupTestDatabase();

const moduleFixture: TestingModule = await Test.createTestingModule({
imports: [AppModule],
providers: [...customProviders],
})
.overrideProvider("DB")
.useValue(db)
.compile();

const app = moduleFixture.createNestApplication();

app.use(cookieParser());

await app.init();

return {
app,
moduleFixture,
db,
getService: <T>(service: Type<T>): T => moduleFixture.get(service),
};
}

0 comments on commit befc4c9

Please sign in to comment.