Skip to content

Commit 6fc5f18

Browse files
crisbetokirjs
authored andcommitted
test(migrations): add test for earlier fix (#59497)
Adds a test for the fix from #59452 now that we know what caused the issue. PR Close #59497
1 parent ff38671 commit 6fc5f18

File tree

1 file changed

+44
-10
lines changed

1 file changed

+44
-10
lines changed

packages/core/schematics/test/cleanup_unused_imports_migration_spec.ts

Lines changed: 44 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,7 @@ describe('cleanup unused imports schematic', () => {
3737
host = new TempScopedNodeJsSyncHost();
3838
tree = new UnitTestTree(new HostTree(host));
3939

40-
writeFile(
41-
'/tsconfig.json',
42-
JSON.stringify({
43-
compilerOptions: {
44-
lib: ['es2015'],
45-
strictNullChecks: true,
46-
},
47-
}),
48-
);
49-
40+
writeFile('/tsconfig.json', '{}');
5041
writeFile(
5142
'/angular.json',
5243
JSON.stringify({
@@ -253,4 +244,47 @@ describe('cleanup unused imports schematic', () => {
253244

254245
expect(tree.readContent('comp.ts')).toBe(initialContent);
255246
});
247+
248+
it('should handle a file that is present in multiple projects', async () => {
249+
writeFile('/tsconfig-2.json', '{}');
250+
writeFile(
251+
'/angular.json',
252+
JSON.stringify({
253+
version: 1,
254+
projects: {
255+
a: {root: '', architect: {build: {options: {tsConfig: './tsconfig.json'}}}},
256+
b: {root: '', architect: {build: {options: {tsConfig: './tsconfig-2.json'}}}},
257+
},
258+
}),
259+
);
260+
261+
writeFile(
262+
'comp.ts',
263+
`
264+
import {Component} from '@angular/core';
265+
import {One, Two, Three} from './directives';
266+
267+
@Component({
268+
imports: [Three, One, Two],
269+
template: '<div one></div>',
270+
})
271+
export class Comp {}
272+
`,
273+
);
274+
275+
await runMigration();
276+
277+
expect(stripWhitespace(tree.readContent('comp.ts'))).toBe(
278+
stripWhitespace(`
279+
import {Component} from '@angular/core';
280+
import {One} from './directives';
281+
282+
@Component({
283+
imports: [One],
284+
template: '<div one></div>',
285+
})
286+
export class Comp {}
287+
`),
288+
);
289+
});
256290
});

0 commit comments

Comments
 (0)