Skip to content

Commit 80b2336

Browse files
committed
install and config test
1 parent 76f43d7 commit 80b2336

File tree

11 files changed

+5993
-1866
lines changed

11 files changed

+5993
-1866
lines changed

package-lock.json

+5,862-1,852
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+6-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"build": "tsc && vite build",
99
"preview": "vite preview",
1010
"lint": "eslint --ext .js,.ts,tsx .",
11+
"test": "vitest",
1112
"lint-fix": "eslint --fix --ext .js,.ts,.jsx,.tsx .",
1213
"format": "prettier --ignore-path .gitignore --write \"**/*.+(js|ts|tsx|json)\""
1314
},
@@ -26,6 +27,8 @@
2627
"styled-components": "^5.3.6"
2728
},
2829
"devDependencies": {
30+
"@testing-library/jest-dom": "^5.16.5",
31+
"@testing-library/react": "^13.4.0",
2932
"@types/lodash.get": "^4.4.7",
3033
"@types/react": "^18.0.24",
3134
"@types/react-router-dom": "^5.3.3",
@@ -42,8 +45,10 @@
4245
"eslint-plugin-prettier": "^4.2.1",
4346
"eslint-plugin-react": "^7.28.0",
4447
"eslint-plugin-react-hooks": "^4.3.0",
48+
"jsdom": "^21.1.0",
4549
"prettier": "^2.8.3",
4650
"typescript": "^4.6.4",
47-
"vite": "^3.2.3"
51+
"vite": "^3.2.3",
52+
"vitest": "^0.28.3"
4853
}
4954
}

src/App.tsx

+16-10
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,30 @@
22
import { BrowserRouter, Routes, Route } from 'react-router-dom';
33
import GlobalStyle from './styles/globalStyles';
44

5-
import { Admin, Home, Signin, Signup } from './components/Pages';
5+
import { Admin, Home, Signin, Signup, NotFound } from './components/Pages';
66

77
function App() {
88
return (
99
<>
1010
<GlobalStyle />
1111
<div className="App">
12-
<BrowserRouter>
13-
<Routes>
14-
<Route index element={<Home />} />
15-
<Route path="signin" element={<Signin />} />
16-
<Route path="signup" element={<Signup />} />
17-
<Route path="admin" element={<Admin />} />
18-
</Routes>
19-
</BrowserRouter>
12+
<Routes>
13+
<Route index element={<Home />} />
14+
<Route path="signin" element={<Signin />} />
15+
<Route path="signup" element={<Signup />} />
16+
<Route path="admin" element={<Admin />} />
17+
<Route path="*" element={<NotFound />} />
18+
</Routes>
2019
</div>
2120
</>
2221
);
2322
}
2423

25-
export default App;
24+
const WrapperApp = () => {
25+
return (
26+
<BrowserRouter>
27+
<App />
28+
</BrowserRouter>
29+
);
30+
};
31+
export default WrapperApp;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
// Vitest Snapshot v1
2+
3+
exports[`App > Render 1`] = `
4+
{
5+
"asFragment": [Function],
6+
"baseElement": <body>
7+
<div>
8+
<p
9+
class="sc-bcXHqe fVoLdb"
10+
>
11+
text
12+
</p>
13+
</div>
14+
</body>,
15+
"container": <div>
16+
<p
17+
class="sc-bcXHqe fVoLdb"
18+
>
19+
text
20+
</p>
21+
</div>,
22+
"debug": [Function],
23+
"findAllByAltText": [Function],
24+
"findAllByDisplayValue": [Function],
25+
"findAllByLabelText": [Function],
26+
"findAllByPlaceholderText": [Function],
27+
"findAllByRole": [Function],
28+
"findAllByTestId": [Function],
29+
"findAllByText": [Function],
30+
"findAllByTitle": [Function],
31+
"findByAltText": [Function],
32+
"findByDisplayValue": [Function],
33+
"findByLabelText": [Function],
34+
"findByPlaceholderText": [Function],
35+
"findByRole": [Function],
36+
"findByTestId": [Function],
37+
"findByText": [Function],
38+
"findByTitle": [Function],
39+
"getAllByAltText": [Function],
40+
"getAllByDisplayValue": [Function],
41+
"getAllByLabelText": [Function],
42+
"getAllByPlaceholderText": [Function],
43+
"getAllByRole": [Function],
44+
"getAllByTestId": [Function],
45+
"getAllByText": [Function],
46+
"getAllByTitle": [Function],
47+
"getByAltText": [Function],
48+
"getByDisplayValue": [Function],
49+
"getByLabelText": [Function],
50+
"getByPlaceholderText": [Function],
51+
"getByRole": [Function],
52+
"getByTestId": [Function],
53+
"getByText": [Function],
54+
"getByTitle": [Function],
55+
"queryAllByAltText": [Function],
56+
"queryAllByDisplayValue": [Function],
57+
"queryAllByLabelText": [Function],
58+
"queryAllByPlaceholderText": [Function],
59+
"queryAllByRole": [Function],
60+
"queryAllByTestId": [Function],
61+
"queryAllByText": [Function],
62+
"queryAllByTitle": [Function],
63+
"queryByAltText": [Function],
64+
"queryByDisplayValue": [Function],
65+
"queryByLabelText": [Function],
66+
"queryByPlaceholderText": [Function],
67+
"queryByRole": [Function],
68+
"queryByTestId": [Function],
69+
"queryByText": [Function],
70+
"queryByTitle": [Function],
71+
"rerender": [Function],
72+
"unmount": [Function],
73+
}
74+
`;
+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import React from 'react';
2+
import { describe, it } from 'vitest';
3+
import { render } from '@testing-library/react';
4+
import Text from './Text';
5+
6+
describe('App', () => {
7+
it('Render', () => {
8+
const app = render(<Text>text</Text>);
9+
expect(app).toMatchSnapshot();
10+
});
11+
});

src/components/Pages/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ export { default as Home } from './home';
22
export { default as Signin } from './signin';
33
export { default as Signup } from './signup';
44
export { default as Admin } from './admin';
5+
export { default as NotFound } from './notFound';
+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
const NotFound = () => {
2+
return <h1> Not Found </h1>;
3+
};
4+
5+
export default NotFound;

src/main.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import React from 'react';
22
import ReactDOM from 'react-dom/client';
3-
import App from './App';
3+
import WrapperApp from './App';
44
import './fontawesome';
55

66
ReactDOM.createRoot(document.getElementById('root') as HTMLElement).render(
77
<React.StrictMode>
8-
<App />
8+
<WrapperApp />
99
</React.StrictMode>
1010
);

src/setupTest.ts

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/* eslint-disable import/no-extraneous-dependencies */
2+
import matchers from '@testing-library/jest-dom/matchers';
3+
import { expect } from 'vitest';
4+
5+
expect.extend(matchers);

tsconfig.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,6 @@
1616
"noEmit": true,
1717
"jsx": "react-jsx"
1818
},
19-
"include": ["src", ".eslintrc.cjs"],
19+
"include": ["src", ".eslintrc.cjs", "vitest.config.ts"],
2020
"references": [{ "path": "./tsconfig.node.json" }]
2121
}

vitest.config.ts

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// eslint-disable-next-line import/no-extraneous-dependencies
2+
import { defineConfig } from 'vitest/config';
3+
4+
export default defineConfig({
5+
test: {
6+
globals: true,
7+
environment: 'jsdom',
8+
setupFiles: ['./src/setupTest.ts'],
9+
},
10+
});

0 commit comments

Comments
 (0)