Skip to content

Commit

Permalink
chore(apiv2): add tarchitecture test
Browse files Browse the repository at this point in the history
  • Loading branch information
Johannbr committed Nov 14, 2024
1 parent 2b6adaa commit 280b2e6
Show file tree
Hide file tree
Showing 7 changed files with 537 additions and 27 deletions.
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,6 @@
"jestCommandLine": "source ~/.zshrc && nvm use && npm run test --",
"runMode": "watch"
}
]
],
"typescript.tsdk": "node_modules/typescript/lib"
}
1 change: 1 addition & 0 deletions apiv2/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
"ts-jest": "^29.2.5",
"ts-loader": "^9.4.3",
"ts-node": "^10.9.1",
"tsarch": "^5.4.0",
"tsconfig-paths": "^4.2.0",
"typescript": "^5.6.3"
},
Expand Down
26 changes: 0 additions & 26 deletions apiv2/src/admin/core/sejours/cle/classe/ClasseService.spec.ts

This file was deleted.

40 changes: 40 additions & 0 deletions apiv2/test/architecture/arch.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// imports and applies the jest extensions
import "tsarch/dist/jest";

// imports the files entrypoint
import { FileConditionBuilder, filesOfProject } from "tsarch";
import { Folders } from "./folder";

describe("architecture", () => {
let files: FileConditionBuilder;
beforeAll(async () => {
// console.log(__filename + "/tsconfig.json");
// files = filesOfProject(__dirname + "/tsconfig.json");
files = await filesOfProject("./tsconfig.json");
});
// architecture tests can take a while to finish
jest.setTimeout(60000);

it("business logic should not depend on infra folder", async () => {
const rule = files.matchingPattern(Folders.CORE).shouldNot().dependOnFiles().matchingPattern(Folders.INFRA);
await expect(rule).toPassAsync();
});

it.skip("business logic should exclusively depend on @notification, @shared, snu-lib, @nestjs/common", async () => {
const rule = files
.inFolder(Folders.SRC_CORE)
.should()
.dependOnFiles()
.matchingPattern(`^(snu-lib|common|core)$`);
// .matchingPattern("^(@notification|@shared|snu-lib|@nestjs/common|core)$");

// console.log(files.matchingPattern(Folders.SRC_CORE_PATTERN));
await expect(rule).toPassAsync();
});

it("business logic should be cycle free", async () => {
const rule = files.inFolder(Folders.SRC).should().beFreeOfCycles();

await expect(rule).toPassAsync();
});
});
7 changes: 7 additions & 0 deletions apiv2/test/architecture/folder.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export enum Folders {
SRC = "src",
CORE = "core",
INFRA = "infra",
SRC_CORE_PATTERN = "^(?=.*\bsrc\b)(?=.*\bcore\b)(?!.*.spec.ts$).*",
SRC_CORE = "src/admin/core",
}
3 changes: 3 additions & 0 deletions apiv2/tsconfig.test.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "./tsconfig.json",
}
Loading

0 comments on commit 280b2e6

Please sign in to comment.