Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bumping react versions, fixing some tests, adding some documentation #60

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,12 @@
"eslint:recommended",
"plugin:@typescript-eslint/recommended",
"plugin:react/recommended",
"prettier"
"prettier",
"plugin:import/errors",
"plugin:import/warnings",
"plugin:import/typescript",
"plugin:@typescript-eslint/recommended",
"plugin:prettier/recommended"
],
"parser": "@typescript-eslint/parser",
"parserOptions": {
Expand All @@ -18,7 +23,12 @@
},
"sourceType": "module"
},
"plugins": ["react", "@typescript-eslint"],
"plugins": [
"react",
"@typescript-eslint",
"jsdoc",
"prefer-arrow"
],
"rules": {
"react/display-name": "off"
},
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/lib
/node_modules
/coverage
.env
5 changes: 5 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

58 changes: 58 additions & 0 deletions .idea/codeStyles/Project.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions .idea/codeStyles/codeStyleConfig.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/inspectionProfiles/Project_Default.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions .idea/react-esi-fork.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
v18.17.0
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,18 @@ Or using NPM:

$ npm install react-esi

## Testing

Update snapshots

$ npm updateSnapshot

Run tests

$ npm run test

Tests do not work locally without a valid url to serve from, currently server.tsx has hardcoded value example.com does not run a local dev server for testing purposes.

## Usage

React ESI provides a convenient [Higher Order Component](https://reactjs.org/docs/higher-order-components.html) that will:
Expand Down
8 changes: 7 additions & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,11 @@ module.exports = {
},
testRegex: "(/__tests__/.*|(\\.|/)(test|spec))\\.tsx?$",
moduleFileExtensions: ["ts", "tsx", "js", "jsx", "json", "node"],
testEnvironment: "jsdom"
testEnvironment: "jsdom",

setupFiles: [
"./jest/jest.polyfills.js",
"./jest/jest.envVars.js",
"./src/server.tsx"
]
};
3 changes: 3 additions & 0 deletions jest/jest.envVars.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
process.env.REACT_ESI_SECRET =
"f7ddf06659aadbcba0cdad4c927ac5bf38167d714e1a15cad13115e7e9d21a9d";
process.env.REACT_ESI_PATH = "/_custom";
33 changes: 33 additions & 0 deletions jest/jest.polyfills.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// jest.polyfills.js
/**
* @note The block below contains polyfills for Node.js globals
* required for Jest to function when running JSDOM tests.
* These HAVE to be require's and HAVE to be in this exact
* order, since "undici" depends on the "TextEncoder" global API.
*
* Consider migrating to a more modern test runner if
* you don't want to deal with this.
*/

// eslint-disable-next-line @typescript-eslint/no-var-requires
const { TextDecoder, TextEncoder, ReadableStream } = require("node:util");
Object.defineProperties(globalThis, {
ReadableStream: { value: ReadableStream },
TextDecoder: { value: TextDecoder },
TextEncoder: { value: TextEncoder }
});

// eslint-disable-next-line @typescript-eslint/no-var-requires
const { Blob, File } = require("node:buffer");
// eslint-disable-next-line @typescript-eslint/no-var-requires
const { fetch, Headers, FormData, Request, Response } = require("undici");

Object.defineProperties(globalThis, {
fetch: { value: fetch, writable: true },
Blob: { value: Blob },
File: { value: File },
Headers: { value: Headers },
FormData: { value: FormData },
Request: { value: Request },
Response: { value: Response },
});
Loading
Loading