Skip to content

Commit f6bd02b

Browse files
committed
Add test & fix prettier plugins
1 parent d03e9b2 commit f6bd02b

File tree

6 files changed

+1866
-51
lines changed

6 files changed

+1866
-51
lines changed

.prettierrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"plugins": [],
2+
"plugins": ["@trivago/prettier-plugin-sort-imports", "prettier-plugin-tailwindcss"],
33
"arrowParens": "avoid",
44
"semi": false,
55
"singleQuote": true,

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ yarn clean
2828

2929
# reinstall
3030
yarn reinstall
31+
32+
# run test in watch mode
33+
yarn test
3134
```
3235

3336
For an example of an api request, let's make a `GET` to `http://localhost:3001/api/hello`.

jest.config.mjs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import nextJest from 'next/jest.js'
2+
3+
const createJestConfig = nextJest({
4+
// Provide the path to your Next.js app to load next.config.js and .env files in your test environment
5+
dir: './'
6+
})
7+
8+
// Add any custom config to be passed to Jest
9+
/** @type {import('jest').Config} */
10+
const config = {
11+
// Add more setup options before each test is run
12+
setupFilesAfterEnv: ['<rootDir>/jest.setup.ts'],
13+
testEnvironment: 'jest-environment-jsdom'
14+
}
15+
16+
// createJestConfig is exported this way to ensure that next/jest can load the Next.js config which is async
17+
export default createJestConfig(config)

jest.setup.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// Learn more: https://github.com/testing-library/jest-dom
2+
import '@testing-library/jest-dom'

package.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
{
22
"name": "nextjs-tailwind-starter",
3-
"version": "1.0.0",
3+
"version": "1.0.1",
44
"author": "Anh-Thi Dinh",
55
"private": true,
66
"scripts": {
77
"dev": "next dev",
88
"build": "next build",
99
"start": "next start",
10+
"test": "jest --watch",
1011
"lint": "next lint",
1112
"check": "yarn run prettier && yarn run build",
1213
"prettier": "prettier --write \"**/*.{tsx,ts,css,scss}\"",
@@ -28,14 +29,19 @@
2829
},
2930
"devDependencies": {
3031
"@tailwindcss/typography": "^0.5.10",
32+
"@testing-library/jest-dom": "^6.1.4",
33+
"@testing-library/react": "^14.1.0",
3134
"@trivago/prettier-plugin-sort-imports": "^4.3.0",
35+
"@types/jest": "^29.5.8",
3236
"@typescript-eslint/eslint-plugin": "^6.10.0",
3337
"@typescript-eslint/parser": "^6.10.0",
3438
"eslint-config-prettier": "^9.0.0",
3539
"eslint-config-react-app": "^7.0.1",
3640
"eslint-plugin-prettier": "^5.0.1",
3741
"eslint-plugin-react": "^7.33.2",
3842
"eslint-plugin-tailwindcss": "^3.13.0",
43+
"jest": "^29.7.0",
44+
"jest-environment-jsdom": "^29.7.0",
3945
"postcss": "8.4.31",
4046
"prettier": "^3.0.3",
4147
"prettier-plugin-tailwindcss": "^0.5.7",

0 commit comments

Comments
 (0)