Skip to content

Commit 793db87

Browse files
authored
fix: react 19 support (#278)
1 parent a54800f commit 793db87

File tree

4 files changed

+1409
-1172
lines changed

4 files changed

+1409
-1172
lines changed

.github/workflows/main.yml

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,7 @@ name: CI
99
jobs:
1010
build:
1111
name: Lint, and test on Node ${{ matrix.node }} and ${{ matrix.os }}
12-
13-
runs-on: ${{ matrix.os }}
14-
strategy:
15-
matrix:
16-
node: ['16.x']
17-
os: [ubuntu-latest, windows-latest, macOS-latest]
12+
runs-on: ubuntu-latest
1813

1914
steps:
2015
- name: Checkout repo

package.json

Lines changed: 95 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -1,99 +1,97 @@
11
{
2-
"name": "react-screen-wake-lock",
3-
"version": "0.0.0-development",
4-
"description": "React implementation of the Screen Wake Lock API. It provides a way to prevent devices from dimming or locking the screen when an application needs to keep running.",
5-
"author": {
6-
"name": "Joris",
7-
"email": "[email protected]",
8-
"url": "https://joris.re"
9-
},
10-
"license": "MIT",
11-
"homepage": "https://github.com/jorisre/react-screen-wake-lock#readme",
12-
"repository": {
13-
"type": "git",
14-
"url": "https://github.com/jorisre/react-screen-wake-lock.git"
15-
},
16-
"bugs": {
17-
"url": "https://github.com/jorisre/react-screen-wake-lock/issues"
18-
},
19-
"keywords": [
20-
"wakeLock",
21-
"wake-lock",
22-
"react",
23-
"hook",
24-
"Screen Wake Lock",
25-
"navigator.wakeLock"
26-
],
27-
"sideEffects": false,
28-
"type": "module",
29-
"source": "src/index.ts",
30-
"main": "dist/react-screen-wake-lock.cjs",
31-
"nodule": "./dist/react-screen-wake-lock.esm.js",
32-
"exports": {
33-
"types": "./dist/index.d.ts",
34-
"require": "./dist/react-screen-wake-lock.cjs",
35-
"default": "./dist/react-screen-wake-lock.esm.js"
36-
},
37-
"umd:main": "dist/react-screen-wake-lock.umd.js",
38-
"unpkg": "dist/react-screen-wake-lock.umd.js",
39-
"typings": "dist/index.d.ts",
40-
"files": [
41-
"dist",
42-
"src"
43-
],
44-
"engines": {
45-
"node": ">=v14.21.3"
46-
},
47-
"scripts": {
48-
"prepare": "husky install",
49-
"prepack": "pinst --disable",
50-
"postpack": "pinst --enable",
51-
"start": "microbundle watch",
52-
"prebuild": "rimraf dist",
53-
"build": "npm-run-all --parallel build:*",
54-
"build:other": "microbundle --define process.env.NODE_ENV=production -f cjs,umd",
55-
"build:es": "microbundle -f es",
56-
"test": "jest",
57-
"lint": "eslint --ignore-path .gitignore --ext .ts,.tsx ."
58-
},
59-
"peerDependencies": {
60-
"react": "^16.8.0 || ^17.0.0 || ^18.0.0"
61-
},
62-
"devDependencies": {
63-
"@testing-library/dom": "^9.3.1",
64-
"@testing-library/react": "^14.0.0",
65-
"@testing-library/react-hooks": "^8.0.1",
66-
"@types/dom-screen-wake-lock": "^1.0.1",
67-
"@types/jest": "^29.5.4",
68-
"@types/react": "^18.2.21",
69-
"@types/react-dom": "^18.2.7",
70-
"@typescript-eslint/eslint-plugin": "^6.7.0",
71-
"@typescript-eslint/parser": "^6.7.0",
72-
"eslint": "^8.49.0",
73-
"eslint-plugin-react": "^7.33.2",
74-
"eslint-plugin-react-hooks": "^4.6.0",
75-
"eslint-plugin-testing-library": "^6.0.1",
76-
"husky": "^8.0.3",
77-
"jest": "^29.7.0",
78-
"jest-environment-jsdom": "^29.7.0",
79-
"jest-wake-lock-mock": "^1.1.0",
80-
"lodash": "^4.17.21",
81-
"microbundle": "^0.15.1",
82-
"nano-staged": "^0.8.0",
83-
"npm-run-all": "^4.1.5",
84-
"pinst": "^3.0.0",
85-
"prettier": "^3.0.3",
86-
"react": "18.2.0",
87-
"react-dom": "18.2.0",
88-
"react-test-renderer": "18.2.0",
89-
"rimraf": "^5.0.1",
90-
"ts-jest": "^29.1.1",
91-
"ts-node": "^10.9.1",
92-
"typescript": "^5.2.2"
93-
},
94-
"nano-staged": {
95-
"*.{ts,tsx}": "eslint --fix",
96-
"*.{js,css,md}": "prettier --write"
97-
},
98-
"dependencies": {}
2+
"name": "react-screen-wake-lock",
3+
"version": "0.0.0-development",
4+
"description": "React implementation of the Screen Wake Lock API. It provides a way to prevent devices from dimming or locking the screen when an application needs to keep running.",
5+
"author": {
6+
"name": "Joris",
7+
"email": "[email protected]",
8+
"url": "https://joris.re"
9+
},
10+
"license": "MIT",
11+
"homepage": "https://github.com/jorisre/react-screen-wake-lock#readme",
12+
"repository": {
13+
"type": "git",
14+
"url": "https://github.com/jorisre/react-screen-wake-lock.git"
15+
},
16+
"bugs": {
17+
"url": "https://github.com/jorisre/react-screen-wake-lock/issues"
18+
},
19+
"keywords": [
20+
"wakeLock",
21+
"wake-lock",
22+
"react",
23+
"hook",
24+
"Screen Wake Lock",
25+
"navigator.wakeLock"
26+
],
27+
"sideEffects": false,
28+
"type": "module",
29+
"source": "src/index.ts",
30+
"main": "dist/react-screen-wake-lock.cjs",
31+
"nodule": "./dist/react-screen-wake-lock.esm.js",
32+
"exports": {
33+
"types": "./dist/index.d.ts",
34+
"require": "./dist/react-screen-wake-lock.cjs",
35+
"default": "./dist/react-screen-wake-lock.esm.js"
36+
},
37+
"umd:main": "dist/react-screen-wake-lock.umd.js",
38+
"unpkg": "dist/react-screen-wake-lock.umd.js",
39+
"typings": "dist/index.d.ts",
40+
"files": [
41+
"dist",
42+
"src"
43+
],
44+
"engines": {
45+
"node": ">=v14.21.3"
46+
},
47+
"scripts": {
48+
"prepare": "husky install",
49+
"prepack": "pinst --disable",
50+
"postpack": "pinst --enable",
51+
"start": "microbundle watch",
52+
"prebuild": "rimraf dist",
53+
"build": "npm-run-all --parallel build:*",
54+
"build:other": "microbundle --define process.env.NODE_ENV=production -f cjs,umd",
55+
"build:es": "microbundle -f es",
56+
"test": "jest",
57+
"lint": "eslint --ignore-path .gitignore --ext .ts,.tsx ."
58+
},
59+
"peerDependencies": {
60+
"react": "^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0"
61+
},
62+
"devDependencies": {
63+
"@testing-library/dom": "^10.4.0",
64+
"@testing-library/react": "^16.2.0",
65+
"@types/dom-screen-wake-lock": "^1.0.3",
66+
"@types/jest": "^29.5.4",
67+
"@types/react": "^18.2.21",
68+
"@types/react-dom": "^18.2.7",
69+
"@typescript-eslint/eslint-plugin": "^6.7.0",
70+
"@typescript-eslint/parser": "^6.7.0",
71+
"eslint": "^8.49.0",
72+
"eslint-plugin-react": "^7.33.2",
73+
"eslint-plugin-react-hooks": "^4.6.0",
74+
"eslint-plugin-testing-library": "^6.0.1",
75+
"husky": "^8.0.3",
76+
"jest": "^29.7.0",
77+
"jest-environment-jsdom": "^29.7.0",
78+
"jest-wake-lock-mock": "^1.1.0",
79+
"microbundle": "^0.15.1",
80+
"nano-staged": "^0.8.0",
81+
"npm-run-all": "^4.1.5",
82+
"pinst": "^3.0.0",
83+
"prettier": "^3.0.3",
84+
"react": "^19.0.0",
85+
"react-dom": "^19.0.0",
86+
"react-test-renderer": "18.2.0",
87+
"rimraf": "^5.0.1",
88+
"ts-jest": "^29.1.1",
89+
"ts-node": "^10.9.1",
90+
"typescript": "^5.2.2"
91+
},
92+
"nano-staged": {
93+
"*.{ts,tsx}": "eslint --fix",
94+
"*.{js,css,md}": "prettier --write"
95+
},
96+
"dependencies": {}
9997
}

test/use-wake-lock.test.tsx

Lines changed: 30 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { act, renderHook } from '@testing-library/react-hooks';
2-
import { useWakeLock, WakeLockOptions } from '../src';
1+
import { renderHook, act } from '@testing-library/react';
2+
import { useWakeLock } from '../src';
33

44
const noop = () => {};
55

@@ -31,8 +31,8 @@ test('in development|test mode there are warnings displayed if `request` or `rel
3131

3232
expect(result.current.released).not.toBeDefined();
3333
expect(result.current.type).not.toBeDefined();
34-
expect(spyedConsoleWarn).toBeCalledWith(
35-
"[react-screen-wake-lock]: Calling the `request` function has no effect, Wake Lock Screen API isn't supported"
34+
expect(spyedConsoleWarn).toHaveBeenCalledWith(
35+
"[react-screen-wake-lock]: Calling the `request` function has no effect, Wake Lock Screen API isn't supported",
3636
);
3737

3838
await act(async () => {
@@ -41,8 +41,8 @@ test('in development|test mode there are warnings displayed if `request` or `rel
4141

4242
expect(result.current.released).not.toBeDefined();
4343
expect(result.current.type).not.toBeDefined();
44-
expect(spyedConsoleWarn).toBeCalledWith(
45-
"[react-screen-wake-lock]: Calling the `release` function has no effect, Wake Lock Screen API isn't supported"
44+
expect(spyedConsoleWarn).toHaveBeenCalledWith(
45+
"[react-screen-wake-lock]: Calling the `release` function has no effect, Wake Lock Screen API isn't supported",
4646
);
4747
});
4848

@@ -72,20 +72,16 @@ test('useWakeLock handles request then release with success', async () => {
7272
});
7373

7474
test('useWakeLock handles request and throw an error', async () => {
75-
const requestError = new Error(
76-
'An error occured during `navigator.wakeLock.request` 💥'
77-
);
75+
const requestError = new Error('An error occured during `navigator.wakeLock.request` 💥');
7876
const handleError = jest.fn();
79-
jest
80-
.spyOn(window.navigator.wakeLock, 'request')
81-
.mockRejectedValueOnce(requestError);
82-
83-
const { result } = renderHook<
84-
WakeLockOptions,
85-
ReturnType<typeof useWakeLock>
86-
>((props) => useWakeLock(props), {
87-
initialProps: { onError: handleError },
88-
});
77+
jest.spyOn(window.navigator.wakeLock, 'request').mockRejectedValueOnce(requestError);
78+
79+
const { result } = renderHook(
80+
(props) => useWakeLock(props),
81+
{
82+
initialProps: { onError: handleError },
83+
},
84+
);
8985

9086
// Handle wakeLock request
9187
await act(async () => {
@@ -109,7 +105,7 @@ test('in development|test mode, a warning is displayed when calling `release` be
109105
});
110106

111107
expect(spyedConsoleWarn).toHaveBeenCalledWith(
112-
'[react-screen-wake-lock]: Calling `release` before `request` has no effect.'
108+
'[react-screen-wake-lock]: Calling `release` before `request` has no effect.',
113109
);
114110
});
115111

@@ -124,18 +120,18 @@ test('once WakeLock released and in development|test mode, a warning is displaye
124120
});
125121

126122
expect(spyedConsoleWarn).toHaveBeenCalledWith(
127-
'[react-screen-wake-lock]: Calling `release` before `request` has no effect.'
123+
'[react-screen-wake-lock]: Calling `release` before `request` has no effect.',
128124
);
129125
});
130126

131127
test('useWakeLock should call `onRequest` when request done with success', async () => {
132128
const handleRequest = jest.fn();
133-
const { result } = renderHook<
134-
WakeLockOptions,
135-
ReturnType<typeof useWakeLock>
136-
>((props) => useWakeLock(props), {
137-
initialProps: { onRequest: handleRequest },
138-
});
129+
const { result } = renderHook(
130+
(props) => useWakeLock(props),
131+
{
132+
initialProps: { onRequest: handleRequest },
133+
},
134+
);
139135

140136
await act(async () => void (await result.current.request()));
141137

@@ -152,19 +148,19 @@ test('in development|test show a warning if `request` is called more than once w
152148
});
153149

154150
expect(spyedConsoleWarn).toHaveBeenCalledWith(
155-
'[react-screen-wake-lock]: Calling `request` multiple times without `release` has no effect'
151+
'[react-screen-wake-lock]: Calling `request` multiple times without `release` has no effect',
156152
);
157153
expect(window.navigator.wakeLock.request).toHaveBeenCalledTimes(1);
158154
});
159155

160156
test('useWakeLock should call `onRelease` when wakeLockSentinel is released', async () => {
161157
const handleRelease = jest.fn();
162-
const { result } = renderHook<
163-
WakeLockOptions,
164-
ReturnType<typeof useWakeLock>
165-
>((props) => useWakeLock(props), {
166-
initialProps: { onRelease: handleRelease },
167-
});
158+
const { result } = renderHook(
159+
(props) => useWakeLock(props),
160+
{
161+
initialProps: { onRelease: handleRelease },
162+
},
163+
);
168164

169165
expect(handleRelease).not.toHaveBeenCalled();
170166

0 commit comments

Comments
 (0)