@tanstack/devtools-vite 0.3.5 → 0.3.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/esm/inject-plugin.d.ts +21 -0
- package/dist/esm/inject-plugin.js +228 -0
- package/dist/esm/inject-plugin.js.map +1 -0
- package/dist/esm/inject-plugin.test.d.ts +1 -0
- package/dist/esm/package-manager.d.ts +16 -0
- package/dist/esm/package-manager.js +139 -0
- package/dist/esm/package-manager.js.map +1 -0
- package/dist/esm/plugin.d.ts +7 -1
- package/dist/esm/plugin.js +186 -2
- package/dist/esm/plugin.js.map +1 -1
- package/dist/esm/utils.d.ts +3 -0
- package/dist/esm/utils.js +24 -1
- package/dist/esm/utils.js.map +1 -1
- package/package.json +2 -1
- package/src/inject-plugin.test.ts +1086 -0
- package/src/inject-plugin.ts +343 -0
- package/src/package-manager.ts +181 -0
- package/src/plugin.ts +242 -3
- package/src/utils.ts +14 -8
|
@@ -0,0 +1,1086 @@
|
|
|
1
|
+
import { describe, expect, test } from 'vitest'
|
|
2
|
+
import {
|
|
3
|
+
detectDevtoolsFile,
|
|
4
|
+
findDevtoolsComponentName,
|
|
5
|
+
transformAndInject,
|
|
6
|
+
} from './inject-plugin'
|
|
7
|
+
import { gen, parse } from './babel'
|
|
8
|
+
|
|
9
|
+
const removeEmptySpace = (str: string) => {
|
|
10
|
+
return str.replace(/\s/g, '').trim()
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
// Helper to test transformation without file I/O
|
|
14
|
+
const testTransform = (
|
|
15
|
+
code: string,
|
|
16
|
+
packageName: string,
|
|
17
|
+
pluginName: string,
|
|
18
|
+
pluginImport: {
|
|
19
|
+
importName: string
|
|
20
|
+
type: 'jsx' | 'function'
|
|
21
|
+
},
|
|
22
|
+
) => {
|
|
23
|
+
const ast = parse(code, {
|
|
24
|
+
sourceType: 'module',
|
|
25
|
+
plugins: ['jsx', 'typescript'],
|
|
26
|
+
})
|
|
27
|
+
|
|
28
|
+
const devtoolsComponentName = findDevtoolsComponentName(ast)
|
|
29
|
+
if (!devtoolsComponentName) {
|
|
30
|
+
return { transformed: false, code }
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const didTransform = transformAndInject(
|
|
34
|
+
ast,
|
|
35
|
+
{ packageName, pluginName, pluginImport },
|
|
36
|
+
devtoolsComponentName,
|
|
37
|
+
)
|
|
38
|
+
|
|
39
|
+
if (!didTransform) {
|
|
40
|
+
return { transformed: false, code }
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const result = gen(ast, { sourceMaps: false, retainLines: false })
|
|
44
|
+
return { transformed: true, code: result.code }
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
describe('inject-plugin', () => {
|
|
48
|
+
describe('detectDevtoolsFile', () => {
|
|
49
|
+
test('should detect named import from @tanstack/react-devtools', () => {
|
|
50
|
+
const code = `
|
|
51
|
+
import { TanStackDevtools } from '@tanstack/react-devtools'
|
|
52
|
+
`
|
|
53
|
+
expect(detectDevtoolsFile(code)).toBe(true)
|
|
54
|
+
})
|
|
55
|
+
|
|
56
|
+
test('should detect named import from @tanstack/solid-devtools', () => {
|
|
57
|
+
const code = `
|
|
58
|
+
import { TanStackDevtools } from '@tanstack/solid-devtools'
|
|
59
|
+
`
|
|
60
|
+
expect(detectDevtoolsFile(code)).toBe(true)
|
|
61
|
+
})
|
|
62
|
+
|
|
63
|
+
test('should detect namespace import', () => {
|
|
64
|
+
const code = `
|
|
65
|
+
import * as Devtools from '@tanstack/react-devtools'
|
|
66
|
+
`
|
|
67
|
+
expect(detectDevtoolsFile(code)).toBe(true)
|
|
68
|
+
})
|
|
69
|
+
|
|
70
|
+
test('should detect renamed named import', () => {
|
|
71
|
+
const code = `
|
|
72
|
+
import { TanStackDevtools as DevtoolsPanel } from '@tanstack/react-devtools'
|
|
73
|
+
`
|
|
74
|
+
expect(detectDevtoolsFile(code)).toBe(true)
|
|
75
|
+
})
|
|
76
|
+
|
|
77
|
+
test('should not detect non-devtools imports', () => {
|
|
78
|
+
const code = `
|
|
79
|
+
import React from 'react'
|
|
80
|
+
import { useState } from 'react'
|
|
81
|
+
`
|
|
82
|
+
expect(detectDevtoolsFile(code)).toBe(false)
|
|
83
|
+
})
|
|
84
|
+
|
|
85
|
+
test('should not detect files without imports', () => {
|
|
86
|
+
const code = `
|
|
87
|
+
function App() {
|
|
88
|
+
return <div>Hello</div>
|
|
89
|
+
}
|
|
90
|
+
`
|
|
91
|
+
expect(detectDevtoolsFile(code)).toBe(false)
|
|
92
|
+
})
|
|
93
|
+
|
|
94
|
+
test('should handle invalid code gracefully', () => {
|
|
95
|
+
const code = `
|
|
96
|
+
this is not valid javascript{{{
|
|
97
|
+
`
|
|
98
|
+
expect(detectDevtoolsFile(code)).toBe(false)
|
|
99
|
+
})
|
|
100
|
+
})
|
|
101
|
+
|
|
102
|
+
describe('named import pattern', () => {
|
|
103
|
+
test('should add plugin to existing empty plugins array', () => {
|
|
104
|
+
const code = `
|
|
105
|
+
import { TanStackDevtools } from '@tanstack/react-devtools'
|
|
106
|
+
|
|
107
|
+
function App() {
|
|
108
|
+
return <TanStackDevtools plugins={[]} />
|
|
109
|
+
}
|
|
110
|
+
`
|
|
111
|
+
|
|
112
|
+
const result = testTransform(
|
|
113
|
+
code,
|
|
114
|
+
'@tanstack/react-query-devtools',
|
|
115
|
+
'TanStack Query',
|
|
116
|
+
{
|
|
117
|
+
importName: 'ReactQueryDevtoolsPanel',
|
|
118
|
+
type: 'jsx',
|
|
119
|
+
},
|
|
120
|
+
)
|
|
121
|
+
|
|
122
|
+
expect(result.transformed).toBe(true)
|
|
123
|
+
expect(removeEmptySpace(result.code)).toBe(
|
|
124
|
+
removeEmptySpace(`
|
|
125
|
+
import { TanStackDevtools } from '@tanstack/react-devtools';
|
|
126
|
+
import { ReactQueryDevtoolsPanel } from "@tanstack/react-query-devtools";
|
|
127
|
+
|
|
128
|
+
function App() {
|
|
129
|
+
return <TanStackDevtools plugins={[{
|
|
130
|
+
name: "TanStack Query",
|
|
131
|
+
render: <ReactQueryDevtoolsPanel />
|
|
132
|
+
}]} />;
|
|
133
|
+
}
|
|
134
|
+
`),
|
|
135
|
+
)
|
|
136
|
+
})
|
|
137
|
+
|
|
138
|
+
test('should add plugin to existing plugins array with other plugins', () => {
|
|
139
|
+
const code = `
|
|
140
|
+
import { TanStackDevtools } from '@tanstack/react-devtools'
|
|
141
|
+
import { OtherPlugin } from '@tanstack/other-plugin'
|
|
142
|
+
|
|
143
|
+
function App() {
|
|
144
|
+
return <TanStackDevtools plugins={[
|
|
145
|
+
{ name: 'other', render: <OtherPlugin /> }
|
|
146
|
+
]} />
|
|
147
|
+
}
|
|
148
|
+
`
|
|
149
|
+
|
|
150
|
+
const result = testTransform(
|
|
151
|
+
code,
|
|
152
|
+
'@tanstack/react-query-devtools',
|
|
153
|
+
'TanStack Query',
|
|
154
|
+
{
|
|
155
|
+
importName: 'ReactQueryDevtoolsPanel',
|
|
156
|
+
type: 'jsx',
|
|
157
|
+
},
|
|
158
|
+
)
|
|
159
|
+
|
|
160
|
+
expect(result.transformed).toBe(true)
|
|
161
|
+
expect(removeEmptySpace(result.code)).toBe(
|
|
162
|
+
removeEmptySpace(`
|
|
163
|
+
import { TanStackDevtools } from '@tanstack/react-devtools';
|
|
164
|
+
import { OtherPlugin } from '@tanstack/other-plugin';
|
|
165
|
+
import { ReactQueryDevtoolsPanel } from "@tanstack/react-query-devtools";
|
|
166
|
+
|
|
167
|
+
function App() {
|
|
168
|
+
return <TanStackDevtools plugins={[
|
|
169
|
+
{ name: 'other', render: <OtherPlugin /> },
|
|
170
|
+
{
|
|
171
|
+
name: "TanStack Query",
|
|
172
|
+
render: <ReactQueryDevtoolsPanel />
|
|
173
|
+
}
|
|
174
|
+
]} />;
|
|
175
|
+
}
|
|
176
|
+
`),
|
|
177
|
+
)
|
|
178
|
+
})
|
|
179
|
+
|
|
180
|
+
test('should create plugins prop if it does not exist', () => {
|
|
181
|
+
const code = `
|
|
182
|
+
import { TanStackDevtools } from '@tanstack/react-devtools'
|
|
183
|
+
|
|
184
|
+
function App() {
|
|
185
|
+
return <TanStackDevtools />
|
|
186
|
+
}
|
|
187
|
+
`
|
|
188
|
+
|
|
189
|
+
const result = testTransform(
|
|
190
|
+
code,
|
|
191
|
+
'@tanstack/react-query-devtools',
|
|
192
|
+
'TanStack Query',
|
|
193
|
+
{
|
|
194
|
+
importName: 'ReactQueryDevtoolsPanel',
|
|
195
|
+
type: 'jsx',
|
|
196
|
+
},
|
|
197
|
+
)
|
|
198
|
+
|
|
199
|
+
expect(result.transformed).toBe(true)
|
|
200
|
+
expect(removeEmptySpace(result.code)).toBe(
|
|
201
|
+
removeEmptySpace(`
|
|
202
|
+
import { TanStackDevtools } from '@tanstack/react-devtools';
|
|
203
|
+
import { ReactQueryDevtoolsPanel } from "@tanstack/react-query-devtools";
|
|
204
|
+
|
|
205
|
+
function App() {
|
|
206
|
+
return <TanStackDevtools plugins={[{
|
|
207
|
+
name: "TanStack Query",
|
|
208
|
+
render: <ReactQueryDevtoolsPanel />
|
|
209
|
+
}]} />;
|
|
210
|
+
}
|
|
211
|
+
`),
|
|
212
|
+
)
|
|
213
|
+
})
|
|
214
|
+
|
|
215
|
+
test('should create plugins prop with other existing props', () => {
|
|
216
|
+
const code = `
|
|
217
|
+
import { TanStackDevtools } from '@tanstack/react-devtools'
|
|
218
|
+
|
|
219
|
+
function App() {
|
|
220
|
+
return <TanStackDevtools position="bottom-right" />
|
|
221
|
+
}
|
|
222
|
+
`
|
|
223
|
+
|
|
224
|
+
const result = testTransform(
|
|
225
|
+
code,
|
|
226
|
+
'@tanstack/react-query-devtools',
|
|
227
|
+
'TanStack Query',
|
|
228
|
+
{
|
|
229
|
+
importName: 'ReactQueryDevtoolsPanel',
|
|
230
|
+
type: 'jsx',
|
|
231
|
+
},
|
|
232
|
+
)
|
|
233
|
+
|
|
234
|
+
expect(result.transformed).toBe(true)
|
|
235
|
+
expect(removeEmptySpace(result.code)).toBe(
|
|
236
|
+
removeEmptySpace(`
|
|
237
|
+
import { TanStackDevtools } from '@tanstack/react-devtools';
|
|
238
|
+
import { ReactQueryDevtoolsPanel } from "@tanstack/react-query-devtools";
|
|
239
|
+
|
|
240
|
+
function App() {
|
|
241
|
+
return <TanStackDevtools position="bottom-right" plugins={[{
|
|
242
|
+
name: "TanStack Query",
|
|
243
|
+
render: <ReactQueryDevtoolsPanel />
|
|
244
|
+
}]} />;
|
|
245
|
+
}
|
|
246
|
+
`),
|
|
247
|
+
)
|
|
248
|
+
})
|
|
249
|
+
|
|
250
|
+
test('should not add plugin if it already exists', () => {
|
|
251
|
+
const code = `
|
|
252
|
+
import { TanStackDevtools } from '@tanstack/react-devtools'
|
|
253
|
+
import { ReactQueryDevtoolsPanel } from '@tanstack/react-query-devtools'
|
|
254
|
+
|
|
255
|
+
function App() {
|
|
256
|
+
return <TanStackDevtools plugins={[
|
|
257
|
+
{ name: 'TanStack Query', render: <ReactQueryDevtoolsPanel /> }
|
|
258
|
+
]} />
|
|
259
|
+
}
|
|
260
|
+
`
|
|
261
|
+
|
|
262
|
+
const result = testTransform(
|
|
263
|
+
code,
|
|
264
|
+
'@tanstack/react-query-devtools',
|
|
265
|
+
'TanStack Query',
|
|
266
|
+
{
|
|
267
|
+
importName: 'ReactQueryDevtoolsPanel',
|
|
268
|
+
type: 'jsx',
|
|
269
|
+
},
|
|
270
|
+
)
|
|
271
|
+
|
|
272
|
+
expect(result.transformed).toBe(false)
|
|
273
|
+
})
|
|
274
|
+
})
|
|
275
|
+
|
|
276
|
+
describe('renamed named import pattern', () => {
|
|
277
|
+
test('should handle renamed named import', () => {
|
|
278
|
+
const code = `
|
|
279
|
+
import { TanStackDevtools as DevtoolsPanel } from '@tanstack/react-devtools'
|
|
280
|
+
|
|
281
|
+
function App() {
|
|
282
|
+
return <DevtoolsPanel plugins={[]} />
|
|
283
|
+
}
|
|
284
|
+
`
|
|
285
|
+
|
|
286
|
+
const result = testTransform(
|
|
287
|
+
code,
|
|
288
|
+
'@tanstack/react-query-devtools',
|
|
289
|
+
'TanStack Query',
|
|
290
|
+
{
|
|
291
|
+
importName: 'ReactQueryDevtoolsPanel',
|
|
292
|
+
type: 'jsx',
|
|
293
|
+
},
|
|
294
|
+
)
|
|
295
|
+
|
|
296
|
+
expect(result.transformed).toBe(true)
|
|
297
|
+
expect(removeEmptySpace(result.code)).toBe(
|
|
298
|
+
removeEmptySpace(`
|
|
299
|
+
import { TanStackDevtools as DevtoolsPanel } from '@tanstack/react-devtools';
|
|
300
|
+
import { ReactQueryDevtoolsPanel } from "@tanstack/react-query-devtools";
|
|
301
|
+
|
|
302
|
+
function App() {
|
|
303
|
+
return <DevtoolsPanel plugins={[{
|
|
304
|
+
name: "TanStack Query",
|
|
305
|
+
render: <ReactQueryDevtoolsPanel />
|
|
306
|
+
}]} />;
|
|
307
|
+
}
|
|
308
|
+
`),
|
|
309
|
+
)
|
|
310
|
+
})
|
|
311
|
+
|
|
312
|
+
test('should handle renamed import without plugins prop', () => {
|
|
313
|
+
const code = `
|
|
314
|
+
import { TanStackDevtools as MyDevtools } from '@tanstack/solid-devtools'
|
|
315
|
+
|
|
316
|
+
function App() {
|
|
317
|
+
return <MyDevtools />
|
|
318
|
+
}
|
|
319
|
+
`
|
|
320
|
+
|
|
321
|
+
const result = testTransform(
|
|
322
|
+
code,
|
|
323
|
+
'@tanstack/react-query-devtools',
|
|
324
|
+
'TanStack Query',
|
|
325
|
+
{
|
|
326
|
+
importName: 'ReactQueryDevtoolsPanel',
|
|
327
|
+
type: 'jsx',
|
|
328
|
+
},
|
|
329
|
+
)
|
|
330
|
+
|
|
331
|
+
expect(result.transformed).toBe(true)
|
|
332
|
+
expect(removeEmptySpace(result.code)).toBe(
|
|
333
|
+
removeEmptySpace(`
|
|
334
|
+
import { TanStackDevtools as MyDevtools } from '@tanstack/solid-devtools';
|
|
335
|
+
import { ReactQueryDevtoolsPanel } from "@tanstack/react-query-devtools";
|
|
336
|
+
|
|
337
|
+
function App() {
|
|
338
|
+
return <MyDevtools plugins={[{
|
|
339
|
+
name: "TanStack Query",
|
|
340
|
+
render: <ReactQueryDevtoolsPanel />
|
|
341
|
+
}]} />;
|
|
342
|
+
}
|
|
343
|
+
`),
|
|
344
|
+
)
|
|
345
|
+
})
|
|
346
|
+
})
|
|
347
|
+
|
|
348
|
+
describe('namespace import pattern', () => {
|
|
349
|
+
test('should handle namespace import', () => {
|
|
350
|
+
const code = `
|
|
351
|
+
import * as DevtoolsModule from '@tanstack/react-devtools'
|
|
352
|
+
|
|
353
|
+
function App() {
|
|
354
|
+
return <DevtoolsModule.TanStackDevtools plugins={[]} />
|
|
355
|
+
}
|
|
356
|
+
`
|
|
357
|
+
|
|
358
|
+
const result = testTransform(
|
|
359
|
+
code,
|
|
360
|
+
'@tanstack/react-query-devtools',
|
|
361
|
+
'TanStack Query',
|
|
362
|
+
{
|
|
363
|
+
importName: 'ReactQueryDevtoolsPanel',
|
|
364
|
+
type: 'jsx',
|
|
365
|
+
},
|
|
366
|
+
)
|
|
367
|
+
|
|
368
|
+
expect(result.transformed).toBe(true)
|
|
369
|
+
expect(removeEmptySpace(result.code)).toBe(
|
|
370
|
+
removeEmptySpace(`
|
|
371
|
+
import * as DevtoolsModule from '@tanstack/react-devtools';
|
|
372
|
+
import { ReactQueryDevtoolsPanel } from "@tanstack/react-query-devtools";
|
|
373
|
+
|
|
374
|
+
function App() {
|
|
375
|
+
return <DevtoolsModule.TanStackDevtools plugins={[{
|
|
376
|
+
name: "TanStack Query",
|
|
377
|
+
render: <ReactQueryDevtoolsPanel />
|
|
378
|
+
}]} />;
|
|
379
|
+
}
|
|
380
|
+
`),
|
|
381
|
+
)
|
|
382
|
+
})
|
|
383
|
+
|
|
384
|
+
test('should handle namespace import without plugins prop', () => {
|
|
385
|
+
const code = `
|
|
386
|
+
import * as TSD from '@tanstack/solid-devtools'
|
|
387
|
+
|
|
388
|
+
function App() {
|
|
389
|
+
return <TSD.TanStackDevtools />
|
|
390
|
+
}
|
|
391
|
+
`
|
|
392
|
+
|
|
393
|
+
const result = testTransform(
|
|
394
|
+
code,
|
|
395
|
+
'@tanstack/solid-router-devtools',
|
|
396
|
+
'TanStack Router',
|
|
397
|
+
{
|
|
398
|
+
importName: 'SolidRouterDevtoolsPanel',
|
|
399
|
+
type: 'jsx',
|
|
400
|
+
},
|
|
401
|
+
)
|
|
402
|
+
|
|
403
|
+
expect(result.transformed).toBe(true)
|
|
404
|
+
expect(removeEmptySpace(result.code)).toBe(
|
|
405
|
+
removeEmptySpace(`
|
|
406
|
+
import * as TSD from '@tanstack/solid-devtools';
|
|
407
|
+
import { SolidRouterDevtoolsPanel } from "@tanstack/solid-router-devtools";
|
|
408
|
+
|
|
409
|
+
function App() {
|
|
410
|
+
return <TSD.TanStackDevtools plugins={[{
|
|
411
|
+
name: "TanStack Router",
|
|
412
|
+
render: <SolidRouterDevtoolsPanel />
|
|
413
|
+
}]} />;
|
|
414
|
+
}
|
|
415
|
+
`),
|
|
416
|
+
)
|
|
417
|
+
})
|
|
418
|
+
})
|
|
419
|
+
|
|
420
|
+
describe('different plugin types', () => {
|
|
421
|
+
test('should handle router devtools', () => {
|
|
422
|
+
const code = `
|
|
423
|
+
import { TanStackDevtools } from '@tanstack/react-devtools'
|
|
424
|
+
|
|
425
|
+
function App() {
|
|
426
|
+
return <TanStackDevtools plugins={[]} />
|
|
427
|
+
}
|
|
428
|
+
`
|
|
429
|
+
|
|
430
|
+
const result = testTransform(
|
|
431
|
+
code,
|
|
432
|
+
'@tanstack/react-router-devtools',
|
|
433
|
+
'TanStack Router',
|
|
434
|
+
{
|
|
435
|
+
importName: 'ReactRouterDevtoolsPanel',
|
|
436
|
+
type: 'jsx',
|
|
437
|
+
},
|
|
438
|
+
)
|
|
439
|
+
|
|
440
|
+
expect(result.transformed).toBe(true)
|
|
441
|
+
expect(removeEmptySpace(result.code)).toBe(
|
|
442
|
+
removeEmptySpace(`
|
|
443
|
+
import { TanStackDevtools } from '@tanstack/react-devtools';
|
|
444
|
+
import { ReactRouterDevtoolsPanel } from "@tanstack/react-router-devtools";
|
|
445
|
+
|
|
446
|
+
function App() {
|
|
447
|
+
return <TanStackDevtools plugins={[{
|
|
448
|
+
name: "TanStack Router",
|
|
449
|
+
render: <ReactRouterDevtoolsPanel />
|
|
450
|
+
}]} />;
|
|
451
|
+
}
|
|
452
|
+
`),
|
|
453
|
+
)
|
|
454
|
+
})
|
|
455
|
+
|
|
456
|
+
test('should handle form devtools', () => {
|
|
457
|
+
const code = `
|
|
458
|
+
import { TanStackDevtools } from '@tanstack/solid-devtools'
|
|
459
|
+
|
|
460
|
+
function App() {
|
|
461
|
+
return <TanStackDevtools />
|
|
462
|
+
}
|
|
463
|
+
`
|
|
464
|
+
|
|
465
|
+
const result = testTransform(
|
|
466
|
+
code,
|
|
467
|
+
'@tanstack/react-form-devtools',
|
|
468
|
+
'TanStack Form',
|
|
469
|
+
{
|
|
470
|
+
importName: 'ReactFormDevtoolsPanel',
|
|
471
|
+
type: 'jsx',
|
|
472
|
+
},
|
|
473
|
+
)
|
|
474
|
+
|
|
475
|
+
expect(result.transformed).toBe(true)
|
|
476
|
+
expect(removeEmptySpace(result.code)).toBe(
|
|
477
|
+
removeEmptySpace(`
|
|
478
|
+
import { TanStackDevtools } from '@tanstack/solid-devtools';
|
|
479
|
+
import { ReactFormDevtoolsPanel } from "@tanstack/react-form-devtools";
|
|
480
|
+
|
|
481
|
+
function App() {
|
|
482
|
+
return <TanStackDevtools plugins={[{
|
|
483
|
+
name: "TanStack Form",
|
|
484
|
+
render: <ReactFormDevtoolsPanel />
|
|
485
|
+
}]} />;
|
|
486
|
+
}
|
|
487
|
+
`),
|
|
488
|
+
)
|
|
489
|
+
})
|
|
490
|
+
|
|
491
|
+
test('should handle query devtools', () => {
|
|
492
|
+
const code = `
|
|
493
|
+
import { TanStackDevtools } from '@tanstack/vue-devtools'
|
|
494
|
+
|
|
495
|
+
function App() {
|
|
496
|
+
return <TanStackDevtools plugins={[]} />
|
|
497
|
+
}
|
|
498
|
+
`
|
|
499
|
+
|
|
500
|
+
const result = testTransform(
|
|
501
|
+
code,
|
|
502
|
+
'@tanstack/react-query-devtools',
|
|
503
|
+
'TanStack Query',
|
|
504
|
+
{
|
|
505
|
+
importName: 'ReactQueryDevtoolsPanel',
|
|
506
|
+
type: 'jsx',
|
|
507
|
+
},
|
|
508
|
+
)
|
|
509
|
+
|
|
510
|
+
expect(result.transformed).toBe(true)
|
|
511
|
+
expect(removeEmptySpace(result.code)).toBe(
|
|
512
|
+
removeEmptySpace(`
|
|
513
|
+
import { TanStackDevtools } from '@tanstack/vue-devtools';
|
|
514
|
+
import { ReactQueryDevtoolsPanel } from "@tanstack/react-query-devtools";
|
|
515
|
+
|
|
516
|
+
function App() {
|
|
517
|
+
return <TanStackDevtools plugins={[{
|
|
518
|
+
name: "TanStack Query",
|
|
519
|
+
render: <ReactQueryDevtoolsPanel />
|
|
520
|
+
}]} />;
|
|
521
|
+
}
|
|
522
|
+
`),
|
|
523
|
+
)
|
|
524
|
+
})
|
|
525
|
+
})
|
|
526
|
+
|
|
527
|
+
describe('edge cases', () => {
|
|
528
|
+
test('should not transform files without TanStackDevtools component', () => {
|
|
529
|
+
const code = `
|
|
530
|
+
import { TanStackDevtools } from '@tanstack/react-devtools'
|
|
531
|
+
|
|
532
|
+
function App() {
|
|
533
|
+
return <div>Hello World</div>
|
|
534
|
+
}
|
|
535
|
+
`
|
|
536
|
+
|
|
537
|
+
const result = testTransform(
|
|
538
|
+
code,
|
|
539
|
+
'@tanstack/react-query-devtools',
|
|
540
|
+
'TanStack Query',
|
|
541
|
+
{
|
|
542
|
+
importName: 'ReactQueryDevtoolsPanel',
|
|
543
|
+
type: 'jsx',
|
|
544
|
+
},
|
|
545
|
+
)
|
|
546
|
+
|
|
547
|
+
expect(result.transformed).toBe(false)
|
|
548
|
+
})
|
|
549
|
+
|
|
550
|
+
test('should handle TanStackDevtools with children', () => {
|
|
551
|
+
const code = `
|
|
552
|
+
import { TanStackDevtools } from '@tanstack/react-devtools'
|
|
553
|
+
|
|
554
|
+
function App() {
|
|
555
|
+
return (
|
|
556
|
+
<TanStackDevtools plugins={[]}>
|
|
557
|
+
<div>Custom content</div>
|
|
558
|
+
</TanStackDevtools>
|
|
559
|
+
)
|
|
560
|
+
}
|
|
561
|
+
`
|
|
562
|
+
|
|
563
|
+
const result = testTransform(
|
|
564
|
+
code,
|
|
565
|
+
'@tanstack/react-query-devtools',
|
|
566
|
+
'TanStack Query',
|
|
567
|
+
{
|
|
568
|
+
importName: 'ReactQueryDevtoolsPanel',
|
|
569
|
+
type: 'jsx',
|
|
570
|
+
},
|
|
571
|
+
)
|
|
572
|
+
|
|
573
|
+
expect(result.transformed).toBe(true)
|
|
574
|
+
expect(removeEmptySpace(result.code)).toBe(
|
|
575
|
+
removeEmptySpace(`
|
|
576
|
+
import { TanStackDevtools } from '@tanstack/react-devtools';
|
|
577
|
+
import { ReactQueryDevtoolsPanel } from "@tanstack/react-query-devtools";
|
|
578
|
+
|
|
579
|
+
function App() {
|
|
580
|
+
return <TanStackDevtools plugins={[{
|
|
581
|
+
name: "TanStack Query",
|
|
582
|
+
render: <ReactQueryDevtoolsPanel />
|
|
583
|
+
}]}>
|
|
584
|
+
<div>Custom content</div>
|
|
585
|
+
</TanStackDevtools>;
|
|
586
|
+
}
|
|
587
|
+
`),
|
|
588
|
+
)
|
|
589
|
+
})
|
|
590
|
+
|
|
591
|
+
test('should handle multiple TanStackDevtools in same file', () => {
|
|
592
|
+
const code = `
|
|
593
|
+
import { TanStackDevtools } from '@tanstack/react-devtools'
|
|
594
|
+
|
|
595
|
+
function App() {
|
|
596
|
+
return (
|
|
597
|
+
<>
|
|
598
|
+
<TanStackDevtools plugins={[]} />
|
|
599
|
+
<TanStackDevtools plugins={[]} />
|
|
600
|
+
</>
|
|
601
|
+
)
|
|
602
|
+
}
|
|
603
|
+
`
|
|
604
|
+
|
|
605
|
+
const result = testTransform(
|
|
606
|
+
code,
|
|
607
|
+
'@tanstack/react-query-devtools',
|
|
608
|
+
'TanStack Query',
|
|
609
|
+
{
|
|
610
|
+
importName: 'ReactQueryDevtoolsPanel',
|
|
611
|
+
type: 'jsx',
|
|
612
|
+
},
|
|
613
|
+
)
|
|
614
|
+
|
|
615
|
+
expect(result.transformed).toBe(true)
|
|
616
|
+
expect(removeEmptySpace(result.code)).toBe(
|
|
617
|
+
removeEmptySpace(`
|
|
618
|
+
import { TanStackDevtools } from '@tanstack/react-devtools';
|
|
619
|
+
import { ReactQueryDevtoolsPanel } from "@tanstack/react-query-devtools";
|
|
620
|
+
|
|
621
|
+
function App() {
|
|
622
|
+
return <>
|
|
623
|
+
<TanStackDevtools plugins={[{
|
|
624
|
+
name: "TanStack Query",
|
|
625
|
+
render: <ReactQueryDevtoolsPanel />
|
|
626
|
+
}]} />
|
|
627
|
+
<TanStackDevtools plugins={[{
|
|
628
|
+
name: "TanStack Query",
|
|
629
|
+
render: <ReactQueryDevtoolsPanel />
|
|
630
|
+
}]} />
|
|
631
|
+
</>;
|
|
632
|
+
}
|
|
633
|
+
`),
|
|
634
|
+
)
|
|
635
|
+
})
|
|
636
|
+
|
|
637
|
+
test('should handle TanStackDevtools deeply nested', () => {
|
|
638
|
+
const code = `
|
|
639
|
+
import { TanStackDevtools } from '@tanstack/react-devtools'
|
|
640
|
+
|
|
641
|
+
function App() {
|
|
642
|
+
return (
|
|
643
|
+
<div>
|
|
644
|
+
<header>
|
|
645
|
+
<nav>
|
|
646
|
+
<TanStackDevtools plugins={[]} />
|
|
647
|
+
</nav>
|
|
648
|
+
</header>
|
|
649
|
+
</div>
|
|
650
|
+
)
|
|
651
|
+
}
|
|
652
|
+
`
|
|
653
|
+
|
|
654
|
+
const result = testTransform(
|
|
655
|
+
code,
|
|
656
|
+
'@tanstack/react-query-devtools',
|
|
657
|
+
'TanStack Query',
|
|
658
|
+
{
|
|
659
|
+
importName: 'ReactQueryDevtoolsPanel',
|
|
660
|
+
type: 'jsx',
|
|
661
|
+
},
|
|
662
|
+
)
|
|
663
|
+
|
|
664
|
+
expect(result.transformed).toBe(true)
|
|
665
|
+
expect(removeEmptySpace(result.code)).toBe(
|
|
666
|
+
removeEmptySpace(`
|
|
667
|
+
import { TanStackDevtools } from '@tanstack/react-devtools';
|
|
668
|
+
import { ReactQueryDevtoolsPanel } from "@tanstack/react-query-devtools";
|
|
669
|
+
|
|
670
|
+
function App() {
|
|
671
|
+
return <div>
|
|
672
|
+
<header>
|
|
673
|
+
<nav>
|
|
674
|
+
<TanStackDevtools plugins={[{
|
|
675
|
+
name: "TanStack Query",
|
|
676
|
+
render: <ReactQueryDevtoolsPanel />
|
|
677
|
+
}]} />
|
|
678
|
+
</nav>
|
|
679
|
+
</header>
|
|
680
|
+
</div>;
|
|
681
|
+
}
|
|
682
|
+
`),
|
|
683
|
+
)
|
|
684
|
+
})
|
|
685
|
+
|
|
686
|
+
test('should preserve existing code formatting and structure', () => {
|
|
687
|
+
const code = `
|
|
688
|
+
import { TanStackDevtools } from '@tanstack/react-devtools'
|
|
689
|
+
import { useState } from 'react'
|
|
690
|
+
|
|
691
|
+
function App() {
|
|
692
|
+
const [count, setCount] = useState(0)
|
|
693
|
+
|
|
694
|
+
return (
|
|
695
|
+
<div>
|
|
696
|
+
<button onClick={() => setCount(count + 1)}>
|
|
697
|
+
Count: {count}
|
|
698
|
+
</button>
|
|
699
|
+
<TanStackDevtools />
|
|
700
|
+
</div>
|
|
701
|
+
)
|
|
702
|
+
}
|
|
703
|
+
`
|
|
704
|
+
|
|
705
|
+
const result = testTransform(
|
|
706
|
+
code,
|
|
707
|
+
'@tanstack/react-query-devtools',
|
|
708
|
+
'TanStack Query',
|
|
709
|
+
{
|
|
710
|
+
importName: 'ReactQueryDevtoolsPanel',
|
|
711
|
+
type: 'jsx',
|
|
712
|
+
},
|
|
713
|
+
)
|
|
714
|
+
|
|
715
|
+
expect(result.transformed).toBe(true)
|
|
716
|
+
expect(removeEmptySpace(result.code)).toBe(
|
|
717
|
+
removeEmptySpace(`
|
|
718
|
+
import { TanStackDevtools } from '@tanstack/react-devtools';
|
|
719
|
+
import { useState } from 'react';
|
|
720
|
+
import { ReactQueryDevtoolsPanel } from "@tanstack/react-query-devtools";
|
|
721
|
+
|
|
722
|
+
function App() {
|
|
723
|
+
const [count, setCount] = useState(0);
|
|
724
|
+
return <div>
|
|
725
|
+
<button onClick={() => setCount(count + 1)}>
|
|
726
|
+
Count: {count}
|
|
727
|
+
</button>
|
|
728
|
+
<TanStackDevtools plugins={[{
|
|
729
|
+
name: "TanStack Query",
|
|
730
|
+
render: <ReactQueryDevtoolsPanel />
|
|
731
|
+
}]} />
|
|
732
|
+
</div>;
|
|
733
|
+
}
|
|
734
|
+
`),
|
|
735
|
+
)
|
|
736
|
+
})
|
|
737
|
+
|
|
738
|
+
test('should handle TypeScript code', () => {
|
|
739
|
+
const code = `
|
|
740
|
+
import { TanStackDevtools } from '@tanstack/react-devtools'
|
|
741
|
+
import type { FC } from 'react'
|
|
742
|
+
|
|
743
|
+
const App: FC = () => {
|
|
744
|
+
return <TanStackDevtools plugins={[]} />
|
|
745
|
+
}
|
|
746
|
+
`
|
|
747
|
+
|
|
748
|
+
const result = testTransform(
|
|
749
|
+
code,
|
|
750
|
+
'@tanstack/react-query-devtools',
|
|
751
|
+
'TanStack Query',
|
|
752
|
+
{
|
|
753
|
+
importName: 'ReactQueryDevtoolsPanel',
|
|
754
|
+
type: 'jsx',
|
|
755
|
+
},
|
|
756
|
+
)
|
|
757
|
+
|
|
758
|
+
expect(result.transformed).toBe(true)
|
|
759
|
+
expect(removeEmptySpace(result.code)).toBe(
|
|
760
|
+
removeEmptySpace(`
|
|
761
|
+
import { TanStackDevtools } from '@tanstack/react-devtools';
|
|
762
|
+
import type { FC } from 'react';
|
|
763
|
+
import { ReactQueryDevtoolsPanel } from "@tanstack/react-query-devtools";
|
|
764
|
+
|
|
765
|
+
const App: FC = () => {
|
|
766
|
+
return <TanStackDevtools plugins={[{
|
|
767
|
+
name: "TanStack Query",
|
|
768
|
+
render: <ReactQueryDevtoolsPanel />
|
|
769
|
+
}]} />;
|
|
770
|
+
};
|
|
771
|
+
`),
|
|
772
|
+
)
|
|
773
|
+
})
|
|
774
|
+
|
|
775
|
+
test('should handle plugins array with trailing comma', () => {
|
|
776
|
+
const code = `
|
|
777
|
+
import { TanStackDevtools } from '@tanstack/react-devtools'
|
|
778
|
+
|
|
779
|
+
function App() {
|
|
780
|
+
return <TanStackDevtools plugins={[
|
|
781
|
+
{ name: 'other', render: <OtherPlugin /> },
|
|
782
|
+
]} />
|
|
783
|
+
}
|
|
784
|
+
`
|
|
785
|
+
|
|
786
|
+
const result = testTransform(
|
|
787
|
+
code,
|
|
788
|
+
'@tanstack/react-query-devtools',
|
|
789
|
+
'TanStack Query',
|
|
790
|
+
{
|
|
791
|
+
importName: 'ReactQueryDevtoolsPanel',
|
|
792
|
+
type: 'jsx',
|
|
793
|
+
},
|
|
794
|
+
)
|
|
795
|
+
|
|
796
|
+
expect(result.transformed).toBe(true)
|
|
797
|
+
expect(removeEmptySpace(result.code)).toBe(
|
|
798
|
+
removeEmptySpace(`
|
|
799
|
+
import { TanStackDevtools } from '@tanstack/react-devtools';
|
|
800
|
+
import { ReactQueryDevtoolsPanel } from "@tanstack/react-query-devtools";
|
|
801
|
+
|
|
802
|
+
function App() {
|
|
803
|
+
return <TanStackDevtools plugins={[
|
|
804
|
+
{ name: 'other', render: <OtherPlugin /> },
|
|
805
|
+
{
|
|
806
|
+
name: "TanStack Query",
|
|
807
|
+
render: <ReactQueryDevtoolsPanel />
|
|
808
|
+
}
|
|
809
|
+
]} />;
|
|
810
|
+
}
|
|
811
|
+
`),
|
|
812
|
+
)
|
|
813
|
+
})
|
|
814
|
+
|
|
815
|
+
test('should not transform if devtools import not found', () => {
|
|
816
|
+
const code = `
|
|
817
|
+
import { SomeOtherComponent } from 'some-package'
|
|
818
|
+
|
|
819
|
+
function App() {
|
|
820
|
+
return <SomeOtherComponent />
|
|
821
|
+
}
|
|
822
|
+
`
|
|
823
|
+
|
|
824
|
+
const result = testTransform(
|
|
825
|
+
code,
|
|
826
|
+
'@tanstack/react-query-devtools',
|
|
827
|
+
'TanStack Query',
|
|
828
|
+
{
|
|
829
|
+
importName: 'ReactQueryDevtoolsPanel',
|
|
830
|
+
type: 'jsx',
|
|
831
|
+
},
|
|
832
|
+
)
|
|
833
|
+
|
|
834
|
+
expect(result.transformed).toBe(false)
|
|
835
|
+
})
|
|
836
|
+
})
|
|
837
|
+
|
|
838
|
+
describe('function-based plugins', () => {
|
|
839
|
+
test('should add function plugin to empty plugins array', () => {
|
|
840
|
+
const code = `
|
|
841
|
+
import { TanStackDevtools } from '@tanstack/react-devtools'
|
|
842
|
+
|
|
843
|
+
function App() {
|
|
844
|
+
return <TanStackDevtools plugins={[]} />
|
|
845
|
+
}
|
|
846
|
+
`
|
|
847
|
+
|
|
848
|
+
const result = testTransform(
|
|
849
|
+
code,
|
|
850
|
+
'@tanstack/react-form-devtools',
|
|
851
|
+
'react-form',
|
|
852
|
+
{
|
|
853
|
+
importName: 'FormDevtoolsPlugin',
|
|
854
|
+
type: 'function',
|
|
855
|
+
},
|
|
856
|
+
)
|
|
857
|
+
|
|
858
|
+
expect(result.transformed).toBe(true)
|
|
859
|
+
expect(removeEmptySpace(result.code)).toBe(
|
|
860
|
+
removeEmptySpace(`
|
|
861
|
+
import { TanStackDevtools } from '@tanstack/react-devtools';
|
|
862
|
+
import { FormDevtoolsPlugin } from "@tanstack/react-form-devtools";
|
|
863
|
+
|
|
864
|
+
function App() {
|
|
865
|
+
return <TanStackDevtools plugins={[FormDevtoolsPlugin()]} />;
|
|
866
|
+
}
|
|
867
|
+
`),
|
|
868
|
+
)
|
|
869
|
+
})
|
|
870
|
+
|
|
871
|
+
test('should add function plugin alongside JSX plugins', () => {
|
|
872
|
+
const code = `
|
|
873
|
+
import { TanStackDevtools } from '@tanstack/react-devtools'
|
|
874
|
+
import { ReactQueryDevtoolsPanel } from '@tanstack/react-query-devtools'
|
|
875
|
+
|
|
876
|
+
function App() {
|
|
877
|
+
return <TanStackDevtools plugins={[
|
|
878
|
+
{ name: 'TanStack Query', render: <ReactQueryDevtoolsPanel /> }
|
|
879
|
+
]} />
|
|
880
|
+
}
|
|
881
|
+
`
|
|
882
|
+
|
|
883
|
+
const result = testTransform(
|
|
884
|
+
code,
|
|
885
|
+
'@tanstack/react-form-devtools',
|
|
886
|
+
'react-form',
|
|
887
|
+
{
|
|
888
|
+
importName: 'FormDevtoolsPlugin',
|
|
889
|
+
type: 'function',
|
|
890
|
+
},
|
|
891
|
+
)
|
|
892
|
+
|
|
893
|
+
expect(result.transformed).toBe(true)
|
|
894
|
+
expect(removeEmptySpace(result.code)).toBe(
|
|
895
|
+
removeEmptySpace(`
|
|
896
|
+
import { TanStackDevtools } from '@tanstack/react-devtools';
|
|
897
|
+
import { ReactQueryDevtoolsPanel } from '@tanstack/react-query-devtools';
|
|
898
|
+
import { FormDevtoolsPlugin } from "@tanstack/react-form-devtools";
|
|
899
|
+
|
|
900
|
+
function App() {
|
|
901
|
+
return <TanStackDevtools plugins={[
|
|
902
|
+
{ name: 'TanStack Query', render: <ReactQueryDevtoolsPanel /> },
|
|
903
|
+
FormDevtoolsPlugin()
|
|
904
|
+
]} />;
|
|
905
|
+
}
|
|
906
|
+
`),
|
|
907
|
+
)
|
|
908
|
+
})
|
|
909
|
+
|
|
910
|
+
test('should create plugins prop with function plugin when it does not exist', () => {
|
|
911
|
+
const code = `
|
|
912
|
+
import { TanStackDevtools } from '@tanstack/react-devtools'
|
|
913
|
+
|
|
914
|
+
function App() {
|
|
915
|
+
return <TanStackDevtools />
|
|
916
|
+
}
|
|
917
|
+
`
|
|
918
|
+
|
|
919
|
+
const result = testTransform(
|
|
920
|
+
code,
|
|
921
|
+
'@tanstack/react-form-devtools',
|
|
922
|
+
'react-form',
|
|
923
|
+
{
|
|
924
|
+
importName: 'FormDevtoolsPlugin',
|
|
925
|
+
type: 'function',
|
|
926
|
+
},
|
|
927
|
+
)
|
|
928
|
+
|
|
929
|
+
expect(result.transformed).toBe(true)
|
|
930
|
+
expect(removeEmptySpace(result.code)).toBe(
|
|
931
|
+
removeEmptySpace(`
|
|
932
|
+
import { TanStackDevtools } from '@tanstack/react-devtools';
|
|
933
|
+
import { FormDevtoolsPlugin } from "@tanstack/react-form-devtools";
|
|
934
|
+
|
|
935
|
+
function App() {
|
|
936
|
+
return <TanStackDevtools plugins={[FormDevtoolsPlugin()]} />;
|
|
937
|
+
}
|
|
938
|
+
`),
|
|
939
|
+
)
|
|
940
|
+
})
|
|
941
|
+
|
|
942
|
+
test('should not add function plugin if it already exists', () => {
|
|
943
|
+
const code = `
|
|
944
|
+
import { TanStackDevtools } from '@tanstack/react-devtools'
|
|
945
|
+
import { FormDevtoolsPlugin } from '@tanstack/react-form-devtools'
|
|
946
|
+
|
|
947
|
+
function App() {
|
|
948
|
+
return <TanStackDevtools plugins={[FormDevtoolsPlugin()]} />
|
|
949
|
+
}
|
|
950
|
+
`
|
|
951
|
+
|
|
952
|
+
const result = testTransform(
|
|
953
|
+
code,
|
|
954
|
+
'@tanstack/react-form-devtools',
|
|
955
|
+
'react-form',
|
|
956
|
+
{
|
|
957
|
+
importName: 'FormDevtoolsPlugin',
|
|
958
|
+
type: 'function',
|
|
959
|
+
},
|
|
960
|
+
)
|
|
961
|
+
|
|
962
|
+
expect(result.transformed).toBe(false)
|
|
963
|
+
})
|
|
964
|
+
|
|
965
|
+
test('should handle function plugin with renamed devtools import', () => {
|
|
966
|
+
const code = `
|
|
967
|
+
import { TanStackDevtools as DevtoolsPanel } from '@tanstack/react-devtools'
|
|
968
|
+
|
|
969
|
+
function App() {
|
|
970
|
+
return <DevtoolsPanel plugins={[]} />
|
|
971
|
+
}
|
|
972
|
+
`
|
|
973
|
+
|
|
974
|
+
const result = testTransform(
|
|
975
|
+
code,
|
|
976
|
+
'@tanstack/react-form-devtools',
|
|
977
|
+
'react-form',
|
|
978
|
+
{
|
|
979
|
+
importName: 'FormDevtoolsPlugin',
|
|
980
|
+
type: 'function',
|
|
981
|
+
},
|
|
982
|
+
)
|
|
983
|
+
|
|
984
|
+
expect(result.transformed).toBe(true)
|
|
985
|
+
expect(removeEmptySpace(result.code)).toBe(
|
|
986
|
+
removeEmptySpace(`
|
|
987
|
+
import { TanStackDevtools as DevtoolsPanel } from '@tanstack/react-devtools';
|
|
988
|
+
import { FormDevtoolsPlugin } from "@tanstack/react-form-devtools";
|
|
989
|
+
|
|
990
|
+
function App() {
|
|
991
|
+
return <DevtoolsPanel plugins={[FormDevtoolsPlugin()]} />;
|
|
992
|
+
}
|
|
993
|
+
`),
|
|
994
|
+
)
|
|
995
|
+
})
|
|
996
|
+
|
|
997
|
+
test('should handle function plugin with namespace import', () => {
|
|
998
|
+
const code = `
|
|
999
|
+
import * as DevtoolsModule from '@tanstack/solid-devtools'
|
|
1000
|
+
|
|
1001
|
+
function App() {
|
|
1002
|
+
return <DevtoolsModule.TanStackDevtools plugins={[]} />
|
|
1003
|
+
}
|
|
1004
|
+
`
|
|
1005
|
+
|
|
1006
|
+
const result = testTransform(
|
|
1007
|
+
code,
|
|
1008
|
+
'@tanstack/solid-form-devtools',
|
|
1009
|
+
'solid-form',
|
|
1010
|
+
{
|
|
1011
|
+
importName: 'FormDevtoolsPlugin',
|
|
1012
|
+
type: 'function',
|
|
1013
|
+
},
|
|
1014
|
+
)
|
|
1015
|
+
|
|
1016
|
+
expect(result.transformed).toBe(true)
|
|
1017
|
+
expect(removeEmptySpace(result.code)).toBe(
|
|
1018
|
+
removeEmptySpace(`
|
|
1019
|
+
import * as DevtoolsModule from '@tanstack/solid-devtools';
|
|
1020
|
+
import { FormDevtoolsPlugin } from "@tanstack/solid-form-devtools";
|
|
1021
|
+
|
|
1022
|
+
function App() {
|
|
1023
|
+
return <DevtoolsModule.TanStackDevtools plugins={[FormDevtoolsPlugin()]} />;
|
|
1024
|
+
}
|
|
1025
|
+
`),
|
|
1026
|
+
)
|
|
1027
|
+
})
|
|
1028
|
+
|
|
1029
|
+
test('should add multiple function plugins correctly', () => {
|
|
1030
|
+
const code = `
|
|
1031
|
+
import { TanStackDevtools } from '@tanstack/react-devtools'
|
|
1032
|
+
import { FormDevtoolsPlugin } from '@tanstack/react-form-devtools'
|
|
1033
|
+
|
|
1034
|
+
function App() {
|
|
1035
|
+
return <TanStackDevtools plugins={[FormDevtoolsPlugin()]} />
|
|
1036
|
+
}
|
|
1037
|
+
`
|
|
1038
|
+
|
|
1039
|
+
const result = testTransform(
|
|
1040
|
+
code,
|
|
1041
|
+
'@tanstack/react-router-devtools',
|
|
1042
|
+
'react-router',
|
|
1043
|
+
{
|
|
1044
|
+
importName: 'RouterDevtoolsPlugin',
|
|
1045
|
+
type: 'function',
|
|
1046
|
+
},
|
|
1047
|
+
)
|
|
1048
|
+
|
|
1049
|
+
expect(result.transformed).toBe(true)
|
|
1050
|
+
expect(removeEmptySpace(result.code)).toBe(
|
|
1051
|
+
removeEmptySpace(`
|
|
1052
|
+
import { TanStackDevtools } from '@tanstack/react-devtools';
|
|
1053
|
+
import { FormDevtoolsPlugin } from '@tanstack/react-form-devtools';
|
|
1054
|
+
import { RouterDevtoolsPlugin } from "@tanstack/react-router-devtools";
|
|
1055
|
+
|
|
1056
|
+
function App() {
|
|
1057
|
+
return <TanStackDevtools plugins={[FormDevtoolsPlugin(), RouterDevtoolsPlugin()]} />;
|
|
1058
|
+
}
|
|
1059
|
+
`),
|
|
1060
|
+
)
|
|
1061
|
+
})
|
|
1062
|
+
|
|
1063
|
+
test('should not transform when pluginImport is not provided', () => {
|
|
1064
|
+
const code = `
|
|
1065
|
+
import { TanStackDevtools } from '@tanstack/react-devtools'
|
|
1066
|
+
|
|
1067
|
+
function App() {
|
|
1068
|
+
return <TanStackDevtools plugins={[]} />
|
|
1069
|
+
}
|
|
1070
|
+
`
|
|
1071
|
+
|
|
1072
|
+
// No pluginImport provided - should return false
|
|
1073
|
+
const result = testTransform(
|
|
1074
|
+
code,
|
|
1075
|
+
'@tanstack/react-query-devtools',
|
|
1076
|
+
'TanStack Query',
|
|
1077
|
+
{
|
|
1078
|
+
importName: '',
|
|
1079
|
+
type: 'jsx',
|
|
1080
|
+
},
|
|
1081
|
+
)
|
|
1082
|
+
|
|
1083
|
+
expect(result.transformed).toBe(false)
|
|
1084
|
+
})
|
|
1085
|
+
})
|
|
1086
|
+
})
|