Skip to content

Commit

Permalink
feat: introduce network shim (#106)
Browse files Browse the repository at this point in the history
* chore: add hendrik as contributor

* chore(eslint): add eslint-plugin-cypress

* feat(network-shim): introduce network shim setup

* feat(commands): add `cy.all()` command

* feat: create plugins package

* fix(testing-network-shim-app): fix app

* chore(network-shim): add test app to examples instead of packages dir

* feat(cli): refactor run and open command with stub and capture support

* fix(network-shim): assume disabledMode if dhis2_api_stub_mode is not set

* feat(network-shim): add support for 304 responses

* fix(network-shim): add fixtures and yarn commands to example app

* chore(network-shim): gitignore eslintcache in example app

* fix(network-shim): gitignore eslintcache from example app .gitignore

* fix(network-shim): adjust how the example app imports local packages

* chore(network-shim): remove files related to plugins since unrelated

* chore(network-shim): new fixtures

* chore(network-shim): reformat workspaces configuration

* chore(network-shim): restore plugins file in cli repo because unrelated

* chore(network-shim): stop linting the example app

* feat(network-shim): validate version minot in capture mode

* fix(network-shim): sanitise request fixtures to avoid too many changes

* refactor(network-shim): remove everything related to static fixture mode

* refactor(network-shim): avoid ambiguous usage of the word request

* refactor(network-shim): remove tags from open command

* refactor(network-shim): use fs-extra ensureDir to skip parent dir check

* refactor(network-shim): improve variable name clarity

* refactor(network-shim): switch to cy.fixture and get dir from config

* refactor(network-shim): create alias directly

* refactor(network-shim): stop using abbreviations

* chore(network-shim): remove unused import

* chore(network-shim): add issue link to todo comment

* fix(network-shim): stop catching error but let them be thrown

* feat(network-shim): throw error if stub was not found

* chore: remove unused argument

* chore(network-shim): remove unused summary property

* chore(network-shim): add type annotations

* docs(network-shim): add docs to captureRequest

* chore(network-shim): update example app deps and fixtures

* docs(network-shim): add jsdocs to more complex functions

* fix(plugins): fix build command

* fix(cli): fix lint error
  • Loading branch information
HendrikThePendric authored Jan 7, 2021
1 parent ae92925 commit 2755e89
Show file tree
Hide file tree
Showing 60 changed files with 15,976 additions and 151 deletions.
14 changes: 14 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Editor settings
/.vscode

# dependencies
node_modules/

# production
build/
dist/

# d2
.d2/

examples/testing-network-shim-app
7 changes: 1 addition & 6 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
const { config } = require('@dhis2/cli-style')

module.exports = {
extends: [config.eslint],
globals: {
Cypress: 'readonly',
cy: 'readonly',
},
ignorePatterns: ['**/templates/*.js'],
extends: ['plugin:cypress/recommended', config.eslint],
}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,4 @@ bundle.stats.json

# d2
.d2/

2 changes: 2 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.vscode/
examples/testing-network-shim-app/cypress/fixtures
1 change: 1 addition & 0 deletions examples/testing-network-shim-app/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
SKIP_PREFLIGHT_CHECK=true
5 changes: 5 additions & 0 deletions examples/testing-network-shim-app/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const { config } = require('@dhis2/cli-style')

module.exports = {
extends: ['plugin:cypress/recommended', config.eslintReact],
}
26 changes: 26 additions & 0 deletions examples/testing-network-shim-app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules
/.pnp
.pnp.js

# testing
/coverage

# production
/build

# misc
.DS_Store
.env.local
.env.development.local
.env.test.local
.env.production.local

npm-debug.log*
yarn-debug.log*
yarn-error.log*

# eslint cache
.eslintcache
70 changes: 70 additions & 0 deletions examples/testing-network-shim-app/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# Getting Started with Create React App

This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).

## Available Scripts

In the project directory, you can run:

### `yarn start`

Runs the app in the development mode.\
Open [http://localhost:3000](http://localhost:3000) to view it in the browser.

The page will reload if you make edits.\
You will also see any lint errors in the console.

### `yarn test`

Launches the test runner in the interactive watch mode.\
See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information.

### `yarn build`

Builds the app for production to the `build` folder.\
It correctly bundles React in production mode and optimizes the build for the best performance.

The build is minified and the filenames include the hashes.\
Your app is ready to be deployed!

See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information.

### `yarn eject`

**Note: this is a one-way operation. Once you `eject`, you can’t go back!**

If you aren’t satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project.

Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you’re on your own.

You don’t have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn’t feel obligated to use this feature. However we understand that this tool wouldn’t be useful if you couldn’t customize it when you are ready for it.

## Learn More

You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started).

To learn React, check out the [React documentation](https://reactjs.org/).

### Code Splitting

This section has moved here: [https://facebook.github.io/create-react-app/docs/code-splitting](https://facebook.github.io/create-react-app/docs/code-splitting)

### Analyzing the Bundle Size

This section has moved here: [https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size](https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size)

### Making a Progressive Web App

This section has moved here: [https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app](https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app)

### Advanced Configuration

This section has moved here: [https://facebook.github.io/create-react-app/docs/advanced-configuration](https://facebook.github.io/create-react-app/docs/advanced-configuration)

### Deployment

This section has moved here: [https://facebook.github.io/create-react-app/docs/deployment](https://facebook.github.io/create-react-app/docs/deployment)

### `yarn build` fails to minify

This section has moved here: [https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify](https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify)
6 changes: 6 additions & 0 deletions examples/testing-network-shim-app/cypress.env.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"dhis2_base_url": "http://localhost:1337",
"dhis2_username": "admin",
"dhis2_password": "district",
"dhis2_datatest_prefix": "dhis2-networkshim"
}
4 changes: 4 additions & 0 deletions examples/testing-network-shim-app/cypress.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"baseUrl": "http://localhost:3000",
"video": false
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
[
{
"path": "/api/36/names",
"testName": "Filter -- is possible to filter the list",
"static": false,
"count": 2,
"nonDeterministic": false,
"method": "GET",
"requestBody": "",
"requestHeaders": {
"host": "localhost:1337",
"proxy-connection": "keep-alive",
"accept": "application/json, text/plain, */*",
"user-agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 11_0_0) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/87.0.4280.88 Safari/537.36",
"origin": "http://localhost:3000",
"sec-fetch-site": "same-site",
"sec-fetch-mode": "cors",
"sec-fetch-dest": "empty",
"referer": "http://localhost:3000/",
"accept-encoding": "gzip, deflate, br",
"accept-language": "en-US"
},
"statusCode": 200,
"responseBody": "[{\"name\":\"Goofy\",\"id\":1},{\"name\":\"Donald\",\"id\":2},{\"name\":\"Duck\",\"id\":3}]",
"responseSize": 73,
"responseHeaders": {
"x-powered-by": "Express",
"access-control-allow-origin": "http://localhost:3000",
"vary": "Origin, Accept-Encoding",
"access-control-allow-credentials": "true",
"cache-control": "no-cache",
"pragma": "no-cache",
"expires": "-1",
"x-content-type-options": "nosniff",
"content-type": "application/json; charset=utf-8",
"content-length": "128",
"etag": "W/\"80-7amB96uJ+4oWmNgr+D5YpTptWdI\"",
"connection": "keep-alive"
}
},
{
"path": "/api/36/names?q=D",
"testName": "Filter -- is possible to filter the list",
"static": false,
"count": 1,
"nonDeterministic": false,
"method": "GET",
"requestBody": "",
"requestHeaders": {
"host": "localhost:1337",
"proxy-connection": "keep-alive",
"accept": "application/json, text/plain, */*",
"user-agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 11_0_0) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/87.0.4280.88 Safari/537.36",
"origin": "http://localhost:3000",
"sec-fetch-site": "same-site",
"sec-fetch-mode": "cors",
"sec-fetch-dest": "empty",
"referer": "http://localhost:3000/",
"accept-encoding": "gzip, deflate, br",
"accept-language": "en-US"
},
"statusCode": 200,
"responseBody": "[{\"name\":\"Donald\",\"id\":2},{\"name\":\"Duck\",\"id\":3}]",
"responseSize": 49,
"responseHeaders": {
"x-powered-by": "Express",
"access-control-allow-origin": "http://localhost:3000",
"vary": "Origin, Accept-Encoding",
"access-control-allow-credentials": "true",
"cache-control": "no-cache",
"pragma": "no-cache",
"expires": "-1",
"x-content-type-options": "nosniff",
"content-type": "application/json; charset=utf-8",
"content-length": "86",
"etag": "W/\"56-xQIJmK5HFoagWlaw949SaSlIw9U\"",
"connection": "keep-alive"
}
}
]
Loading

0 comments on commit 2755e89

Please sign in to comment.