Skip to content

Commit 0cb6800

Browse files
committed
fix: Small changes and chores
- Decreased bundle size - Added eslint - Improved testing tooling
1 parent 90ab1c3 commit 0cb6800

File tree

15 files changed

+1965
-370
lines changed

15 files changed

+1965
-370
lines changed

.eslintrc.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
module.exports = {
2+
root: true,
3+
parser: "@typescript-eslint/parser",
4+
plugins: ["@typescript-eslint", "react-hooks"],
5+
extends: [
6+
"plugin:@typescript-eslint/recommended",
7+
"plugin:react-hooks/recommended",
8+
],
9+
rules: {
10+
"@typescript-eslint/ban-ts-comment": "off",
11+
},
12+
};

.github/workflows/testing.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,12 @@ jobs:
2222
run: yarn install --frozen-lockfile
2323
- name: Checking File Size
2424
run: yarn check:size
25+
- name: Checking Linting Rules
26+
run: yarn check:lint
2527
- name: Checking Types
2628
run: yarn check:types
29+
- name: Running Unit Tests
30+
run: yarn test:unit
2731
- name: Testing SSR
2832
run: yarn test:create:ssr
2933
- name: Testing in Modern Browsers (BrowserStack)

.size-limit.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
[
22
{
33
"path": "dist/bundle.esm.js",
4-
"limit": "661B",
4+
"limit": "648B",
55
"gzip": true
66
},
77
{
88
"path": "dist/bundle.cjs.js",
9-
"limit": "637B",
9+
"limit": "625B",
1010
"gzip": true
1111
},
1212
{
1313
"path": "polyfilled.js",
14-
"limit": "3.4kB",
14+
"limit": "3384B",
1515
"gzip": true
1616
}
1717
]

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ A React hook that allows you to use a ResizeObserver to measure an element's siz
1616
## Highlights
1717

1818
- Written in **TypeScript**.
19-
- **Tiny**: [661B](.size-limit.json) (minified, gzipped) Monitored by [size-limit](https://github.com/ai/size-limit).
19+
- **Tiny**: [648B](.size-limit.json) (minified, gzipped) Monitored by [size-limit](https://github.com/ai/size-limit).
2020
- Exposes an **onResize callback** if you need more control.
2121
- `box` [option](https://developer.mozilla.org/en-US/docs/Web/API/ResizeObserver/observe#syntax).
2222
- Works with **SSR**.

jest.config.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */
2+
module.exports = {
3+
preset: "ts-jest",
4+
testEnvironment: "jsdom",
5+
testPathIgnorePatterns: ["/node_modules/", "/tests/"],
6+
};

package.json

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@
3232
"src:watch": "rollup -c -w",
3333
"check:size": "size-limit",
3434
"check:types": "tsc -p tests",
35-
"test": "run-s 'build' 'check:size' 'check:types' 'test:create:ssr' 'test:headless:chrome'",
35+
"check:lint": "eslint src/**",
36+
"test": "run-s 'build' 'check:size' 'check:types' 'check:lint' 'test:unit' 'test:create:ssr' 'test:headless:chrome'",
37+
"test:unit": "jest",
3638
"test:create:ssr": "node ./tests/ssr/create-ssr-test.js",
3739
"test:chrome": "KARMA_BROWSERS=Chrome yarn karma:run",
3840
"test:headless:chrome": "KARMA_BROWSERS=ChromeHeadless yarn karma:run",
@@ -90,18 +92,25 @@
9092
"@semantic-release/release-notes-generator": "^10.0.3",
9193
"@size-limit/preset-small-lib": "^5.0.1",
9294
"@testing-library/react": "^13.1.1",
95+
"@types/jest": "^28.1.1",
9396
"@types/karma": "^6.3.1",
9497
"@types/karma-jasmine": "^4.0.1",
9598
"@types/react": "^18.0.8",
9699
"@types/react-dom": "^18.0.3",
100+
"@typescript-eslint/eslint-plugin": "^5.27.1",
101+
"@typescript-eslint/parser": "^5.27.1",
97102
"babel-loader": "^8.1.0",
98103
"delay": "^5.0.0",
104+
"eslint": "^8.17.0",
105+
"eslint-plugin-react-hooks": "^4.5.0",
99106
"husky": "^8.0.1",
107+
"jest": "^28.1.1",
108+
"jest-environment-jsdom": "^28.1.1",
100109
"karma": "^6.3.4",
101110
"karma-browserstack-launcher": "^1.6.0",
102111
"karma-chrome-launcher": "^3.0.0",
103112
"karma-firefox-launcher": "^2.1.1",
104-
"karma-jasmine": "^5.0.1",
113+
"karma-jasmine": "^4.0.0",
105114
"karma-sourcemap-loader": "^0.3.7",
106115
"karma-spec-reporter": "^0.0.34",
107116
"karma-webpack": "^5.0.0",
@@ -114,8 +123,9 @@
114123
"rollup": "^2.6.1",
115124
"semantic-release": "^19.0.3",
116125
"size-limit": "^5.0.1",
126+
"ts-jest": "^28.0.4",
117127
"typescript": "^4.3.5",
118-
"webpack": "^5.73.0"
128+
"webpack": "^4.1"
119129
},
120130
"dependencies": {
121131
"@juggle/resize-observer": "^3.3.1"

src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ function useResizeObserver<T extends Element>(
161161
width: size.width,
162162
height: size.height,
163163
}),
164-
[refCallback, size ? size.width : null, size ? size.height : null]
164+
[refCallback, size.width, size.height]
165165
);
166166
}
167167

tests/@types/jest/jasmine/index.d.ts

Whitespace-only changes.

tests/@types/jest/karma-jasmine/index.d.ts

Whitespace-only changes.

tests/@types/karma/jest/index.d.ts

Whitespace-only changes.

0 commit comments

Comments
 (0)