Skip to content

Commit 28b9504

Browse files
committed
test(transform): make tests use new format
1 parent bf5e35d commit 28b9504

File tree

2 files changed

+36
-86
lines changed

2 files changed

+36
-86
lines changed

test/capture.test.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,6 @@ describe('useFlytrapCall capture', () => {
5050
id: '/file.js-console.log',
5151
name: 'log',
5252
output: undefined,
53-
scopes: [],
54-
source: {
55-
filePath: '/file.js',
56-
lineNumber: 1
57-
},
5853
timestamp: 0
5954
}
6055
])

test/transform.test.ts

Lines changed: 36 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -134,11 +134,11 @@ describe('useFlytrapFunction transform', () => {
134134
expect(transform(someFixture)).toStrictEqual(
135135
toOneLine(`
136136
;(useFlytrapFunction((() => {}), {
137-
id: '/file.js-_anonymous',
137+
id: '/file.js-_anonymous'
138138
}))
139139
140140
;(useFlytrapFunction((() => {}), {
141-
id: '/file.js-_anonymous2',
141+
id: '/file.js-_anonymous2'
142142
}));
143143
`)
144144
)
@@ -224,11 +224,7 @@ it('transforms default exports', () => {
224224
).toStrictEqual(
225225
toOneLine(`
226226
export default useFlytrapFunction(function getAllConfigs() {}, {
227-
id: '/file.js-getAllConfigs',
228-
name: 'getAllConfigs',
229-
filePath: '/file.js',
230-
lineNumber: 2,
231-
scopes: []
227+
id: '/file.js-_getAllConfigs'
232228
});
233229
`)
234230
)
@@ -241,11 +237,7 @@ it('transforms default exports', () => {
241237
).toStrictEqual(
242238
toOneLine(`
243239
export default useFlytrapFunction(function() {}, {
244-
id: '/file.js-anonymous',
245-
name: 'anonymous',
246-
filePath: '/file.js',
247-
lineNumber: 2,
248-
scopes: []
240+
id: '/file.js-_anonymous'
249241
});
250242
`)
251243
)
@@ -362,12 +354,12 @@ describe('useFlytrapCall(Async) transform', () => {
362354
it('transforms sync functions', () => {
363355
expect(transform('const a = listUsers()')).toStrictEqual(
364356
toOneLine(
365-
`const a = useFlytrapCall(listUsers, { id: '/file.js-listUsers', args: [], name: 'listUsers', filePath: '/file.js', lineNumber: 1, scopes: [] })`
357+
`const a = useFlytrapCall(listUsers, { id: '/file.js-call-_listUsers', args: [], name: 'listUsers' })`
366358
)
367359
)
368360
expect(transform('const a = await listUsers()')).toStrictEqual(
369361
toOneLine(
370-
`const a = await useFlytrapCallAsync(listUsers, { id: '/file.js-listUsers', args: [], name: 'listUsers', filePath: '/file.js', lineNumber: 1, scopes: [] })`
362+
`const a = await useFlytrapCallAsync(listUsers, { id: '/file.js-call-_listUsers', args: [], name: 'listUsers' })`
371363
)
372364
)
373365

@@ -378,21 +370,13 @@ describe('useFlytrapCall(Async) transform', () => {
378370
).toStrictEqual(
379371
toOneLine(
380372
`
381-
useFlytrapCall(console, { id: '/file.js-console.log', args: [''], name: 'log', filePath: '/file.js', lineNumber: 2, scopes: [] })
382-
useFlytrapCall(console, { id: '/file.js-console.log-2', args: ['hello world'], name: 'log', filePath: '/file.js', lineNumber: 3, scopes: [] })
373+
useFlytrapCall(console, { id: '/file.js-call-_log', args: [''], name: 'log' })
374+
useFlytrapCall(console, { id: '/file.js-call-_log2', args: ['hello world'], name: 'log' })
383375
`
384376
)
385377
)
386378
})
387379

388-
/*it('correct params', () => {
389-
expect(transform('const a = await listUsers(/* should ignore comments)')).toStrictEqual(
390-
toOneLine(
391-
`const a = await useFlytrapCallAsync(listUsers, { args: [], params: '', name: 'listUsers', filePath: '/file.js', lineNumber: 1, scopes: [] })`
392-
)
393-
)
394-
})*/
395-
396380
it('transforms default exports', () => {
397381
const defaultExportFixture = `
398382
import NextAuth from "next-auth";
@@ -404,20 +388,20 @@ describe('useFlytrapCall(Async) transform', () => {
404388
toOneLine(`
405389
import NextAuth from "next-auth";
406390
import { authOptions } from "@/server/auth";
407-
export default useFlytrapCall(NextAuth, { id: '/file.js-NextAuth', args: [authOptions], name: 'NextAuth', filePath: '/file.js', lineNumber: 4, scopes: [] });
391+
export default useFlytrapCall(NextAuth, { id: '/file.js-call-_NextAuth', args: [authOptions], name: 'NextAuth' });
408392
`)
409393
)
410394
})
411395

412396
it('transforms arguments', () => {
413397
expect(transform('const a = listUsers(1, 2);')).toStrictEqual(
414398
toOneLine(
415-
`const a = useFlytrapCall(listUsers, { id: '/file.js-listUsers', args: [1, 2], name: 'listUsers', filePath: '/file.js', lineNumber: 1, scopes: [] });`
399+
`const a = useFlytrapCall(listUsers, { id: '/file.js-call-_listUsers', args: [1, 2], name: 'listUsers' });`
416400
)
417401
)
418402
expect(transform('const a = await listUsers(1, 2);')).toStrictEqual(
419403
toOneLine(
420-
`const a = await useFlytrapCallAsync(listUsers, { id: '/file.js-listUsers', args: [1, 2], name: 'listUsers', filePath: '/file.js', lineNumber: 1, scopes: [] });`
404+
`const a = await useFlytrapCallAsync(listUsers, { id: '/file.js-call-_listUsers', args: [1, 2], name: 'listUsers' });`
421405
)
422406
)
423407
})
@@ -427,12 +411,9 @@ describe('useFlytrapCall(Async) transform', () => {
427411
toOneLine(
428412
`
429413
useFlytrapCall(supabase, {
430-
id: '/file.js-supabase.from',
414+
id: '/file.js-call-_from',
431415
args: ['Capture'],
432-
name: 'from',
433-
filePath: '/file.js',
434-
lineNumber: 1,
435-
scopes: []
416+
name: 'from'
436417
})
437418
`
438419
)
@@ -441,25 +422,17 @@ describe('useFlytrapCall(Async) transform', () => {
441422
expect(
442423
transform(`const { data, error } = await supabase.from('Capture').select('*')`)
443424
).toStrictEqual(
444-
toOneLine(
445-
`
425+
toOneLine(`
446426
const { data, error } = await useFlytrapCallAsync(useFlytrapCall(supabase, {
447-
id: '/file.js-supabase.from',
427+
id: '/file.js-call-_from',
448428
args: ['Capture'],
449-
name: 'from',
450-
filePath: '/file.js',
451-
lineNumber: 1,
452-
scopes: []
429+
name: 'from'
453430
}), {
454-
id: '/file.js-(anonymous).select',
431+
id: '/file.js-call-_select',
455432
args: ['*'],
456-
name: 'select',
457-
filePath: '/file.js',
458-
lineNumber: 1,
459-
scopes: []
433+
name: 'select'
460434
})
461-
`
462-
)
435+
`)
463436
)
464437
})
465438

@@ -468,16 +441,16 @@ describe('useFlytrapCall(Async) transform', () => {
468441

469442
expect(transform(fixture).split('\n').join('')).toStrictEqual(
470443
toOneLine(
471-
`const a = useFlytrapCall(listUsers, { id: '/file.js-listUsers', args: [{ fetch: useFlytrapFunction(endpoint => {}, { id: '/file.js-fetch', name: 'fetch', filePath: '/file.js', lineNumber: 1, scopes: [] }) }], name: 'listUsers', filePath: '/file.js', lineNumber: 1, scopes: [] })`
444+
`const a = useFlytrapCall(listUsers, { id: '/file.js-call-_listUsers', args: [{ fetch: useFlytrapFunction(endpoint => {}, { id: '/file.js-_fetch' }) }], name: 'listUsers' })`
472445
)
473446
)
474447
})
475448

476449
it('generates unique IDs for function calls based on AST', () => {
477450
expect(transform(`listUsers()`)).toStrictEqual(
478451
toOneLine(`
479-
useFlytrapCall(listUsers,{id: '/file.js-listUsers',args:[],name:'listUsers',filePath:'/file.js',lineNumber:1,scopes:[]})
480-
`)
452+
useFlytrapCall(listUsers, { id: '/file.js-call-_listUsers', args:[], name:'listUsers' })
453+
`)
481454
)
482455
expect(
483456
transform(`
@@ -486,8 +459,8 @@ describe('useFlytrapCall(Async) transform', () => {
486459
`)
487460
).toStrictEqual(
488461
toOneLine(`
489-
useFlytrapCall(listUsers,{id: '/file.js-listUsers',args:[],name:'listUsers',filePath:'/file.js',lineNumber:2,scopes:[]})
490-
useFlytrapCall(listUsers,{id: '/file.js-listUsers-2',args:[],name:'listUsers',filePath:'/file.js',lineNumber:3,scopes:[]})
462+
useFlytrapCall(listUsers, {id: '/file.js-call-_listUsers',args:[],name:'listUsers' })
463+
useFlytrapCall(listUsers, {id: '/file.js-call-_listUsers2',args:[],name:'listUsers' })
491464
`)
492465
)
493466

@@ -504,47 +477,29 @@ describe('useFlytrapCall(Async) transform', () => {
504477
).toStrictEqual(
505478
toOneLine(`
506479
useFlytrapCall(listUsers, {
507-
id: '/file.js-listUsers',
480+
id: '/file.js-call-_listUsers',
508481
args: [],
509-
name: 'listUsers',
510-
filePath: '/file.js',
511-
lineNumber: 2,
512-
scopes: []
482+
name: 'listUsers'
513483
})
514484
useFlytrapCall(listUsers, {
515-
id: '/file.js-listUsers-2',
485+
id: '/file.js-call-_listUsers2',
516486
args: [],
517-
name: 'listUsers',
518-
filePath: '/file.js',
519-
lineNumber: 3,
520-
scopes: []
487+
name: 'listUsers'
521488
})
522489
523490
const helloWorld = useFlytrapFunction(function helloWorld() {
524491
useFlytrapCall(listUsers, {
525-
functionId: '/file.js-helloWorld',
526-
id: '/file.js-helloWorld-listUsers',
492+
id: '/file.js-call-_helloWorldListUsers',
527493
args: [],
528-
name: 'listUsers',
529-
filePath: '/file.js',
530-
lineNumber: 5,
531-
scopes: ['helloWorld']
494+
name: 'listUsers'
532495
})
533496
useFlytrapCall(listUsers, {
534-
functionId: '/file.js-helloWorld',
535-
id: '/file.js-helloWorld-listUsers-2',
497+
id: '/file.js-call-_helloWorldListUsers2',
536498
args: [],
537-
name: 'listUsers',
538-
filePath: '/file.js',
539-
lineNumber: 6,
540-
scopes: ['helloWorld']
499+
name: 'listUsers'
541500
})
542501
}, {
543-
id: '/file.js-helloWorld',
544-
name: 'helloWorld',
545-
filePath: '/file.js',
546-
lineNumber: 4,
547-
scopes: []
502+
id: '/file.js-_helloWorld'
548503
});
549504
`)
550505
)
@@ -554,14 +509,14 @@ describe('useFlytrapCall(Async) transform', () => {
554509
const fixture = `
555510
const helloWorld = useFlytrapFunction(function helloWorld() {
556511
console.log('hello world')
557-
}, { id: '/file.js-helloWorld', filePath: '/file.js', lineNumber: 2, scopes: [] })
512+
}, { id: '/file.js-_helloWorld' })
558513
`
559514

560515
expect(transform(fixture)).toStrictEqual(
561516
toOneLine(`
562517
const helloWorld = useFlytrapFunction(function helloWorld() {
563-
useFlytrapCall(console, { functionId: '/file.js-helloWorld', id: '/file.js-helloWorld-console.log', args: ['hello world'], name: 'log', filePath: '/file.js', lineNumber: 3, scopes: ['helloWorld'] })
564-
}, { id: '/file.js-helloWorld', filePath: '/file.js', lineNumber: 2, scopes: [] })
518+
useFlytrapCall(console, { id: '/file.js-call-_helloWorldLog', args: ['hello world'], name: 'log' })
519+
}, { id: '/file.js-_helloWorld' })
565520
`)
566521
)
567522
})

0 commit comments

Comments
 (0)