-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: default Jest testing configuration (#19)
* feat: default Jest testing configuration * Update .github/workflows/jest-testing.yml * chore: moved jest config from js to ts * chore: removed unused check to trigger Jest Action --------- Co-authored-by: アレクサンダー.eth <4975670+pavlovcik@users.noreply.github.com>
- Loading branch information
Showing
11 changed files
with
2,080 additions
and
21 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
name: Run Jest testing suite | ||
on: | ||
workflow_dispatch: | ||
push: | ||
branches: | ||
- development | ||
pull_request: | ||
|
||
env: | ||
NODE_ENV: "test" | ||
|
||
jobs: | ||
testing: | ||
permissions: write-all | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/setup-node@v4 | ||
with: | ||
node-version: '20.10.0' | ||
- uses: actions/checkout@master | ||
with: | ||
fetch-depth: 0 | ||
- name: Build & Run test suite | ||
run: | | ||
yarn | ||
yarn test | tee ./coverage.txt && exit ${PIPESTATUS[0]} | ||
- name: Jest Coverage Comment | ||
# Ensures this step is run even on previous step failure (e.g. test failed) | ||
if: always() | ||
uses: MishaKav/jest-coverage-comment@main | ||
with: | ||
coverage-summary-path: coverage/coverage-summary.json | ||
junitxml-path: junit.xml | ||
junitxml-title: JUnit | ||
coverage-path: ./coverage.txt |
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 |
---|---|---|
|
@@ -7,4 +7,6 @@ node_modules | |
.pnp.cjs | ||
.pnp.loader.mjs | ||
.env | ||
static/dist | ||
static/dist | ||
coverage | ||
junit.xml |
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,12 @@ | ||
import { JestConfigWithTsJest } from "ts-jest"; | ||
|
||
module.exports = { | ||
preset: "ts-jest", | ||
testEnvironment: "node", | ||
roots: ["./tests"], | ||
coveragePathIgnorePatterns: ["node_modules", "mocks"], | ||
collectCoverage: true, | ||
coverageReporters: ["json", "lcov", "text", "clover", "json-summary"], | ||
reporters: ["default", "jest-junit"], | ||
coverageDirectory: "coverage", | ||
} as JestConfigWithTsJest; |
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,11 @@ | ||
import { factory, primaryKey } from "@mswjs/data"; | ||
|
||
/** | ||
* Creates an object that can be used as a db to persist data within tests | ||
*/ | ||
export const db = factory({ | ||
users: { | ||
id: primaryKey(Number), | ||
name: String, | ||
}, | ||
}); |
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,11 @@ | ||
import { http, HttpResponse } from "msw"; | ||
import { db } from "./db"; | ||
|
||
/** | ||
* Intercepts the routes and returns a custom payload | ||
*/ | ||
export const handlers = [ | ||
http.get("https://api.ubiquity.com/users", () => { | ||
return HttpResponse.json(db.users.getAll()); | ||
}), | ||
]; |
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,4 @@ | ||
import { setupServer } from "msw/node"; | ||
import { handlers } from "./handlers"; | ||
|
||
export const server = setupServer(...handlers); |
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,10 @@ | ||
[ | ||
{ | ||
"id": 1, | ||
"name": "user1" | ||
}, | ||
{ | ||
"id": 2, | ||
"name": "user2" | ||
} | ||
] |
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,21 @@ | ||
import { db } from "./__mocks__/db"; | ||
import { server } from "./__mocks__/node"; | ||
import usersGet from "./__mocks__/users-get.json"; | ||
|
||
beforeAll(() => server.listen()); | ||
afterEach(() => server.resetHandlers()); | ||
afterAll(() => server.close()); | ||
|
||
describe("User tests", () => { | ||
beforeEach(() => { | ||
for (const item of usersGet) { | ||
db.users.create(item); | ||
} | ||
}); | ||
|
||
it("Should fetch all the users", async () => { | ||
const res = await fetch("https://api.ubiquity.com/users"); | ||
const data = await res.json(); | ||
expect(data).toMatchObject(usersGet); | ||
}); | ||
}); |
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
Oops, something went wrong.
f0c06fb
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
JUnit
Coverage Report (0%)