Skip to content

refactor: fix schematics not respecting new -module.ts suffix #31299

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions src/cdk/schematics/ng-generate/drag-drop/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ describe('CDK drag-drop schematic', () => {
// updating the other tests as well because `createTestApp` is responsible for creating
// the project.
project: 'material',
module: 'app-module.ts',
};

beforeEach(() => {
Expand All @@ -21,7 +22,7 @@ describe('CDK drag-drop schematic', () => {
it('should create drag-drop files and add them to module', async () => {
const app = await createTestApp(runner, {standalone: false});
const tree = await runner.runSchematic('drag-drop', baseOptions, app);
const moduleContent = getFileContent(tree, '/projects/material/src/app/app.module.ts');
const moduleContent = getFileContent(tree, '/projects/material/src/app/app-module.ts');
const files = tree.files;

expect(files).toContain('/projects/material/src/app/foo/foo.component.css');
Expand All @@ -36,7 +37,7 @@ describe('CDK drag-drop schematic', () => {
it('should add drag-drop module', async () => {
const app = await createTestApp(runner, {standalone: false});
const tree = await runner.runSchematic('drag-drop', baseOptions, app);
const moduleContent = getFileContent(tree, '/projects/material/src/app/app.module.ts');
const moduleContent = getFileContent(tree, '/projects/material/src/app/app-module.ts');

expect(moduleContent).toContain('DragDropModule');
});
Expand All @@ -45,7 +46,7 @@ describe('CDK drag-drop schematic', () => {
it('should generate a standalone component', async () => {
const app = await createTestApp(runner, {standalone: false});
const tree = await runner.runSchematic('drag-drop', {...baseOptions, standalone: true}, app);
const module = getFileContent(tree, '/projects/material/src/app/app.module.ts');
const module = getFileContent(tree, '/projects/material/src/app/app-module.ts');
const component = getFileContent(tree, '/projects/material/src/app/foo/foo.component.ts');

expect(module).not.toContain('DragDropModule');
Expand All @@ -58,7 +59,7 @@ describe('CDK drag-drop schematic', () => {
it('should generate a component with no imports and standalone false', async () => {
const app = await createTestApp(runner, {standalone: false});
const tree = await runner.runSchematic('drag-drop', {...baseOptions, standalone: false}, app);
const module = getFileContent(tree, '/projects/material/src/app/app.module.ts');
const module = getFileContent(tree, '/projects/material/src/app/app-module.ts');
const component = getFileContent(tree, '/projects/material/src/app/foo/foo.component.ts');

expect(module).toContain('DragDropModule');
Expand All @@ -74,7 +75,7 @@ describe('CDK drag-drop schematic', () => {
const component = getFileContent(tree, '/projects/material/src/app/foo/foo.component.ts');
const test = getFileContent(tree, '/projects/material/src/app/foo/foo.component.spec.ts');

expect(tree.exists('/projects/material/src/app/app.module.ts')).toBe(false);
expect(tree.exists('/projects/material/src/app/app-module.ts')).toBe(false);

expect(component).toContain('imports: [');

Expand Down
3 changes: 2 additions & 1 deletion src/cdk/schematics/utils/build-component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,8 @@ export function buildComponent(
options.standalone = await isStandaloneSchematic(host, options);

if (!options.standalone) {
options.module = findModuleFromOptions(host, options);
// TODO: Remove ext option when the Angular CLI looks for both candidate locations.
options.module = findModuleFromOptions(host, {...options, moduleExt: 'module.ts'});
}

const parsedPath = parseName(options.path!, options.name);
Expand Down
11 changes: 6 additions & 5 deletions src/material/schematics/ng-generate/address-form/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ describe('Material address-form schematic', () => {
const baseOptions: Schema = {
name: 'foo',
project: 'material',
module: 'app-module.ts',
};

beforeEach(() => {
Expand All @@ -25,15 +26,15 @@ describe('Material address-form schematic', () => {
expect(files).toContain('/projects/material/src/app/foo/foo.component.spec.ts');
expect(files).toContain('/projects/material/src/app/foo/foo.component.ts');

const moduleContent = getFileContent(tree, '/projects/material/src/app/app.module.ts');
const moduleContent = getFileContent(tree, '/projects/material/src/app/app-module.ts');
expect(moduleContent).toMatch(/import.*Foo.*from '.\/foo\/foo.component'/);
expect(moduleContent).toMatch(/declarations:\s*\[[^\]]+?,\r?\n\s+FooComponent\r?\n/m);
});

it('should add address-form imports to module', async () => {
const app = await createTestApp(runner, {standalone: false});
const tree = await runner.runSchematic('address-form', baseOptions, app);
const moduleContent = getFileContent(tree, '/projects/material/src/app/app.module.ts');
const moduleContent = getFileContent(tree, '/projects/material/src/app/app-module.ts');

expect(moduleContent).toContain('MatInputModule');
expect(moduleContent).toContain('MatButtonModule');
Expand All @@ -58,7 +59,7 @@ describe('Material address-form schematic', () => {
{...baseOptions, standalone: true},
app,
);
const module = getFileContent(tree, '/projects/material/src/app/app.module.ts');
const module = getFileContent(tree, '/projects/material/src/app/app-module.ts');
const content = getFileContent(tree, '/projects/material/src/app/foo/foo.component.ts');
const requiredModules = [
'MatInputModule',
Expand All @@ -84,7 +85,7 @@ describe('Material address-form schematic', () => {
{...baseOptions, standalone: false},
app,
);
const module = getFileContent(tree, '/projects/material/src/app/app.module.ts');
const module = getFileContent(tree, '/projects/material/src/app/app-module.ts');
const content = getFileContent(tree, '/projects/material/src/app/foo/foo.component.ts');
const requiredModules = [
'MatInputModule',
Expand All @@ -108,7 +109,7 @@ describe('Material address-form schematic', () => {
const tree = await runner.runSchematic('address-form', baseOptions, app);
const component = getFileContent(tree, '/projects/material/src/app/foo/foo.component.ts');

expect(tree.exists('/projects/material/src/app/app.module.ts')).toBe(false);
expect(tree.exists('/projects/material/src/app/app-module.ts')).toBe(false);
expect(component).toContain('imports: [');
});
});
Expand Down
11 changes: 6 additions & 5 deletions src/material/schematics/ng-generate/dashboard/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ describe('material-dashboard-schematic', () => {
const baseOptions: Schema = {
name: 'foo',
project: 'material',
module: './app-module.ts',
};

beforeEach(() => {
Expand All @@ -25,15 +26,15 @@ describe('material-dashboard-schematic', () => {
expect(files).toContain('/projects/material/src/app/foo/foo.component.spec.ts');
expect(files).toContain('/projects/material/src/app/foo/foo.component.ts');

const moduleContent = getFileContent(tree, '/projects/material/src/app/app.module.ts');
const moduleContent = getFileContent(tree, '/projects/material/src/app/app-module.ts');
expect(moduleContent).toMatch(/import.*Foo.*from '.\/foo\/foo.component'/);
expect(moduleContent).toMatch(/declarations:\s*\[[^\]]+?,\r?\n\s+FooComponent\r?\n/m);
});

it('should add dashboard imports to module', async () => {
const app = await createTestApp(runner, {standalone: false});
const tree = await runner.runSchematic('dashboard', baseOptions, app);
const moduleContent = getFileContent(tree, '/projects/material/src/app/app.module.ts');
const moduleContent = getFileContent(tree, '/projects/material/src/app/app-module.ts');

expect(moduleContent).toContain('MatGridListModule');
expect(moduleContent).toContain('MatCardModule');
Expand Down Expand Up @@ -62,7 +63,7 @@ describe('material-dashboard-schematic', () => {
it('should generate a standalone component', async () => {
const app = await createTestApp(runner, {standalone: false});
const tree = await runner.runSchematic('dashboard', {...baseOptions, standalone: true}, app);
const module = getFileContent(tree, '/projects/material/src/app/app.module.ts');
const module = getFileContent(tree, '/projects/material/src/app/app-module.ts');
const component = getFileContent(tree, '/projects/material/src/app/foo/foo.component.ts');
const requiredModules = [
'MatButtonModule',
Expand All @@ -84,7 +85,7 @@ describe('material-dashboard-schematic', () => {
it('should generate a component with no imports and standalone false', async () => {
const app = await createTestApp(runner, {standalone: false});
const tree = await runner.runSchematic('dashboard', {...baseOptions, standalone: false}, app);
const module = getFileContent(tree, '/projects/material/src/app/app.module.ts');
const module = getFileContent(tree, '/projects/material/src/app/app-module.ts');
const component = getFileContent(tree, '/projects/material/src/app/foo/foo.component.ts');
const requiredModules = [
'MatButtonModule',
Expand Down Expand Up @@ -113,7 +114,7 @@ describe('material-dashboard-schematic', () => {
'/projects/material/src/app/foo/foo.component.ts',
);

expect(tree.exists('/projects/material/src/app/app.module.ts')).toBe(false);
expect(tree.exists('/projects/material/src/app/app-module.ts')).toBe(false);
expect(componentContent).toContain('imports: [');
});
});
Expand Down
11 changes: 6 additions & 5 deletions src/material/schematics/ng-generate/navigation/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,15 @@ describe('material-navigation-schematic', () => {
const baseOptions: Schema = {
name: 'foo',
project: 'material',
module: './app-module.ts',
};

beforeEach(() => {
runner = new SchematicTestRunner('schematics', COLLECTION_PATH);
});

function expectNavigationSchematicModuleImports(tree: UnitTestTree) {
const moduleContent = getFileContent(tree, '/projects/material/src/app/app.module.ts');
const moduleContent = getFileContent(tree, '/projects/material/src/app/app-module.ts');
expect(moduleContent).toMatch(/MatToolbarModule,\s+/);
expect(moduleContent).toMatch(/MatButtonModule,\s+/);
expect(moduleContent).toMatch(/MatSidenavModule,\s+/);
Expand All @@ -44,7 +45,7 @@ describe('material-navigation-schematic', () => {
expect(files).toContain('/projects/material/src/app/foo/foo.component.spec.ts');
expect(files).toContain('/projects/material/src/app/foo/foo.component.ts');

const moduleContent = getFileContent(tree, '/projects/material/src/app/app.module.ts');
const moduleContent = getFileContent(tree, '/projects/material/src/app/app-module.ts');
expect(moduleContent).toMatch(/import.*Foo.*from '.\/foo\/foo.component'/);
expect(moduleContent).toMatch(/declarations:\s*\[[^\]]+?,\r?\n\s+FooComponent\r?\n/m);
});
Expand Down Expand Up @@ -73,7 +74,7 @@ describe('material-navigation-schematic', () => {
it('should generate a standalone component', async () => {
const app = await createTestApp(runner, {standalone: false});
const tree = await runner.runSchematic('navigation', {...baseOptions, standalone: true}, app);
const module = getFileContent(tree, '/projects/material/src/app/app.module.ts');
const module = getFileContent(tree, '/projects/material/src/app/app-module.ts');
const component = getFileContent(tree, '/projects/material/src/app/foo/foo.component.ts');
const requiredModules = [
'MatToolbarModule',
Expand All @@ -99,7 +100,7 @@ describe('material-navigation-schematic', () => {
{...baseOptions, standalone: false},
app,
);
const module = getFileContent(tree, '/projects/material/src/app/app.module.ts');
const module = getFileContent(tree, '/projects/material/src/app/app-module.ts');
const component = getFileContent(tree, '/projects/material/src/app/foo/foo.component.ts');
const requiredModules = [
'MatToolbarModule',
Expand Down Expand Up @@ -128,7 +129,7 @@ describe('material-navigation-schematic', () => {
'/projects/material/src/app/foo/foo.component.ts',
);

expect(tree.exists('/projects/material/src/app/app.module.ts')).toBe(false);
expect(tree.exists('/projects/material/src/app/app-module.ts')).toBe(false);
expect(componentContent).toContain('imports: [');
});
});
Expand Down
11 changes: 6 additions & 5 deletions src/material/schematics/ng-generate/table/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ describe('material-table-schematic', () => {
const baseOptions: Schema = {
name: 'foo',
project: 'material',
module: './app-module.ts',
};

beforeEach(() => {
Expand All @@ -26,7 +27,7 @@ describe('material-table-schematic', () => {
expect(files).toContain('/projects/material/src/app/foo/foo.component.ts');
expect(files).toContain('/projects/material/src/app/foo/foo-datasource.ts');

const moduleContent = getFileContent(tree, '/projects/material/src/app/app.module.ts');
const moduleContent = getFileContent(tree, '/projects/material/src/app/app-module.ts');
expect(moduleContent).toMatch(/import.*Foo.*from '.\/foo\/foo.component'/);
expect(moduleContent).toMatch(/declarations:\s*\[[^\]]+?,\r?\n\s+FooComponent\r?\n/m);

Expand All @@ -49,7 +50,7 @@ describe('material-table-schematic', () => {
it('should add table imports to module', async () => {
const app = await createTestApp(runner, {standalone: false});
const tree = await runner.runSchematic('table', baseOptions, app);
const moduleContent = getFileContent(tree, '/projects/material/src/app/app.module.ts');
const moduleContent = getFileContent(tree, '/projects/material/src/app/app-module.ts');

expect(moduleContent).toContain('MatTableModule');
expect(moduleContent).toContain('MatPaginatorModule');
Expand All @@ -74,7 +75,7 @@ describe('material-table-schematic', () => {
it('should generate a standalone component', async () => {
const app = await createTestApp(runner, {standalone: false});
const tree = await runner.runSchematic('table', {...baseOptions, standalone: true}, app);
const module = getFileContent(tree, '/projects/material/src/app/app.module.ts');
const module = getFileContent(tree, '/projects/material/src/app/app-module.ts');
const component = getFileContent(tree, '/projects/material/src/app/foo/foo.component.ts');
const requiredModules = ['MatTableModule', 'MatPaginatorModule', 'MatSortModule'];

Expand All @@ -90,7 +91,7 @@ describe('material-table-schematic', () => {
it('should generate a component with no imports and standalone false', async () => {
const app = await createTestApp(runner, {standalone: false});
const tree = await runner.runSchematic('table', {...baseOptions, standalone: false}, app);
const module = getFileContent(tree, '/projects/material/src/app/app.module.ts');
const module = getFileContent(tree, '/projects/material/src/app/app-module.ts');
const component = getFileContent(tree, '/projects/material/src/app/foo/foo.component.ts');
const requiredModules = ['MatTableModule', 'MatPaginatorModule', 'MatSortModule'];

Expand All @@ -113,7 +114,7 @@ describe('material-table-schematic', () => {
'/projects/material/src/app/foo/foo.component.ts',
);

expect(tree.exists('/projects/material/src/app/app.module.ts')).toBe(false);
expect(tree.exists('/projects/material/src/app/app-module.ts')).toBe(false);
expect(componentContent).toContain('imports: [');
});
});
Expand Down
11 changes: 6 additions & 5 deletions src/material/schematics/ng-generate/tree/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ describe('Material tree schematic', () => {
const baseOptions: Schema = {
name: 'foo',
project: 'material',
module: './app-module.ts',
};

beforeEach(() => {
Expand All @@ -25,15 +26,15 @@ describe('Material tree schematic', () => {
expect(files).toContain('/projects/material/src/app/foo/foo.component.spec.ts');
expect(files).toContain('/projects/material/src/app/foo/foo.component.ts');

const moduleContent = getFileContent(tree, '/projects/material/src/app/app.module.ts');
const moduleContent = getFileContent(tree, '/projects/material/src/app/app-module.ts');
expect(moduleContent).toMatch(/import.*Foo.*from '.\/foo\/foo.component'/);
expect(moduleContent).toMatch(/declarations:\s*\[[^\]]+?,\r?\n\s+FooComponent\r?\n/m);
});

it('should add tree imports to module', async () => {
const app = await createTestApp(runner, {standalone: false});
const tree = await runner.runSchematic('tree', baseOptions, app);
const moduleContent = getFileContent(tree, '/projects/material/src/app/app.module.ts');
const moduleContent = getFileContent(tree, '/projects/material/src/app/app-module.ts');

expect(moduleContent).toContain('MatTreeModule');
expect(moduleContent).toContain('MatIconModule');
Expand All @@ -52,7 +53,7 @@ describe('Material tree schematic', () => {
it('should generate a standalone component', async () => {
const app = await createTestApp(runner, {standalone: false});
const tree = await runner.runSchematic('tree', {...baseOptions, standalone: true}, app);
const module = getFileContent(tree, '/projects/material/src/app/app.module.ts');
const module = getFileContent(tree, '/projects/material/src/app/app-module.ts');
const component = getFileContent(tree, '/projects/material/src/app/foo/foo.component.ts');
const requiredModules = ['MatTreeModule', 'MatButtonModule', 'MatIconModule'];

Expand All @@ -68,7 +69,7 @@ describe('Material tree schematic', () => {
it('should generate a component with no imports and standalone false', async () => {
const app = await createTestApp(runner, {standalone: false});
const tree = await runner.runSchematic('tree', {...baseOptions, standalone: false}, app);
const module = getFileContent(tree, '/projects/material/src/app/app.module.ts');
const module = getFileContent(tree, '/projects/material/src/app/app-module.ts');
const component = getFileContent(tree, '/projects/material/src/app/foo/foo.component.ts');
const requiredModules = ['MatTreeModule', 'MatButtonModule', 'MatIconModule'];

Expand All @@ -91,7 +92,7 @@ describe('Material tree schematic', () => {
'/projects/material/src/app/foo/foo.component.ts',
);

expect(tree.exists('/projects/material/src/app/app.module.ts')).toBe(false);
expect(tree.exists('/projects/material/src/app/app-module.ts')).toBe(false);
expect(componentContent).toContain('imports: [');
});
});
Expand Down
Loading
Loading