@@ -136,6 +136,36 @@ describe("walk::user-defined-types-tests", async () => {
136136 }
137137} ) ;
138138
139+ const importDeclarationsTests : TestCase [ ] = [ {
140+ name : "getImportDeclarationTests" ,
141+ testFile : "./test-data/walk-tests/imports/got.ts" ,
142+ goldenFile : "./test-data/walk-tests/imports/want.json" ,
143+ } ] ;
144+
145+ describe ( "walk::import-declarations-tests" , async ( ) => {
146+ for ( const testCase of importDeclarationsTests ) {
147+ before ( function ( ) {
148+ setupTestCase ( testCase ) ;
149+ } ) ;
150+
151+ it ( `${ testCase . name } ` , function ( ) {
152+ const project = new ts . Project ( ) ;
153+ const tsSourceFile = project . addSourceFileAtPath ( testCase . testFile ) ;
154+
155+ const importsMap = tsWalk . getAllImportDeclarationsMap ( tsSourceFile ) ;
156+ const gotImports : Record < string , string > = { } ;
157+
158+ importsMap . forEach ( ( importDeclaration , importName ) => {
159+ gotImports [ importName ] = importDeclaration . getText ( ) ;
160+ } ) ;
161+
162+ assert . deepEqual ( testCase . goldenFileContents , gotImports ) ;
163+
164+ // writeFileSync(testCase.goldenFile, JSON.stringify(gotImports, null, 2));
165+ } ) ;
166+ }
167+ } ) ;
168+
139169function setupTestCase ( testCase : TestCase ) {
140170 testCase . testFile = path . resolve ( __dirname , testCase . testFile ) ;
141171 testCase . goldenFile = path . resolve ( __dirname , testCase . goldenFile ) ;
0 commit comments