-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: create e2e test setup function
- Loading branch information
1 parent
8f74c5e
commit befc4c9
Showing
2 changed files
with
30 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
examples/common_nestjs_remix/apps/api/test/create-e2e-test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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), | ||
}; | ||
} |