@@ -10,11 +10,11 @@ const TS_FILE_PATH = join(PROJECT_ROOT_DIR, 'src/app/app.component.ts');
1010describe ( 'v15 legacy components migration' , ( ) => {
1111 let tree : UnitTestTree ;
1212
13- /** Writes an array of lines as a single file. */
14- let writeLines : ( path : string , lines : string [ ] ) => void ;
13+ /** Writes an single line file. */
14+ let writeLine : ( path : string , line : string ) => void ;
1515
16- /** Reads a file and split it into an array where each item is a new line . */
17- let splitFile : ( path : string ) => string [ ] ;
16+ /** Reads a file. */
17+ let readFile : ( path : string ) => string ;
1818
1919 /** Runs the v15 migration on the test application. */
2020 let runMigration : ( ) => Promise < { logOutput : string } > ;
@@ -23,23 +23,61 @@ describe('v15 legacy components migration', () => {
2323 const testSetup = await createTestCaseSetup ( 'migration-v15' , MIGRATION_PATH , [ ] ) ;
2424 tree = testSetup . appTree ;
2525 runMigration = testSetup . runFixers ;
26- splitFile = ( path : string ) => tree . readContent ( path ) . split ( '\n' ) ;
27- writeLines = ( path : string , lines : string [ ] ) => testSetup . writeFile ( path , lines . join ( '\n' ) ) ;
26+ readFile = ( path : string ) => tree . readContent ( path ) ;
27+ writeLine = ( path : string , lines : string ) => testSetup . writeFile ( path , lines ) ;
2828 } ) ;
2929
3030 describe ( 'typescript migrations' , ( ) => {
31- it ( 'should do nothing yet' , async ( ) => {
32- writeLines ( TS_FILE_PATH , [ ' ' ] ) ;
31+ async function runTypeScriptMigrationTest ( ctx : string , opts : { old : string ; new : string } ) {
32+ writeLine ( TS_FILE_PATH , opts . old ) ;
3333 await runMigration ( ) ;
34- expect ( splitFile ( TS_FILE_PATH ) ) . toEqual ( [ ' ' ] ) ;
34+ expect ( readFile ( TS_FILE_PATH ) ) . withContext ( ctx ) . toEqual ( opts . new ) ;
35+ }
36+
37+ it ( 'updates import declarations' , async ( ) => {
38+ await runTypeScriptMigrationTest ( 'named binding' , {
39+ old : `import {MatButton} from '@angular/material/button';` ,
40+ new : `import {MatLegacyButton as MatButton} from '@angular/material/legacy-button';` ,
41+ } ) ;
42+ await runTypeScriptMigrationTest ( 'named binding w/ alias' , {
43+ old : `import {MatButton as Button} from '@angular/material/button';` ,
44+ new : `import {MatLegacyButton as Button} from '@angular/material/legacy-button';` ,
45+ } ) ;
46+ await runTypeScriptMigrationTest ( 'multiple named bindings' , {
47+ old : `import {MatButton, MatButtonModule} from '@angular/material/button';` ,
48+ new : `import {MatLegacyButton as MatButton, MatLegacyButtonModule as MatButtonModule} from '@angular/material/legacy-button';` ,
49+ } ) ;
50+ await runTypeScriptMigrationTest ( 'multiple named bindings w/ alias' , {
51+ old : `import {MatButton, MatButtonModule as ButtonModule} from '@angular/material/button';` ,
52+ new : `import {MatLegacyButton as MatButton, MatLegacyButtonModule as ButtonModule} from '@angular/material/legacy-button';` ,
53+ } ) ;
54+ } ) ;
55+
56+ it ( 'updates import expressions' , async ( ) => {
57+ await runTypeScriptMigrationTest ( 'destructured & awaited' , {
58+ old : `const {MatButton} = await import('@angular/material/button');` ,
59+ new : `const {MatLegacyButton: MatButton} = await import('@angular/material/legacy-button');` ,
60+ } ) ;
61+ await runTypeScriptMigrationTest ( 'destructured & awaited w/ alias' , {
62+ old : `const {MatButton: Button} = await import('@angular/material/button');` ,
63+ new : `const {MatLegacyButton: Button} = await import('@angular/material/legacy-button');` ,
64+ } ) ;
65+ await runTypeScriptMigrationTest ( 'promise' , {
66+ old : `const promise = import('@angular/material/button');` ,
67+ new : `const promise = import('@angular/material/legacy-button');` ,
68+ } ) ;
69+ await runTypeScriptMigrationTest ( '.then' , {
70+ old : `import('@angular/material/button').then(() => {});` ,
71+ new : `import('@angular/material/legacy-button').then(() => {});` ,
72+ } ) ;
3573 } ) ;
3674 } ) ;
3775
3876 describe ( 'style migrations' , ( ) => {
3977 it ( 'should do nothing yet' , async ( ) => {
40- writeLines ( THEME_FILE_PATH , [ ' ' ] ) ;
78+ writeLine ( THEME_FILE_PATH , ' ' ) ;
4179 await runMigration ( ) ;
42- expect ( splitFile ( THEME_FILE_PATH ) ) . toEqual ( [ ' ' ] ) ;
80+ expect ( readFile ( THEME_FILE_PATH ) ) . toEqual ( ' ' ) ;
4381 } ) ;
4482 } ) ;
4583} ) ;
0 commit comments