Skip to content

Commit e1b82a2

Browse files
Merge pull request #1 from potreco/dev
Added Testing Tools and some fixes. Created the 1.0.0 version
2 parents 04664bf + d82c818 commit e1b82a2

12 files changed

+126
-66
lines changed

.editorconfig

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# EditorConfig is awesome: https://EditorConfig.org
2+
3+
# top-most EditorConfig file
4+
root = true
5+
6+
[*]
7+
indent_style = space
8+
indent_size = 2
9+
end_of_line = lf
10+
charset = utf-8
11+
trim_trailing_whitespace = true
12+
insert_final_newline = true

.eslintignore

+4-1
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,7 @@
33
*.css
44
/node_modules
55
/build
6-
vite.config.ts
6+
vite.config.ts
7+
jest.setup.ts
8+
jest.config.js
9+
/test/__mocks__/fileMock.js

.eslintrc.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
{
22
"env": {
33
"browser": true,
4-
"es2021": true
4+
"es2021": true,
5+
"jest": true
56
},
67
"extends": [
78
"plugin:react/recommended",

README.md

+29-55
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,30 @@
11
# ViteRC ❤️‍🔥
22

3-
A modern minimal Vite + React + TypeScript template with pre-configured ESLint (with Airbnb JS/React rules), Prettier and Git hooks with Husky out of the box 📦
3+
A modern minimal Vite + React + TypeScript template with pre-configured ESLint (with Airbnb JS/React rules), Prettier, Testing with Jest and Git hooks with Husky out of the box 📦
44

55
![Vite](https://img.shields.io/badge/Vite-B73BFE?style=for-the-badge&logo=vite&logoColor=FFD62E)
66
![React](https://img.shields.io/badge/React-20232A?style=for-the-badge&logo=react&logoColor=61DAFB)
77
![TypeScript](https://img.shields.io/badge/TypeScript-007ACC?style=for-the-badge&logo=typescript&logoColor=white)
88
![ESLint](https://img.shields.io/badge/eslint-3A33D1?style=for-the-badge&logo=eslint&logoColor=white)
99
![Prettier](https://img.shields.io/badge/prettier-1A2C34?style=for-the-badge&logo=prettier&logoColor=F7BA3E)
10+
![Jest](https://img.shields.io/badge/jest-C21325?style=for-the-badge&logo=jest&logoColor=white)
11+
![Testing Library](https://img.shields.io/badge/testing%20library-E33332?style=for-the-badge&logo=testing-library&logoColor=white)
1012

11-
![Screenshot](https://i.imgur.com/nqqArrR.png)
13+
![Screenshot](https://i.imgur.com/4dpYsyG.png)
1214

1315
## Features
1416

15-
- React
16-
- Typescript
17-
- Eslint (Airbnb)
18-
- Prettier
19-
- Husky
17+
- ⚡️ [Vite](https://vitejs.dev/) - Next Generation Frontend Tooling
18+
- ⚛️ [React 18](https://reactjs.org/) - A JavaScript library for building user interfaces
19+
- 💎 [TypeScript](https://www.typescriptlang.org/) - Why not?!
20+
- 🔨 [EsLint](https://eslint.org/) - Pluggable JavaScript linter
21+
- 🌀 [Prettier](https://prettier.io) - Opinionated Code Formatter
22+
- 🐺 [Husky](https://github.com/typicode/husky) - Native Git hooks
23+
- ⚙️ [Jest](https://jestjs.io/) - Testing libraries
24+
25+
## Why
26+
27+
This template arose out of a need to unite all the above libraries, which were not found in the existing Vite templates. This template has an active contributors that will update everything on this template as needed
2028

2129
## Usage
2230

@@ -35,61 +43,27 @@ yarn dev
3543

3644
## Available commands
3745

38-
Run in development mode
39-
40-
```bash
41-
yarn dev
42-
```
43-
44-
Create production build
45-
46-
```bash
47-
yarn build
48-
```
49-
50-
Serve production build locally
51-
52-
```bash
53-
yarn preview
54-
```
55-
56-
Install Husky
57-
58-
```bash
59-
yarn prepare
60-
```
61-
62-
Run ESLint linting
63-
64-
```bash
65-
yarn lint
66-
```
46+
<p>In this project, you can run the following scripts:</p>
6747

68-
Run Prettier formatting
69-
70-
```bash
71-
yarn format
72-
```
73-
74-
Run TypeScript compiling
75-
76-
```bash
77-
yarn compile
78-
```
48+
| Script | Description |
49+
| ------------- | --------------------------------------------------------------------------- |
50+
| yarn dev | Runs the app in the development mode. |
51+
| yarn build | Builds the app for production to the `dist` folder. |
52+
| yarn preview | Builds the app for production to the `dist` folder, and run locally server. |
53+
| yarn lint | Runs the Eslint and show code problems |
54+
| yarn lint:fix | Runs the Eslint and fix the code problems |
55+
| yarn format | Runs the Prettier and fix code style |
56+
| yarn compile | Runs the TS Compiling |
57+
| yarn test | Run the app tests. |
7958

8059
## TODO
8160

8261
- [x] Eslint
8362
- [x] Prettier
8463
- [x] Husky
85-
- [] Testing Tools
86-
87-
## Resources
88-
89-
- [Vite](https://github.com/vitejs/vite)
90-
- [Airbnb JS Style Guide](https://github.com/airbnb/javascript)
91-
- [Airbnb React Style Guide](https://github.com/airbnb/javascript/tree/master/react)
92-
- [Husky](https://github.com/typicode/husky)
64+
- [x] Testing Tools
65+
- [ ] Absolute imports
66+
- [ ] Commit linting
9367

9468
## License
9569

index.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<meta charset="UTF-8" />
55
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
66
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
7-
<title>ViterRC</title>
7+
<title>ViteRC</title>
88
</head>
99
<body>
1010
<div id="root"></div>

jest.config.js

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
export default {
2+
testEnvironment: "jsdom",
3+
transform: {
4+
"^.+\\.tsx?$": "ts-jest"
5+
},
6+
moduleNameMapper: {
7+
'\\.(gif|ttf|eot|svg|png)$': '<rootDir>/test/__mocks__/fileMock.js',
8+
'\\.(css|less|sass|scss)$': 'identity-obj-proxy',
9+
},
10+
setupFilesAfterEnv: ['<rootDir>/jest.setup.ts'],
11+
}

jest.setup.ts

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import '@testing-library/jest-dom/extend-expect';

package.json

+14-5
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,34 @@
11
{
22
"name": "viterc",
33
"private": false,
4-
"version": "0.0.0",
5-
"description": "A modern minimal Vite + React + TypeScript template with pre-configured ESLint (with Airbnb JS/React rules), Prettier out of the box 📦",
4+
"version": "1.0.0",
5+
"description": "A modern minimal Vite + React + TypeScript template with pre-configured ESLint (with Airbnb JS/React rules), Prettier, Testing with Jest and Git hooks with Husky out of the box 📦",
66
"license": "MIT",
77
"author": {
88
"name": "Patrick Jean Meurer",
99
"email": "[email protected]",
1010
"url": "https://github.com/potreco"
1111
},
12-
"type": "module",
1312
"scripts": {
13+
"postinstall": "husky install",
1414
"dev": "vite",
1515
"build": "tsc && vite build",
1616
"preview": "vite preview",
17-
"prepare": "husky install",
1817
"lint": "eslint src --ext .js,.jsx,.ts,.tsx",
1918
"lint:fix": "eslint src --ext .js,.jsx,.ts,.tsx --fix",
2019
"format": "prettier \"src/**/*.{js,jsx,ts,tsx,css,scss}\" --write",
21-
"compile": "tsc"
20+
"compile": "tsc",
21+
"test": "jest"
2222
},
2323
"dependencies": {
2424
"react": "^18.2.0",
2525
"react-dom": "^18.2.0"
2626
},
2727
"devDependencies": {
28+
"@testing-library/jest-dom": "^5.16.4",
29+
"@testing-library/react": "^13.3.0",
30+
"@testing-library/user-event": "^14.2.5",
31+
"@types/jest": "^28.1.5",
2832
"@types/react": "^18.0.15",
2933
"@types/react-dom": "^18.0.6",
3034
"@typescript-eslint/eslint-plugin": "^5.30.6",
@@ -40,7 +44,12 @@
4044
"eslint-plugin-react": "7.28.0",
4145
"eslint-plugin-react-hooks": "4.3.0",
4246
"husky": "^8.0.1",
47+
"identity-obj-proxy": "^3.0.0",
48+
"jest": "^28.1.3",
49+
"jest-environment-jsdom": "^28.1.3",
4350
"prettier": "^2.7.1",
51+
"ts-jest": "^28.0.6",
52+
"ts-node": "^10.9.1",
4453
"typescript": "^4.6.4",
4554
"vite": "^3.0.0"
4655
}
File renamed without changes.

src/App.test.tsx

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import { render, screen } from '@testing-library/react';
2+
import user from '@testing-library/user-event';
3+
import App from './App';
4+
5+
describe('Render the app correctly', () => {
6+
test('should render the title', async () => {
7+
render(<App />);
8+
9+
const header = await screen.findByText(/ViteRC/);
10+
11+
expect(header).toBeInTheDocument();
12+
});
13+
14+
test('should render the button and counter', async () => {
15+
render(<App />);
16+
17+
const button = await screen.findByRole('button');
18+
19+
expect(button).toBeInTheDocument();
20+
expect(button.innerHTML).toBe('count is 0');
21+
22+
await user.click(button);
23+
await user.click(button);
24+
await user.click(button);
25+
26+
expect(button.innerHTML).toBe('count is 3');
27+
});
28+
test('should render the `read the docs` row', async () => {
29+
render(<App />);
30+
31+
const readTheDocs = await screen.findByTestId('read-the-docs');
32+
33+
expect(readTheDocs).toBeInTheDocument();
34+
});
35+
});

src/App.tsx

+16-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { useState } from 'react';
2-
import reactLogo from './assets/react.svg';
2+
import reactLogo from '../public/react.svg';
33
import './App.css';
44

55
function App() {
@@ -11,13 +11,13 @@ function App() {
1111
<img src="/vite.svg" className="logo" alt="Vite logo" />
1212
<img src={reactLogo} className="logo react" alt="React logo" />
1313
</div>
14-
<h2>Vite + React + TypeScript + Eslint (Airbnb) + Eslint = ViteRC❤️‍🔥</h2>
14+
<h2>Vite + React + TypeScript + Eslint (Airbnb) + Eslint + Jest + Testing Library = ViteRC❤️‍🔥</h2>
1515
<div className="card">
1616
<button type="button" onClick={() => setCount(count + 1)}>
1717
count is {count}
1818
</button>
1919
</div>
20-
<p className="read-the-docs">
20+
<p className="read-the-docs" data-testId="read-the-docs">
2121
<a className="App-link" href="https://vitejs.dev/guide/features.html" target="_blank" rel="noopener noreferrer">
2222
Vite Docs
2323
</a>
@@ -47,6 +47,19 @@ function App() {
4747
Airbnb React Style Guide
4848
</a>
4949
{' | '}
50+
<a
51+
className="App-link"
52+
href="https://jestjs.io/pt-BR/docs/getting-started"
53+
target="_blank"
54+
rel="noopener noreferrer"
55+
>
56+
Jest
57+
</a>
58+
{' | '}
59+
<a className="App-link" href="https://testing-library.com" target="_blank" rel="noopener noreferrer">
60+
Testing Library
61+
</a>
62+
{' | '}
5063
<a className="App-link" href="https://github.com/potreco/viterc" target="_blank" rel="noopener noreferrer">
5164
Template repository
5265
</a>

test/__mocks__/fileMock.js

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = 'test-file-stub';

0 commit comments

Comments
 (0)