Skip to content

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
joonashak committed Jul 28, 2023
1 parent a49037b commit 5234506
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 67 deletions.
2 changes: 1 addition & 1 deletion app-nest/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"test:watch": "jest --watch",
"test:cov": "jest --coverage",
"test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand",
"test:integration": "jest --config ./test/jest-e2e.json"
"test:integration": "jest --config ./test/jest-integration.json"
},
"dependencies": {
"@golevelup/nestjs-discovery": "^4.0.0",
Expand Down
63 changes: 0 additions & 63 deletions app-nest/test/app.e2e-spec.ts

This file was deleted.

23 changes: 23 additions & 0 deletions app-nest/test/app.int-spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { INestApplication } from "@nestjs/common";
import { UserService } from "../src/entities/user/user.service";
import createTestingModule from "./test-app.module";

describe("App", () => {
let app: INestApplication;

beforeEach(async () => {
const moduleFixture = await createTestingModule().compile();
app = moduleFixture.createNestApplication();
await app.init();
});

afterAll(async () => {
await app.close();
});

it("Find all users", async () => {
const userService = app.get(UserService);
const users = await userService.findAll();
expect(users).toHaveLength(1);
});
});
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
{
"moduleFileExtensions": ["js", "json", "ts"],
"moduleFileExtensions": [
"js",
"json",
"ts"
],
"rootDir": ".",
"testEnvironment": "node",
"testRegex": ".e2e-spec.ts$",
"testRegex": ".int-spec.ts$",
"transform": {
"^.+\\.(t|j)s$": "ts-jest"
}
}
}
26 changes: 26 additions & 0 deletions app-nest/test/test-app.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { Test } from "@nestjs/testing";
import { TypeOrmModule } from "@nestjs/typeorm";
import configuration from "../src/config/configuration";
import { EntitiesModule } from "../src/entities/entities.module";
import { GuiModule } from "../src/gui/gui.module";
import testConfiguration from "./testConfiguration";

const createTestingModule = () =>
Test.createTestingModule({
imports: [
TypeOrmModule.forRoot({
type: "postgres",
host: testConfiguration.database.host,
port: configuration.database.port,
username: testConfiguration.database.username,
password: testConfiguration.database.password,
database: testConfiguration.database.name,
synchronize: true,
autoLoadEntities: true,
}),
GuiModule,
EntitiesModule,
],
});

export default createTestingModule;

0 comments on commit 5234506

Please sign in to comment.