├── .eslintrc.js ├── .github └── workflows │ └── bruno.yml ├── .gitignore ├── .husky ├── .gitignore └── pre-commit ├── .prettierrc.json ├── README.md ├── jest.config.js ├── next-env.d.ts ├── next.config.js ├── package-lock.json ├── package.json ├── public ├── favicon.ico └── vercel.svg ├── src ├── components │ ├── Hello.spec.tsx │ ├── Hello.tsx │ ├── sum.spec.ts │ └── sum.ts ├── jest.setup.ts └── pages │ ├── _app.tsx │ ├── api │ └── hello.ts │ └── index.tsx ├── tsconfig.jest.json └── tsconfig.json /.eslintrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | extends: [ 3 | 'eslint:recommended', 4 | 'plugin:react/recommended', 5 | 'plugin:@typescript-eslint/recommended', 6 | 'plugin:@typescript-eslint/recommended-requiring-type-checking', 7 | 'plugin:jest/recommended', 8 | 'plugin:jest/style', 9 | 'plugin:testing-library/react', 10 | 'next', 11 | 'next/core-web-vitals', 12 | ], 13 | parser: '@typescript-eslint/parser', 14 | parserOptions: { 15 | project: './tsconfig.json', 16 | ecmaFeatures: { 17 | jsx: true, 18 | }, 19 | ecmaVersion: 12, 20 | sourceType: 'module', 21 | }, 22 | rules: { 23 | '@typescript-eslint/explicit-module-boundary-types': 'off', 24 | }, 25 | }; 26 | -------------------------------------------------------------------------------- /.github/workflows/bruno.yml: -------------------------------------------------------------------------------- 1 | # This workflow will do a clean install of node dependencies, cache/restore them, build the source code and run tests across different versions of node 2 | # For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions 3 | 4 | name: Node.js CI 5 | 6 | on: 7 | push: 8 | branches: [main] 9 | pull_request: 10 | branches: '*' 11 | 12 | jobs: 13 | build: 14 | runs-on: ${{matrix.os}} 15 | 16 | strategy: 17 | matrix: 18 | node-version: [12.x, 14.x, 16.x] 19 | os: [ubuntu-latest, windows-latest, macos-latest] 20 | # See supported Node.js release schedule at https://nodejs.org/en/about/releases/ 21 | 22 | steps: 23 | - uses: actions/checkout@v2 24 | - name: Use Node.js ${{ matrix.node-version }} 25 | uses: actions/setup-node@v2 26 | with: 27 | node-version: ${{ matrix.node-version }} 28 | cache: 'npm' 29 | - run: npm ci 30 | - run: npm run lint 31 | - run: npm run test:ci 32 | - run: npm run build 33 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files. 2 | 3 | # dependencies 4 | /node_modules 5 | /.pnp 6 | .pnp.js 7 | 8 | # testing 9 | /coverage 10 | 11 | # next.js 12 | /.next/ 13 | /out/ 14 | 15 | # production 16 | /build 17 | 18 | # misc 19 | .DS_Store 20 | *.pem 21 | 22 | # debug 23 | npm-debug.log* 24 | yarn-debug.log* 25 | yarn-error.log* 26 | 27 | # local env files 28 | .env.local 29 | .env.development.local 30 | .env.test.local 31 | .env.production.local 32 | 33 | # vercel 34 | .vercel 35 | 36 | # eslint cache 37 | .eslintcache -------------------------------------------------------------------------------- /.husky/.gitignore: -------------------------------------------------------------------------------- 1 | _ 2 | -------------------------------------------------------------------------------- /.husky/pre-commit: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | . "$(dirname "$0")/_/husky.sh" 3 | 4 | npm run lint-staged 5 | -------------------------------------------------------------------------------- /.prettierrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "trailingComma": "es5", 3 | "tabWidth": 2, 4 | "singleQuote": true 5 | } 6 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | This is a [Next.js](https://nextjs.org/) project bootstrapped with [`create-next-app`](https://github.com/vercel/next.js/tree/canary/packages/create-next-app). 2 | 3 | ## Getting Started 4 | 5 | First, run the development server: 6 | 7 | ```bash 8 | npm run dev 9 | # or 10 | yarn dev 11 | ``` 12 | 13 | Open [http://localhost:3000](http://localhost:3000) with your browser to see the result. 14 | 15 | You can start editing the page by modifying `pages/index.tsx`. The page auto-updates as you edit the file. 16 | 17 | [API routes](https://nextjs.org/docs/api-routes/introduction) can be accessed on [http://localhost:3000/api/hello](http://localhost:3000/api/hello). This endpoint can be edited in `pages/api/hello.tsx`. 18 | 19 | The `pages/api` directory is mapped to `/api/*`. Files in this directory are treated as [API routes](https://nextjs.org/docs/api-routes/introduction) instead of React pages. 20 | 21 | ## Learn More 22 | 23 | To learn more about Next.js, take a look at the following resources: 24 | 25 | - [Next.js Documentation](https://nextjs.org/docs) - learn about Next.js features and API. 26 | - [Learn Next.js](https://nextjs.org/learn) - an interactive Next.js tutorial. 27 | 28 | You can check out [the Next.js GitHub repository](https://github.com/vercel/next.js/) - your feedback and contributions are welcome! 29 | 30 | ## Deploy on Vercel 31 | 32 | The easiest way to deploy your Next.js app is to use the [Vercel Platform](https://vercel.com/new?utm_medium=default-template&filter=next.js&utm_source=create-next-app&utm_campaign=create-next-app-readme) from the creators of Next.js. 33 | 34 | Check out our [Next.js deployment documentation](https://nextjs.org/docs/deployment) for more details. 35 | -------------------------------------------------------------------------------- /jest.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | preset: 'ts-jest', 3 | testEnvironment: 'jsdom', 4 | globals: { 5 | 'ts-jest': { 6 | tsconfig: './tsconfig.jest.json', 7 | }, 8 | }, 9 | setupFilesAfterEnv: ['./src/jest.setup.ts'], 10 | coverageThreshold: { 11 | global: { 12 | branches: 100, 13 | functions: 100, 14 | lines: 100, 15 | statements: 100, 16 | }, 17 | }, 18 | }; 19 | -------------------------------------------------------------------------------- /next-env.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | /// 3 | /// 4 | -------------------------------------------------------------------------------- /next.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | reactStrictMode: true, 3 | }; 4 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "youtube-react-testing-video2-config-jest-react-testing-library", 3 | "version": "0.1.0", 4 | "private": true, 5 | "scripts": { 6 | "dev": "next dev", 7 | "build": "next build", 8 | "start": "next start", 9 | "lint": "next lint --dir src", 10 | "test": "jest", 11 | "test:ci": "jest --coverage --silent --ci", 12 | "prepare": "husky install", 13 | "prettier": "prettier {*,src/*,src/**/*} --write --ignore-unknown", 14 | "lint-staged": "lint-staged" 15 | }, 16 | "dependencies": { 17 | "next": "11.0.1", 18 | "react": "17.0.2", 19 | "react-dom": "17.0.2" 20 | }, 21 | "devDependencies": { 22 | "@testing-library/dom": "8.1.0", 23 | "@testing-library/jest-dom": "5.14.1", 24 | "@testing-library/react": "12.0.0", 25 | "@testing-library/user-event": "13.2.0", 26 | "@types/jest": "26.0.24", 27 | "@types/react": "17.0.14", 28 | "@typescript-eslint/eslint-plugin": "4.28.4", 29 | "@typescript-eslint/parser": "4.28.4", 30 | "eslint": "7.31.0", 31 | "eslint-config-next": "11.0.1", 32 | "eslint-plugin-jest": "24.3.6", 33 | "eslint-plugin-react": "7.24.0", 34 | "eslint-plugin-testing-library": "4.9.1", 35 | "husky": "7.0.1", 36 | "jest": "27.0.6", 37 | "lint-staged": "11.0.1", 38 | "prettier": "2.3.2", 39 | "ts-jest": "27.0.3", 40 | "typescript": "4.3.5" 41 | }, 42 | "lint-staged": { 43 | "*.(tsx|ts)": "eslint --cache --fix", 44 | "*": "prettier --write --ignore-unknown" 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bmvantunes/youtube-react-testing-video2-config-jest-react-testing-library/0b8393e914df1a6e36e1f492977bc6e190025592/public/favicon.ico -------------------------------------------------------------------------------- /public/vercel.svg: -------------------------------------------------------------------------------- 1 | 3 | 4 | -------------------------------------------------------------------------------- /src/components/Hello.spec.tsx: -------------------------------------------------------------------------------- 1 | import { render, screen } from '@testing-library/react'; 2 | import React from 'react'; 3 | import { Hello } from './Hello'; 4 | 5 | it('renders "Hello World"', () => { 6 | render(); 7 | const element = screen.getByText(/Hello World/); 8 | expect(element).toBeInTheDocument(); 9 | }); 10 | -------------------------------------------------------------------------------- /src/components/Hello.tsx: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | 3 | export function Hello() { 4 | return
Hello World!
; 5 | } 6 | -------------------------------------------------------------------------------- /src/components/sum.spec.ts: -------------------------------------------------------------------------------- 1 | import { sum } from './sum'; 2 | 3 | it('sum 5 and 2 will return 7', () => { 4 | expect(sum(5, 2)).toBe(7); 5 | }); 6 | -------------------------------------------------------------------------------- /src/components/sum.ts: -------------------------------------------------------------------------------- 1 | export function sum(a: number, b: number) { 2 | return a + b; 3 | } 4 | -------------------------------------------------------------------------------- /src/jest.setup.ts: -------------------------------------------------------------------------------- 1 | import '@testing-library/jest-dom'; 2 | -------------------------------------------------------------------------------- /src/pages/_app.tsx: -------------------------------------------------------------------------------- 1 | import type { AppProps } from 'next/app'; 2 | 3 | export default function MyApp({ Component, pageProps }: AppProps) { 4 | return ; 5 | } 6 | -------------------------------------------------------------------------------- /src/pages/api/hello.ts: -------------------------------------------------------------------------------- 1 | // Next.js API route support: https://nextjs.org/docs/api-routes/introduction 2 | import type { NextApiRequest, NextApiResponse } from 'next'; 3 | 4 | type Data = { 5 | name: string; 6 | }; 7 | 8 | export default function handler( 9 | req: NextApiRequest, 10 | res: NextApiResponse 11 | ) { 12 | res.status(200).json({ name: 'John Doe' }); 13 | } 14 | -------------------------------------------------------------------------------- /src/pages/index.tsx: -------------------------------------------------------------------------------- 1 | export default function Home() { 2 | return
Hello React.js Testing Series Friends!!!
; 3 | } 4 | -------------------------------------------------------------------------------- /tsconfig.jest.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.json", 3 | "compilerOptions": { 4 | "jsx": "react-jsx" 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "es5", 4 | "lib": ["dom", "dom.iterable", "esnext"], 5 | "allowJs": true, 6 | "skipLibCheck": true, 7 | "strict": true, 8 | "forceConsistentCasingInFileNames": true, 9 | "noEmit": true, 10 | "esModuleInterop": true, 11 | "module": "esnext", 12 | "moduleResolution": "node", 13 | "resolveJsonModule": true, 14 | "isolatedModules": true, 15 | "jsx": "preserve" 16 | }, 17 | "include": ["next-env.d.ts", "**/*.ts", "**/*.tsx"], 18 | "exclude": ["node_modules"] 19 | } 20 | --------------------------------------------------------------------------------