18
18
import { expect } from 'chai' ;
19
19
20
20
import {
21
- extractDeclarations ,
22
21
MemberList ,
23
22
dedup ,
24
23
mapSymbolToType ,
@@ -27,8 +26,9 @@ import {
27
26
ErrorCode ,
28
27
writeReportToDirectory ,
29
28
extractExternalDependencies ,
30
- buildMap ,
31
- Report
29
+ Report ,
30
+ extractExports ,
31
+ extractAllTopLevelSymbols
32
32
} from '../analysis-helper' ;
33
33
34
34
import {
@@ -39,14 +39,14 @@ import {
39
39
import * as fs from 'fs' ;
40
40
import { resolve } from 'path' ;
41
41
42
- describe ( 'extractDeclarations on .d.ts file ' , ( ) => {
42
+ describe ( 'extractExports ' , ( ) => {
43
43
let testModuleDtsFile : string ;
44
44
let extractedDeclarations : MemberList ;
45
45
before ( ( ) => {
46
46
const start = Date . now ( ) ;
47
47
testModuleDtsFile = getTestModuleDtsFilePath ( ) ;
48
- extractedDeclarations = extractDeclarations ( testModuleDtsFile ) ;
49
- console . log ( 'extractDeclarations on .d.ts file took ' , Date . now ( ) - start ) ;
48
+ extractedDeclarations = extractExports ( testModuleDtsFile ) ;
49
+ console . log ( 'extractExports took ' , Date . now ( ) - start ) ;
50
50
} ) ;
51
51
// export {tar as tarr, tar1 as tarr1} from '..'
52
52
it ( 'test export rename' , ( ) => {
@@ -187,42 +187,34 @@ describe('extractDeclarations on .d.ts file', () => {
187
187
} ) ;
188
188
189
189
// import * as fs from 'fs'
190
- // import * as tmp from 'tmp'
191
- // export declare const aVar: tmp.FileOptions;
192
190
// export { fs as fs1 };
193
191
it ( 'test namespace export' , ( ) => {
194
- expect ( extractedDeclarations . variables ) . to . include . members ( [ 'fs1' ] ) ;
195
- expect ( extractedDeclarations . variables ) . to . not . include . members ( [ 'tmp' ] ) ;
196
- expect ( extractedDeclarations . variables ) . to . include . members ( [ 'aVar' ] ) ;
192
+ expect ( extractedDeclarations . unknown ) . to . include . members ( [ 'fs1' ] ) ;
197
193
} ) ;
198
194
} ) ;
199
- describe ( 'extractDeclarations on js bundle file' , ( ) => {
195
+
196
+ describe ( 'extractAllTopLevelSymbols' , ( ) => {
200
197
let subsetExportsBundleFile : string ;
201
198
let extractedDeclarations : MemberList ;
202
199
before ( function ( ) {
203
- this . timeout ( 120000 ) ;
204
200
const start = Date . now ( ) ;
205
- const testModuleDtsFile : string = getTestModuleDtsFilePath ( ) ;
206
- const map : Map < string , string > = buildMap (
207
- extractDeclarations ( testModuleDtsFile )
208
- ) ;
209
201
subsetExportsBundleFile = getSubsetExportsBundleFilePath ( ) ;
210
- extractedDeclarations = extractDeclarations ( subsetExportsBundleFile , map ) ;
202
+ extractedDeclarations = extractAllTopLevelSymbols ( subsetExportsBundleFile ) ;
211
203
console . log (
212
204
'extractDeclarations on js bundle file took ' ,
213
205
Date . now ( ) - start
214
206
) ;
215
207
} ) ;
216
208
it ( 'test variable extractions' , ( ) => {
217
- const variablesArray = [ 'aVar' , 'fs1' ] ;
209
+ const variablesArray = [ 'aVar' ] ;
218
210
variablesArray . sort ( ) ;
219
- expect ( extractedDeclarations . variables ) . to . have . members ( variablesArray ) ;
211
+ expect ( extractedDeclarations . variables ) . to . include . members ( variablesArray ) ;
220
212
} ) ;
221
213
222
214
it ( 'test functions extractions' , ( ) => {
223
215
const functionsArray = [
224
216
'tar' ,
225
- 'tarr1 ' ,
217
+ 'tar1 ' ,
226
218
'basicFuncExportEnumDependencies' ,
227
219
'd1' ,
228
220
'd2' ,
@@ -236,16 +228,15 @@ describe('extractDeclarations on js bundle file', () => {
236
228
it ( 'test enums extractions' , ( ) => {
237
229
const enumsArray = [
238
230
'BasicEnumExport' ,
239
- 'LogLevel2' ,
240
231
'BasicEnumExportBar' ,
241
232
'BasicEnumExportFar'
242
233
] ;
243
234
enumsArray . sort ( ) ;
244
- expect ( extractedDeclarations . enums ) . to . have . members ( enumsArray ) ;
235
+ expect ( extractedDeclarations . variables ) . to . include . members ( enumsArray ) ;
245
236
} ) ;
246
237
247
238
it ( 'test classes extractions' , ( ) => {
248
- const classesArray = [ 'Logger1 ' ] ;
239
+ const classesArray = [ 'BasicClassExport ' ] ;
249
240
classesArray . sort ( ) ;
250
241
expect ( extractedDeclarations . classes ) . to . have . members ( classesArray ) ;
251
242
} ) ;
@@ -257,7 +248,8 @@ describe('test dedup helper function', () => {
257
248
functions : [ 'aFunc' , 'aFunc' , 'bFunc' , 'cFunc' ] ,
258
249
classes : [ 'aClass' , 'bClass' , 'aClass' , 'cClass' ] ,
259
250
variables : [ 'aVar' , 'bVar' , 'cVar' , 'aVar' ] ,
260
- enums : [ 'aEnum' , 'bEnum' , 'cEnum' , 'dEnum' ]
251
+ enums : [ 'aEnum' , 'bEnum' , 'cEnum' , 'dEnum' ] ,
252
+ unknown : [ ]
261
253
} ;
262
254
memberList = dedup ( memberList ) ;
263
255
@@ -287,7 +279,8 @@ describe('test dedup helper function', () => {
287
279
functions : [ ] ,
288
280
classes : [ ] ,
289
281
variables : [ 'aVar' , 'bVar' , 'cVar' , 'aVar' ] ,
290
- enums : [ ]
282
+ enums : [ ] ,
283
+ unknown : [ ]
291
284
} ;
292
285
memberList = dedup ( memberList ) ;
293
286
expect ( memberList . functions ) . to . have . length ( 0 ) ;
@@ -308,7 +301,8 @@ describe('test replaceAll helper function', () => {
308
301
functions : [ 'aFunc' , 'aFunc' , 'bFunc' , 'cFunc' ] ,
309
302
classes : [ 'aClass' , 'bClass' , 'aClass' , 'cClass' ] ,
310
303
variables : [ 'aVar' , 'bVar' , 'cVar' , 'aVar' ] ,
311
- enums : [ 'aEnum' , 'bEnum' , 'cEnum' , 'dEnum' ]
304
+ enums : [ 'aEnum' , 'bEnum' , 'cEnum' , 'dEnum' ] ,
305
+ unknown : [ ]
312
306
} ;
313
307
const original : string = 'aFunc' ;
314
308
const replaceTo : string = 'replacedFunc' ;
@@ -331,7 +325,8 @@ describe('test replaceAll helper function', () => {
331
325
functions : [ 'aFunc' , 'aFunc' , 'bFunc' , 'cFunc' ] ,
332
326
classes : [ 'aClass' , 'bClass' , 'aClass' , 'cClass' ] ,
333
327
variables : [ 'aVar' , 'bVar' , 'cVar' , 'aVar' ] ,
334
- enums : [ 'aEnum' , 'bEnum' , 'cEnum' , 'dEnum' ]
328
+ enums : [ 'aEnum' , 'bEnum' , 'cEnum' , 'dEnum' ] ,
329
+ unknown : [ ]
335
330
} ;
336
331
const replaceTo : string = 'replacedClass' ;
337
332
const original : string = 'bClass' ;
@@ -354,7 +349,8 @@ describe('test replaceAll helper function', () => {
354
349
functions : [ 'aFunc' , 'aFunc' , 'bFunc' , 'cFunc' ] ,
355
350
classes : [ 'aClass' , 'bClass' , 'aClass' , 'cClass' ] ,
356
351
variables : [ 'aVar' , 'bVar' , 'cVar' , 'aVar' ] ,
357
- enums : [ 'aEnum' , 'bEnum' , 'cEnum' , 'dEnum' ]
352
+ enums : [ 'aEnum' , 'bEnum' , 'cEnum' , 'dEnum' ] ,
353
+ unknown : [ ]
358
354
} ;
359
355
const replaceTo : string = 'replacedEnum' ;
360
356
const original : string = 'eEnum' ;
@@ -377,7 +373,8 @@ describe('test mapSymbolToType helper function', () => {
377
373
functions : [ 'aVar' , 'bFunc' , 'cFunc' ] ,
378
374
classes : [ 'bClass' , 'cClass' ] ,
379
375
variables : [ 'aClass' , 'bVar' , 'cVar' , 'aEnum' ] ,
380
- enums : [ 'bEnum' , 'cEnum' , 'dEnum' , 'aFunc' ]
376
+ enums : [ 'bEnum' , 'cEnum' , 'dEnum' , 'aFunc' ] ,
377
+ unknown : [ ]
381
378
} ;
382
379
383
380
const map : Map < string , string > = new Map ( [
0 commit comments