Skip to content

Commit 4dafa22

Browse files
committed
move mocks to another package
1 parent a3505b4 commit 4dafa22

File tree

11 files changed

+122
-68
lines changed

11 files changed

+122
-68
lines changed

examples/vite/package.json

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,20 @@
1010
"postinstall": "msw init"
1111
},
1212
"dependencies": {
13-
"@tanstack/react-query-devtools": "^5.66.9",
13+
"@tanstack/react-query-devtools": "^5.66.11",
1414
"react": "^19.0.0",
1515
"react-dom": "^19.0.0",
16-
"react-query-builder": "*"
16+
"react-query-builder": "*",
17+
"react-query-builder-example-mocks": "*"
1718
},
1819
"devDependencies": {
1920
"@types/react": "^19.0.10",
2021
"@types/react-dom": "^19.0.4",
2122
"@vitejs/plugin-react": "^4.3.4",
22-
"msw": "^2.7.1",
23-
"sass": "^1.85.0",
24-
"typescript": "^5.7.3",
25-
"vite": "^6.1.1"
23+
"msw": "^2.7.3",
24+
"sass": "^1.85.1",
25+
"typescript": "^5.8.2",
26+
"vite": "^6.2.0"
2627
},
2728
"msw": {
2829
"workerDirectory": "public"

examples/vite/public/mockServiceWorker.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* - Please do NOT serve this file on production.
99
*/
1010

11-
const PACKAGE_VERSION = '2.7.1'
11+
const PACKAGE_VERSION = '2.7.3'
1212
const INTEGRITY_CHECKSUM = '00729d72e3b82faf54ca8b9621dbb96f'
1313
const IS_MOCKED_RESPONSE = Symbol('isMockedResponse')
1414
const activeClientIds = new Set()

examples/vite/src/App.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
1-
import './mocks';
1+
import { setupWorker } from 'msw/browser';
22
import { useRef, useState } from 'react';
3-
import { CommentData, PostData, baseUrl } from './mocks';
3+
import { CommentData, PostData, baseUrl, mockHandlers } from 'react-query-builder-example-mocks';
44
import './App.css';
55
import { HttpQueryBuilder } from 'react-query-builder';
66
import { queryClient } from './client';
77

8+
await setupWorker(...mockHandlers).start({
9+
onUnhandledRequest: 'bypass',
10+
quiet: true,
11+
});
12+
813
const builder = new HttpQueryBuilder({
914
queryClient,
1015
syncChannel: new BroadcastChannel('react-query-builder'),

package-lock.json

Lines changed: 63 additions & 50 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"name": "react-query-builder-example-mocks",
3+
"private": true,
4+
"version": "0.0.0",
5+
"type": "module",
6+
"main": "./src/index.ts",
7+
"exports": {
8+
".": "./src/index.ts"
9+
},
10+
"scripts": {
11+
"start": "vite",
12+
"build": "tsc && vite build"
13+
},
14+
"dependencies": {},
15+
"devDependencies": {
16+
"msw": "^2.7.3",
17+
"typescript": "^5.8.2"
18+
}
19+
}
Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { http, HttpResponse, delay } from 'msw';
2-
import { setupWorker } from 'msw/browser';
32
import { createMockComments } from './comments';
43
import { PostData, createMockPosts } from './posts';
54

@@ -57,7 +56,7 @@ window.addEventListener('storage', (event) => {
5756
}
5857
});
5958

60-
const handlers = [
59+
export const mockHandlers = [
6160
http.post(`${baseUrl}/reset`, async () => {
6261
await delay();
6362
const allData = recreateMockData();
@@ -122,8 +121,3 @@ const handlers = [
122121
return HttpResponse.json(posts[postIndex]);
123122
}),
124123
];
125-
126-
await setupWorker(...handlers).start({
127-
onUnhandledRequest: 'bypass',
128-
quiet: true,
129-
});
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"compilerOptions": {
3+
"target": "ESNext",
4+
"lib": ["DOM", "DOM.Iterable", "ESNext"],
5+
"module": "ESNext",
6+
"skipLibCheck": true,
7+
/* Bundler mode */
8+
"moduleResolution": "bundler",
9+
"allowImportingTsExtensions": true,
10+
"resolveJsonModule": true,
11+
"isolatedModules": true,
12+
"noEmit": true,
13+
"jsx": "react-jsx",
14+
/* Linting */
15+
"strict": true,
16+
"noUnusedLocals": true,
17+
"noUnusedParameters": true,
18+
"noFallthroughCasesInSwitch": true
19+
},
20+
"include": ["src", "**/*.d.ts"]
21+
}

0 commit comments

Comments
 (0)