-
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.
test: setup jest testing and gh workflows (#21)
# 🤖 Linear Closes ZKS-85 ZKS-86 ## Description Properly configure Jest, install mocking helper and configure GH Workflows for test and e2e test
- Loading branch information
Showing
10 changed files
with
94 additions
and
28 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
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
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
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,31 @@ | ||
name: Tests | ||
|
||
on: | ||
workflow_call: | ||
|
||
jobs: | ||
unit: | ||
name: Run unit tests | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Check out github repository | ||
uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 1 | ||
|
||
- name: Use PNPM | ||
uses: pnpm/action-setup@v4 | ||
with: | ||
run_install: false | ||
|
||
- name: Use Node.js | ||
uses: actions/setup-node@v4 | ||
with: | ||
node-version: 20 | ||
cache: "pnpm" | ||
|
||
- name: Install dependencies | ||
run: pnpm install --frozen-lockfile | ||
|
||
- name: Run tests | ||
run: pnpm test:e2e |
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
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 |
---|---|---|
|
@@ -36,4 +36,4 @@ yarn-error.log* | |
.DS_Store | ||
*.pem | ||
|
||
packages/*/coverage | ||
coverage |
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 |
---|---|---|
@@ -1,23 +1,32 @@ | ||
import { createMock } from "@golevelup/ts-jest"; | ||
import { Test, TestingModule } from "@nestjs/testing"; | ||
import { EvmProviderService } from "@packages/providers"; | ||
|
||
import { ApiController } from "./api.controller"; | ||
|
||
describe("ApiController", () => { | ||
let apiController: ApiController; | ||
let evmProvider: EvmProviderService; | ||
|
||
beforeEach(async () => { | ||
const app: TestingModule = await Test.createTestingModule({ | ||
controllers: [ApiController], | ||
providers: [EvmProviderService], | ||
providers: [ | ||
{ | ||
provide: EvmProviderService, | ||
useValue: createMock<EvmProviderService>(), | ||
}, | ||
], | ||
}).compile(); | ||
|
||
apiController = app.get<ApiController>(ApiController); | ||
evmProvider = app.get<EvmProviderService>(EvmProviderService); | ||
}); | ||
|
||
describe("root", () => { | ||
it("should return 1", async () => { | ||
expect(await apiController.getTvl()).toBe(1); | ||
it("should return 50", async () => { | ||
jest.spyOn(evmProvider, "getTvl").mockResolvedValue(50); | ||
expect(await apiController.getTvl()).toBe(50); | ||
}); | ||
}); | ||
}); |
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 |
---|---|---|
@@ -1,9 +1,13 @@ | ||
{ | ||
"moduleFileExtensions": ["js", "json", "ts"], | ||
"rootDir": ".", | ||
"testEnvironment": "node", | ||
"testRegex": ".e2e-spec.ts$", | ||
"transform": { | ||
"^.+\\.(t|j)s$": "ts-jest" | ||
} | ||
"moduleFileExtensions": ["js", "json", "ts"], | ||
"rootDir": "../../..", | ||
"testEnvironment": "node", | ||
"testRegex": ".e2e-spec.ts$", | ||
"roots": ["<rootDir>/apps/"], | ||
"transform": { | ||
"^.+\\.(t|j)s$": "ts-jest" | ||
}, | ||
"moduleNameMapper": { | ||
"^@packages/providers(|/.*)$": "<rootDir>/libs/providers/src/$1" | ||
} | ||
} |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.