Skip to content

Commit

Permalink
merge wip/react-query
Browse files Browse the repository at this point in the history
  • Loading branch information
kentcdodds committed Mar 23, 2020
2 parents b02f358 + 415a28b commit 0fd5e8e
Show file tree
Hide file tree
Showing 70 changed files with 8,400 additions and 6,690 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,5 @@
npm-debug.log*
yarn-debug.log*
yarn-error.log*

dev-tools.local.js
7 changes: 6 additions & 1 deletion .prettierrc
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
{
"arrowParens": "avoid",
"bracketSpacing": false,
"endOfLine": "lf",
"htmlWhitespaceSensitivity": "css",
"insertPragma": false,
"jsxBracketSameLine": false,
"jsxSingleQuote": false,
"printWidth": 80,
"proseWrap": "always",
"quoteProps": "as-needed",
"requirePragma": false,
"semi": false,
"singleQuote": true,
"tabWidth": 2,
"trailingComma": "all",
"useTabs": false
}

3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ The more prepared you are for the workshop, the better it will go for you.

- Manage forms (login and registration form)
- Add authentication (auth-context)
- @reach/router (setup all routes)
- react-router v6 (setup all routes)
- App State (List Items)
- Code-splitting (add code-splitting the authenticated and unauthenticated
pages)
Expand Down Expand Up @@ -213,6 +213,7 @@ Thanks goes to these wonderful people

<!-- markdownlint-enable -->
<!-- prettier-ignore-end -->

<!-- ALL-CONTRIBUTORS-LIST:END -->

This project follows the
Expand Down
2 changes: 1 addition & 1 deletion cypress/fixtures/example.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
"name": "Using fixtures to represent data",
"email": "hello@cypress.io",
"body": "Fixtures are a great way to mock data for responses to routes"
}
}
6 changes: 6 additions & 0 deletions jsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"compilerOptions": {
"baseUrl": "./src"
},
"include": ["src"]
}
12,051 changes: 6,819 additions & 5,232 deletions package-lock.json

Large diffs are not rendered by default.

69 changes: 43 additions & 26 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,49 +8,58 @@
"npm": ">=6"
},
"dependencies": {
"@emotion/core": "^10.0.27",
"@emotion/core": "^10.0.28",
"@emotion/styled": "^10.0.27",
"@reach/dialog": "^0.8.0",
"@reach/menu-button": "^0.8.0",
"@reach/router": "^1.2.1",
"@reach/tabs": "^0.8.0",
"@reach/tooltip": "^0.8.0",
"@reach/visually-hidden": "^0.8.0",
"@testing-library/jest-dom": "^5.0.2",
"@testing-library/react": "^9.4.0",
"@reach/dialog": "^0.9.1",
"@reach/menu-button": "^0.9.1",
"@reach/tabs": "^0.9.1",
"@reach/tooltip": "^0.9.1",
"@reach/visually-hidden": "^0.9.0",
"@testing-library/jest-dom": "^5.1.1",
"@testing-library/react": "^10.0.1",
"@testing-library/user-event": "^10.0.0",
"autoprefixer": "^9.7.4",
"bootstrap": "^4.4.1",
"debounce-fn": "^3.0.1",
"debounce-fn": "^4.0.0",
"faker": "^4.1.0",
"history": "^5.0.0-beta.5",
"match-sorter": "^4.0.2",
"msw": "^0.10.0",
"node-match-path": "^0.3.1",
"prop-types": "^15.7.2",
"querystringify": "^2.1.1",
"react": "16.12.0",
"react-async": "^10.0.0",
"react-dom": "16.12.0",
"react": "16.13.1",
"react-dom": "16.13.1",
"react-error-boundary": "^1.2.5",
"react-icons": "^3.9.0",
"react-scripts": "^3.3.1",
"serve": "^11.3.0",
"stop-runaway-react-effects": "^1.2.1"
"react-query": "^1.0.34",
"react-query-devtools": "^1.0.12",
"react-router": "^6.0.0-alpha.2",
"react-router-dom": "^6.0.0-alpha.2",
"react-scripts": "^3.4.1",
"stop-runaway-react-effects": "^2.0.0"
},
"devDependencies": {
"@testing-library/cypress": "^5.1.2",
"cross-env": "^7.0.0",
"cypress": "^3.8.3",
"cypress-hmr-restarter": "^1.0.1",
"eslint-plugin-cypress": "^2.8.1",
"husky": "^4.2.1",
"@testing-library/cypress": "^6.0.0",
"cross-env": "^7.0.2",
"cypress": "^4.2.0",
"cypress-hmr-restarter": "^1.0.2",
"eslint-plugin-cypress": "^2.10.3",
"husky": "^4.2.3",
"is-ci-cli": "^2.0.0",
"jest-environment-jsdom-sixteen": "^1.0.3",
"npm-run-all": "^4.1.5",
"prettier": "^1.19.1",
"start-server-and-test": "^1.10.8",
"prettier": "^2.0.1",
"serve": "^11.3.0",
"start-server-and-test": "^1.10.11",
"test-data-bot": "^0.8.0"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"test": "react-scripts test --env=jest-environment-jsdom-sixteen",
"test:coverage": "npm run test -- --watchAll false --coverage",
"test:debug": "node --inspect-brk ./node_modules/react-scripts/scripts/test.js --runInBand",
"test:debug": "node --inspect-brk ./node_modules/react-scripts/scripts/test.js --env=jest-environment-jsdom-sixteen --watch --runInBand",
"cy:run": "cypress run",
"cy:open": "cypress open",
"test:e2e": "is-ci \"test:e2e:run\" \"test:e2e:dev\"",
Expand All @@ -71,6 +80,14 @@
"pre-commit": "npm run validate"
}
},
"jest": {
"collectCoverageFrom": [
"src/**/*.js",
"!<rootDir>/node_modules/**/*",
"!<rootDir>/src/test/**/*",
"!<rootDir>/src/dev-tools/**/*"
]
},
"browserslist": {
"development": [
"last 2 chrome versions",
Expand Down
3 changes: 0 additions & 3 deletions public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@
<title>React App</title>
</head>
<body>
<noscript>
You need to enable JavaScript to run this app.
</noscript>
<div id="root"></div>
<!--
This HTML file is a template.
Expand Down
135 changes: 135 additions & 0 deletions public/msw.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
/**
* Mock Service Worker.
* @see https://github.com/kettanaito/msw
* This Service Worker is meant for development usage only.
* Make sure not to include it on production.
*/
self.addEventListener('install', (event) => {
return self.skipWaiting()
})

self.addEventListener('activate', (event) => {
console.log('%c[MSW] Activated!', 'color:green;font-weight:bold;')
return self.clients.claim()
})

self.addEventListener('message', (event) => {
switch (event.data) {
case 'MOCK_ACTIVATE': {
self.__isMswEnabled = true
break
}

case 'MOCK_DEACTIVATE': {
self.__isMswEnabled = false
break
}
}
})

const messageClient = (client, message) => {
return new Promise((resolve, reject) => {
const channel = new MessageChannel()

channel.port1.onmessage = (event) => {
if (event.data && event.data.error) {
reject(event.data.error)
} else {
resolve(event.data)
}
}

client.postMessage(JSON.stringify(message), [channel.port2])
})
}

self.addEventListener('fetch', async (event) => {
const { clientId, request: req } = event
const requestClone = req.clone()
const getOriginalResponse = () => fetch(requestClone)

event.respondWith(
new Promise(async (resolve) => {
const client = await event.target.clients.get(clientId)

// Bypass requests while MSW is not enabled
if (!client || !self.__isMswEnabled) {
return resolve(getOriginalResponse())
}

// Bypass requests with the explicit bypass header
if (req.headers.get('x-msw-bypass') === 'true') {
const modifiedHeaders = serializeHeaders(req.headers)
// Remove the bypass header to comply with the CORS preflight check
delete modifiedHeaders['x-msw-bypass']

return resolve(
fetch(
new Request(req.url, {
...req,
headers: new Headers(modifiedHeaders),
}),
),
)
}

/**
* Converts "Headers" to the plain Object to be stringified.
* @todo See how this handles multipe headers with the same name.
*/
const reqHeaders = serializeHeaders(req.headers)

/**
* If the body cannot be resolved (either as JSON or to text/string),
* the default value will be undefined.
*/
const json = await req.json().catch(() => void 0)
const text = await req.text().catch(() => void 0)

const clientResponse = await messageClient(client, {
url: req.url,
method: req.method,
headers: reqHeaders,
cache: req.cache,
mode: req.mode,
credentials: req.credentials,
destination: req.destination,
integrity: req.integrity,
redirect: req.redirect,
referrer: req.referrer,
referrerPolicy: req.referrerPolicy,
body: json || text,
bodyUsed: req.bodyUsed,
keepalive: req.keepalive,
})

if (clientResponse === 'MOCK_NOT_FOUND') {
return resolve(getOriginalResponse())
}

const mockedResponse = JSON.parse(clientResponse, (key, value) => {
return key === 'headers' ? new Headers(value) : value
})

setTimeout(
resolve.bind(this, new Response(mockedResponse.body, mockedResponse)),
mockedResponse.delay,
)
}).catch((error) => {
console.error(
'[MSW] Failed to mock a "%s" request to "%s": %s',
req.method,
req.url,
error,
)
}),
)
})

const serializeHeaders = (headers) => {
const reqHeaders = {}
headers.forEach((value, name) => {
reqHeaders[name] = value
})
return reqHeaders
}
Loading

0 comments on commit 0fd5e8e

Please sign in to comment.