1
1
import { describe , it , expect } from 'vitest'
2
- import { findExports } from '../src'
2
+ import { ESMExport , findExports } from '../src'
3
3
4
4
describe ( 'findExports' , ( ) => {
5
- const tests = {
5
+ const tests : Record < string , Partial < ESMExport > > = {
6
6
'export function useA () { return \'a\' }' : { name : 'useA' , type : 'declaration' } ,
7
7
'export const useD = () => { return \'d\' }' : { name : 'useD' , type : 'declaration' } ,
8
8
'export { useB, _useC as useC }' : { names : [ 'useB' , 'useC' ] , type : 'named' } ,
@@ -15,33 +15,41 @@ describe('findExports', () => {
15
15
'export * as foo from "./other"' : { type : 'star' , specifier : './other' , name : 'foo' }
16
16
}
17
17
18
- describe ( 'findExports' , ( ) => {
19
- for ( const [ input , test ] of Object . entries ( tests ) ) {
20
- it ( input . replace ( / \n / g, '\\n' ) , ( ) => {
21
- const matches = findExports ( input )
22
- expect ( matches . length ) . to . equal ( 1 )
23
- const match = matches [ 0 ]
24
- if ( test . type ) {
25
- expect ( match . type ) . to . eql ( test . type )
26
- }
27
- if ( test . name ) {
28
- expect ( match . name ) . to . eql ( test . name )
29
- }
30
- if ( test . names ) {
31
- expect ( match . names ) . to . deep . eql ( test . names )
32
- }
33
- if ( test . specifier ) {
34
- expect ( match . specifier ) . to . eql ( test . specifier )
35
- }
36
- } )
37
- }
38
- it ( 'handles multiple exports' , ( ) => {
39
- const matches = findExports ( `
18
+ for ( const [ input , test ] of Object . entries ( tests ) ) {
19
+ it ( input . replace ( / \n / g, '\\n' ) , ( ) => {
20
+ const matches = findExports ( input )
21
+ expect ( matches . length ) . toEqual ( 1 )
22
+ const match = matches [ 0 ]
23
+ if ( test . type ) {
24
+ expect ( match . type ) . toEqual ( test . type )
25
+ }
26
+ if ( test . name ) {
27
+ expect ( match . name ) . toEqual ( test . name )
28
+ }
29
+ if ( test . names ) {
30
+ expect ( match . names ) . toEqual ( test . names )
31
+ }
32
+ if ( test . specifier ) {
33
+ expect ( match . specifier ) . toEqual ( test . specifier )
34
+ }
35
+ } )
36
+ }
37
+ it ( 'handles multiple exports' , ( ) => {
38
+ const matches = findExports ( `
40
39
export { useTestMe1 } from "@/test/foo1";
41
40
export { useTestMe2 } from "@/test/foo2";
42
41
export { useTestMe3 } from "@/test/foo3";
43
42
` )
44
- expect ( matches . length ) . to . eql ( 3 )
45
- } )
43
+ expect ( matches . length ) . to . eql ( 3 )
44
+ } )
45
+
46
+ it ( 'works with multiple named exports' , ( ) => {
47
+ const code = `
48
+ export { foo } from 'foo1';
49
+ export { bar } from 'foo2';
50
+ export { foobar } from 'foo2';
51
+ `
52
+ const matches = findExports ( code )
53
+ expect ( matches ) . to . have . lengthOf ( 3 )
46
54
} )
47
55
} )
0 commit comments