@@ -2,6 +2,7 @@ import { join, dirname } from 'path';
22import { cwd } from 'process' ;
33import { writeFileSync , existsSync , mkdirSync , rmdirSync } from 'fs' ;
44import f from 'faker' ;
5+ import { Import } from '../src' ;
56
67export const MOCKS_DIR = '__mocks__' ;
78export const MOCKS_DIR_CWD = join ( join ( cwd ( ) , MOCKS_DIR ) ) ;
@@ -42,7 +43,7 @@ function generatePropList(props: string[]) {
4243 return props . map ( ( prop ) => `${ prop } ="${ prop } "` ) . join ( ' ' ) ;
4344}
4445
45- function jsxElement ( value : string , line : number ) {
46+ function jsxElement ( value : string , line : number ) : [ Import , string ] {
4647 const props = mockUniqueList ( ( ) => word ( ) . toLowerCase ( ) ) ;
4748 return [
4849 {
@@ -61,7 +62,7 @@ function jsxElement(value: string, line: number) {
6162 ] ;
6263}
6364
64- function propertyAccess ( value : string , line : number ) {
65+ function propertyAccess ( value : string , line : number ) : [ Import , string ] {
6566 const property = word ( ) ;
6667 return [
6768 {
@@ -72,14 +73,14 @@ function propertyAccess(value: string, line: number) {
7273 ] ;
7374}
7475
75- function callExpression ( value : string , line : number ) {
76+ function callExpression ( value : string , line : number ) : [ Import , string ] {
7677 return [
7778 { name : value , usages : [ { line : line + 2 , text : `\n${ value } ()` } ] } ,
7879 `${ value } ()` ,
7980 ] ;
8081}
8182
82- function valueUsage ( value : string , line : number ) {
83+ function valueUsage ( value : string , line : number ) : [ Import , string ] {
8384 return [
8485 { name : value , usages : [ { line : line + 2 , text : `\n${ value } ;` } ] } ,
8586 `${ value } ;` ,
@@ -103,7 +104,15 @@ function mockTSFile(pkgName: string, imports: string[]) {
103104 } ;
104105}
105106
106- export function mockPackageUsageFile ( customData ?: string ) {
107+ type mockPackageUsageFileAttributes = {
108+ customData ?: string ;
109+ analyzeImportUsages ?: boolean ;
110+ } ;
111+
112+ export function mockPackageUsageFile ( {
113+ customData,
114+ analyzeImportUsages = false ,
115+ } : mockPackageUsageFileAttributes ) {
107116 const importNames = mockUniqueList ( ( ) => capitalize ( word ( ) ) ) ;
108117 const fileName = f . datatype . uuid ( ) ;
109118 const pkg = f . hacker . noun ( ) ;
@@ -128,8 +137,18 @@ export function mockPackageUsageFile(customData?: string) {
128137 } )
129138 ) ;
130139
140+ if ( customData ) {
141+ return {
142+ fileName,
143+ pkg,
144+ version,
145+ } ;
146+ }
147+
131148 return {
132- imports : ! customData ? imports : undefined ,
149+ imports : analyzeImportUsages
150+ ? imports
151+ : imports . map ( ( { name } ) => ( { name } ) ) ,
133152 fileName,
134153 pkg,
135154 version,
0 commit comments