Skip to content

Commit 420696f

Browse files
committed
Implement react query
1 parent 2cdc35b commit 420696f

File tree

11 files changed

+583
-11
lines changed

11 files changed

+583
-11
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"changes":{"packages/fetch/package.json":"Patch","packages/react-query/package.json":"Minor"},"note":"Implement react-query","date":"2025-12-02T03:13:38.013730100Z"}

bun.lock

Lines changed: 46 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bunfig.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
coverage = true
33
coveragePathIgnorePatterns = ["node_modules", "**/dist/**"]
44
coverageSkipTestFiles = true
5+
preload = ["./packages/react-query/setup.ts"]

package.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,13 @@
44
"type": "module",
55
"private": true,
66
"devDependencies": {
7-
"@types/bun": "latest",
87
"@biomejs/biome": "^2.3",
9-
"husky": "^9"
8+
"@testing-library/react": "^16.3.0",
9+
"@testing-library/react-hooks": "^8.0.1",
10+
"@types/bun": "latest",
11+
"husky": "^9",
12+
"react": "^19.2.0",
13+
"react-dom": "^19.2.0"
1014
},
1115
"author": "JeongMin Oh",
1216
"license": "Apache-2.0",

packages/react-query/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,10 @@
2828
"@tanstack/react-query": "*"
2929
},
3030
"devDependencies": {
31+
"@testing-library/react-hooks": "^8.0.1",
3132
"@types/node": "^24.10",
3233
"@types/react": "^19.2",
34+
"happy-dom": "^20.0.11",
3335
"typescript": "^5.9"
3436
}
3537
}

packages/react-query/setup.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { beforeAll } from 'bun:test'
2+
3+
// Setup DOM environment for React testing
4+
if (typeof globalThis.document === 'undefined') {
5+
// @ts-expect-error - happy-dom types
6+
const { Window } = await import('happy-dom')
7+
const window = new Window()
8+
const document = window.document
9+
10+
// @ts-expect-error - setting global document
11+
globalThis.window = window
12+
// @ts-expect-error - setting global document
13+
globalThis.document = document
14+
// @ts-expect-error - setting global navigator
15+
globalThis.navigator = window.navigator
16+
// @ts-expect-error - setting global HTMLElement
17+
globalThis.HTMLElement = window.HTMLElement
18+
}
19+
20+
beforeAll(() => {
21+
// Ensure DOM is ready
22+
if (globalThis.document) {
23+
const root = globalThis.document.createElement('div')
24+
root.id = 'root'
25+
globalThis.document.body.appendChild(root)
26+
}
27+
})
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/** biome-ignore-all lint/suspicious/noExplicitAny: any is used to allow for flexibility in the type */
2+
import { expect, test } from 'bun:test'
3+
import { createApi } from '@devup-api/fetch'
4+
import { createQueryClient } from '../create-query-client'
5+
import { DevupQueryClient } from '../query-client'
6+
7+
test.each([
8+
['https://api.example.com'],
9+
['https://api.example.com/'],
10+
['http://localhost:3000'],
11+
['http://localhost:3000/'],
12+
] as const)('createQueryClient returns DevupQueryClient instance: %s', (baseUrl) => {
13+
const api = createApi({ baseUrl })
14+
const queryClient = createQueryClient(api)
15+
expect(queryClient).toBeInstanceOf(DevupQueryClient)
16+
})
17+
18+
test.each([
19+
['https://api.example.com', undefined],
20+
['https://api.example.com', {}],
21+
['https://api.example.com', { headers: { Authorization: 'Bearer token' } }],
22+
] as const)('createQueryClient accepts api with defaultOptions: %s', (baseUrl, defaultOptions) => {
23+
const api = createApi({ baseUrl, ...defaultOptions })
24+
const queryClient = createQueryClient(api)
25+
expect(queryClient).toBeInstanceOf(DevupQueryClient)
26+
})
27+
28+
test.each([
29+
['openapi.json'],
30+
['openapi2.json'],
31+
] as const)('createQueryClient accepts api with serverName: %s', (serverName) => {
32+
const api = createApi({
33+
baseUrl: 'https://api.example.com',
34+
serverName: serverName as any,
35+
})
36+
const queryClient = createQueryClient(api)
37+
expect(queryClient).toBeInstanceOf(DevupQueryClient)
38+
})
39+
40+
test('createQueryClient uses default serverName when not provided', () => {
41+
const api = createApi({ baseUrl: 'https://api.example.com' })
42+
const queryClient = createQueryClient(api)
43+
expect(queryClient).toBeInstanceOf(DevupQueryClient)
44+
})
45+
46+
test('createQueryClient uses empty baseUrl when not provided', () => {
47+
const api = createApi({})
48+
const queryClient = createQueryClient(api)
49+
expect(queryClient).toBeInstanceOf(DevupQueryClient)
50+
})
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { expect, test } from 'bun:test'
2+
import * as indexModule from '../index'
3+
4+
// Type imports to verify types are exported (compile-time check)
5+
6+
test('index.ts exports', () => {
7+
expect({ ...indexModule }).toEqual({
8+
createQueryClient: expect.any(Function),
9+
DevupQueryClient: expect.any(Function),
10+
})
11+
})

0 commit comments

Comments
 (0)