Merge pull request #1 from yunglocokid/with-jest

feature: added jest
This commit is contained in:
Dmitriy Bratchikov
2024-05-27 16:53:25 +07:00
committed by GitHub
6 changed files with 103 additions and 44 deletions
+24
View File
@@ -0,0 +1,24 @@
import type { Config } from "jest"
import nextJest from "next/jest.js"
const createJestConfig = nextJest({
dir: "./",
})
const config: Config = {
coverageProvider: "v8",
testEnvironment: "jsdom",
setupFilesAfterEnv: ["<rootDir>/jest.setup.ts"],
moduleNameMapper: {
"@app/(.*)$": "<rootDir>/src/app/$1",
"@entities/(.*)$": "<rootDir>/src/entities/$1",
"@features/(.*)$": "<rootDir>/src/features/$1",
"@pagesLayer/(.*)$": "<rootDir>/src/pagesLayer/$1",
"@shared/(.*)$": "<rootDir>/src/shared/$1",
"@widgets/(.*)$": "<rootDir>/src/widgets/$1",
"@/(.*)$": "<rootDir>/src/$1",
},
}
export default createJestConfig(config)
+1
View File
@@ -0,0 +1 @@
import "@testing-library/jest-dom"
+50 -42
View File
@@ -1,44 +1,52 @@
{ {
"name": "fsd-nest-template", "name": "fsd-nest-template",
"description": "Pure Next.js FSD template with stylelint, prettier and eslint", "description": "Pure Next.js FSD template with stylelint, prettier and eslint",
"author": { "author": {
"name": "@yunglocokid (Dmitriy Bratchikov)", "name": "@yunglocokid (Dmitriy Bratchikov)",
"url": "https://github.com/yunglocokid" "url": "https://github.com/yunglocokid"
}, },
"version": "0.1.0", "version": "0.1.0",
"private": true, "private": true,
"scripts": { "scripts": {
"dev": "next dev", "dev": "next dev",
"build": "next build", "build": "next build",
"start": "next start", "start": "next start",
"lint": "next lint", "lint": "next lint",
"lint:prettier": "prettier . --write" "lint:prettier": "prettier . --write",
}, "test": "jest",
"dependencies": { "test:watch": "jest --watch"
"next": "14.2.3", },
"normalize.css": "^8.0.1", "dependencies": {
"react": "^18", "next": "14.2.3",
"react-dom": "^18" "normalize.css": "^8.0.1",
}, "react": "^18",
"devDependencies": { "react-dom": "^18"
"@ianvs/prettier-plugin-sort-imports": "^4.2.1", },
"@types/node": "^20", "devDependencies": {
"@types/react": "^18", "@ianvs/prettier-plugin-sort-imports": "^4.2.1",
"@types/react-dom": "^18", "@testing-library/jest-dom": "^6.4.5",
"eslint": "^8", "@testing-library/react": "^15.0.7",
"eslint-config-next": "14.2.3", "@types/jest": "^29.5.12",
"eslint-import-resolver-typescript": "^3.6.1", "@types/node": "^20",
"eslint-plugin-boundaries": "^4.2.1", "@types/react": "^18",
"eslint-plugin-react-hooks": "^4.6.2", "@types/react-dom": "^18",
"eslint-plugin-react-refresh": "^0.4.7", "eslint": "^8",
"prettier": "^3.2.5", "eslint-config-next": "14.2.3",
"sass": "^1.77.1", "eslint-import-resolver-typescript": "^3.6.1",
"stylelint": "^16.5.0", "eslint-plugin-boundaries": "^4.2.1",
"stylelint-config-standard": "^36.0.0", "eslint-plugin-react-hooks": "^4.6.2",
"stylelint-config-standard-scss": "^13.1.0", "eslint-plugin-react-refresh": "^0.4.7",
"stylelint-order": "^6.0.4", "jest": "^29.7.0",
"stylelint-order-config-standard": "^0.1.3", "jest-environment-jsdom": "^29.7.0",
"typescript": "^5", "prettier": "^3.2.5",
"typescript-eslint": "^7.10.0" "sass": "^1.77.1",
} "stylelint": "^16.5.0",
"stylelint-config-standard": "^36.0.0",
"stylelint-config-standard-scss": "^13.1.0",
"stylelint-order": "^6.0.4",
"stylelint-order-config-standard": "^0.1.3",
"ts-node": "^10.9.2",
"typescript": "^5",
"typescript-eslint": "^7.10.0"
}
} }
@@ -35,6 +35,10 @@
font-size: 1vw; font-size: 1vw;
} }
.testHint {
margin: 0 30px;
}
.link { .link {
transition: 0.3s; transition: 0.3s;
animation: shine 4s linear infinite; animation: shine 4s linear infinite;
@@ -0,0 +1,19 @@
import "@testing-library/jest-dom"
import { render, screen } from "@testing-library/react"
import HomePage from "./HomePage"
describe("Page", () => {
test("renders a yunglocokid", () => {
render(<HomePage />)
const yunglocokid: HTMLElement = screen.getByText("yunglocokid")
expect(yunglocokid).toBeInTheDocument()
})
test("renders a hint", () => {
render(<HomePage />)
screen.debug()
const hint: HTMLElement = screen.getByTestId("hint-code")
expect(hint).toBeInTheDocument()
})
})
+5 -2
View File
@@ -15,9 +15,12 @@ const HomePage = () => {
yunglocokid yunglocokid
</Link> </Link>
</p> </p>
<pre className={cls.hint}> <pre className={cls.hint} data-testid="hint-code">
You can edit <span className={cls.path}>src/pagesLayer/HomePage</span>{" "} You can edit <span className={cls.path}>src/pagesLayer/HomePage</span>{" "}
to start {"<3"}! to start {"<3"}!<br />
<small className={cls.testHint}>
You can also test your application using Jest :D. Try it!
</small>
</pre> </pre>
</div> </div>
) )