Skip to content

Commit

Permalink
feat(unit-tests): mocked service worker
Browse files Browse the repository at this point in the history
Added mocked services worker for API mocking.
Removed json-server in favor of msw.
Added msw handlers that persist the data to localstorage.

Installed dependencies:
```
yarn add msw @mswjs/data --dev
npx msw init public/ --save
```
  • Loading branch information
rbiedrawa committed Mar 16, 2022
1 parent 50ae5e5 commit 73cecf9
Show file tree
Hide file tree
Showing 23 changed files with 984 additions and 557 deletions.
3 changes: 2 additions & 1 deletion .env
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
REACT_APP_POSTS_API_BASE_URL= "http://localhost:8000/posts"
REACT_APP_API_BASE_URL= "http://localhost:8000"
REACT_APP_MSW_ENABLED=true
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ npx husky add .husky/commit-msg 'npx --no -- commitlint --edit "$1"'
* [Husky](https://typicode.github.io/husky/#/)
* [commitlint](https://commitlint.js.org/#/) - Lint commit messages
* [Standard Version](https://github.com/conventional-changelog/standard-version) - A utility for versioning using semver and CHANGELOG generation powered by Conventional Commits.

* [Mock Service Worker](https://mswjs.io/)
* [Redux Saga Test Plan](https://github.com/jfairbank/redux-saga-test-plan) - Redux Saga Test Plan aims to embrace both integration testing and unit testing approaches to make testing your sagas easy.

## Additional Links
Expand All @@ -131,4 +131,6 @@ npx husky add .husky/commit-msg 'npx --no -- commitlint --edit "$1"'
* [MUI - theme switcher](https://mui.com/customization/dark-mode/)
* [Level up your CSS linting using Stylelint](https://blog.logrocket.com/using-stylelint-improve-lint-css-scss-sass/)
* [Create React App: A quick setup guide](https://blog.logrocket.com/create-react-app-a-quick-setup-guide-b812f0aad03c/)
* [TypeScript Deep Dive](https://basarat.gitbook.io/typescript/)
* [TypeScript Deep Dive](https://basarat.gitbook.io/typescript/)
* [Bulletproof React](https://github.com/alan2207/bulletproof-react)
* [Jest cheat sheet](https://github.com/sapegin/jest-cheat-sheet)
21 changes: 16 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
"@reduxjs/toolkit": "^1.8.0",
"history": "^5.3.0",
"i18next": "^21.6.14",
"json-server": "^0.17.0",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"react-hook-form": "^7.27.1",
Expand All @@ -30,11 +29,10 @@
},
"scripts": {
"start": "react-scripts start",
"start:backend": "json-server --watch db.json --port 8000",
"build": "react-scripts build",
"eject": "react-scripts eject",
"test": "react-scripts test",
"coverage": "react-scripts test --coverage",
"coverage": "react-scripts test --coverage --watchAll=false",
"format": "prettier --write 'src'",
"eslint": "eslint --ext ts,tsx",
"lint": "yarn lint:css && yarn eslint src",
Expand Down Expand Up @@ -66,8 +64,7 @@
"devDependencies": {
"@commitlint/cli": "16.2.1",
"@commitlint/config-conventional": "16.2.1",
"@typescript-eslint/eslint-plugin": "5.14.0",
"@typescript-eslint/parser": "5.14.0",
"@mswjs/data": "^0.9.2",
"@testing-library/jest-dom": "^5.14.1",
"@testing-library/react": "^12.0.0",
"@testing-library/user-event": "^13.2.1",
Expand All @@ -76,6 +73,8 @@
"@types/react": "^17.0.20",
"@types/react-dom": "^17.0.9",
"@types/redux-logger": "^3.0.9",
"@typescript-eslint/eslint-plugin": "5.14.0",
"@typescript-eslint/parser": "5.14.0",
"eslint": "8.11.0",
"eslint-config-airbnb": "19.0.4",
"eslint-config-airbnb-typescript": "16.1.2",
Expand All @@ -88,6 +87,7 @@
"eslint-plugin-react-hooks": "4.3.0",
"husky": "7.0.4",
"lint-staged": "12.3.5",
"msw": "^0.39.2",
"postcss-scss": "4.0.3",
"prettier": "2.5.1",
"redux-saga-test-plan": "^4.0.4",
Expand All @@ -98,9 +98,20 @@
"stylelint-config-styled-components": "0.1.1",
"stylelint-processor-styled-components": "1.10.0"
},
"jest": {
"collectCoverageFrom": [
"src/**/*.{js,jsx,ts,tsx}",
"!src/test/**",
"!src/index.tsx",
"!src/reportWebVitals.ts"
]
},
"lint-staged": {
"src/*.{tsx,ts,js,jsx}": [
"yarn lint"
]
},
"msw": {
"workerDirectory": "public"
}
}
Loading

0 comments on commit 73cecf9

Please sign in to comment.