Skip to content

Commit 29e8cb3

Browse files
committed
Initial commit
0 parents  commit 29e8cb3

File tree

124 files changed

+20115
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

124 files changed

+20115
-0
lines changed

.env

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
SKIP_PREFLIGHT_CHECK=true

.gitignore

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
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+
# production
12+
/build
13+
14+
# editors
15+
/.idea
16+
/.vscode
17+
18+
# misc
19+
.DS_Store
20+
.eslintcache
21+
.env.local
22+
.env.development.local
23+
.env.test.local
24+
.env.production.local
25+
26+
npm-debug.log*
27+
yarn-debug.log*
28+
yarn-error.log*

.prettierignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
package.json
2+
package-lock.json
3+
*.snap

.prettierrc.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
module.exports = {
2+
singleQuote: true,
3+
proseWrap: 'always',
4+
};

.storybook/main.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// @ts-ignore
2+
module.exports = {
3+
stories: ['../src/**/*.stories.mdx', '../src/**/*.stories.@(js|jsx|ts|tsx)'],
4+
addons: [
5+
'@storybook/addon-links',
6+
'@storybook/addon-essentials',
7+
'@storybook/preset-create-react-app',
8+
],
9+
};

.storybook/preview-head.html

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<link rel="stylesheet" href="https://rsms.me/inter/inter.css" />
2+
<script>
3+
window._env_ = {
4+
API_URL: 'http://localhost:8080',
5+
};
6+
</script>

.storybook/preview.tsx

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import React from 'react';
2+
import { addDecorator } from '@storybook/react';
3+
import { QueryClient, QueryClientProvider } from 'react-query';
4+
import { BrowserRouter as Router } from 'react-router-dom';
5+
import { EnvProvider } from '../src/contexts';
6+
import '../src/services/AxiosInterceptors';
7+
import '../src/styles/main.css';
8+
9+
export const parameters = {
10+
actions: { argTypesRegex: '^on[A-Z].*' },
11+
options: {
12+
storySort: {
13+
order: ['Home'],
14+
},
15+
},
16+
};
17+
18+
// Start mock service worker
19+
const { worker } = require('../src/mocks/browser');
20+
worker.start();
21+
worker.printHandlers();
22+
23+
const queryClient = new QueryClient({
24+
defaultOptions: {
25+
queries: {
26+
refetchOnWindowFocus: false,
27+
},
28+
},
29+
});
30+
31+
const StoryDecorator = (Story: any) => (
32+
<EnvProvider>
33+
<QueryClientProvider client={queryClient}>
34+
<Router>
35+
<Story />
36+
</Router>
37+
</QueryClientProvider>
38+
</EnvProvider>
39+
);
40+
41+
addDecorator(StoryDecorator);

README.md

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
# React Testing Techniques
2+
3+
This project implements an online shopping application to show techniques used
4+
to test React applications. We use the following tools for testing:
5+
6+
**Unit Testing**
7+
8+
- [Jest](https://jestjs.io/) - a testing framework designed to ensure
9+
correctness of any JavaScript or TypeScript codebase
10+
11+
- [React Testing Library](https://testing-library.com/) - a testing framework
12+
for React components that encourages better testing practices
13+
14+
- [Mock Service Worker](https://mswjs.io/) - a framework to mock APIs by
15+
intercepting requests at the network level. It allows us to reuse the same
16+
mock definition for testing, development, and debugging.
17+
18+
**Integration Testing**
19+
20+
- [Cypress](https://www.cypress.io/) - a testing framework for fully built Web
21+
applications running in a browser
22+
23+
This project was bootstrapped with
24+
[React Accelerate](https://github.com/PublicisSapient/cra-template-accelerate).
25+
26+
## Screenshots
27+
28+
**Home page with item catalog and shopping cart**
29+
30+
![Home Page](assets/screenshot-home.png)
31+
32+
## Getting Started
33+
34+
Make sure your development machine is set up for building React apps. See the
35+
recommended setup procedure
36+
[here](https://github.com/nareshbhatia/react-learning-resources/blob/main/docs/mac-setup.md).
37+
38+
Execute the following commands to install dependencies:
39+
40+
```sh
41+
# if using yarn v7 add --legacy-peer-deps option
42+
# see details here: https://github.com/storybookjs/storybook/issues/12983
43+
yarn install
44+
```
45+
46+
Now execute the following commands to run the app:
47+
48+
```sh
49+
yarn start
50+
```
51+
52+
Now point your browser to http://localhost:3000/.
53+
54+
## Running Unit Tests
55+
56+
React Accelerate comes ready with Jest and React Testing Library to run unit
57+
tests. Execute one of the following command to run unit tests.
58+
59+
```sh
60+
yarn test # interactive mode
61+
yarn test:coverage # non-interactive mode with coverage information
62+
```
63+
64+
Note that unit tests are automatically executed when you commit code to your
65+
local repo. This ensures that you are not committing broken code.
66+
67+
## Running End-to-End Tests
68+
69+
React Accelerate comes ready with Cypress to run end-to-end tests. Execute
70+
Cypress using the following commands:
71+
72+
```sh
73+
yarn start # starts a local server hosting your react app
74+
75+
# run cypress in a different shell
76+
yarn cypress:open
77+
```

assets/screenshot-home.png

930 KB
Loading

cypress.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"baseUrl": "http://localhost:3000"
3+
}

0 commit comments

Comments
 (0)