@@ -10,11 +10,11 @@ const TS_FILE_PATH = join(PROJECT_ROOT_DIR, 'src/app/app.component.ts');
10
10
describe ( 'v15 legacy components migration' , ( ) => {
11
11
let tree : UnitTestTree ;
12
12
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 ;
15
15
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 ;
18
18
19
19
/** Runs the v15 migration on the test application. */
20
20
let runMigration : ( ) => Promise < { logOutput : string } > ;
@@ -23,23 +23,61 @@ describe('v15 legacy components migration', () => {
23
23
const testSetup = await createTestCaseSetup ( 'migration-v15' , MIGRATION_PATH , [ ] ) ;
24
24
tree = testSetup . appTree ;
25
25
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 ) ;
28
28
} ) ;
29
29
30
30
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 ) ;
33
33
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
+ } ) ;
35
73
} ) ;
36
74
} ) ;
37
75
38
76
describe ( 'style migrations' , ( ) => {
39
77
it ( 'should do nothing yet' , async ( ) => {
40
- writeLines ( THEME_FILE_PATH , [ ' ' ] ) ;
78
+ writeLine ( THEME_FILE_PATH , ' ' ) ;
41
79
await runMigration ( ) ;
42
- expect ( splitFile ( THEME_FILE_PATH ) ) . toEqual ( [ ' ' ] ) ;
80
+ expect ( readFile ( THEME_FILE_PATH ) ) . toEqual ( ' ' ) ;
43
81
} ) ;
44
82
} ) ;
45
83
} ) ;
0 commit comments