Skip to content

Commit 96ec375

Browse files
committed
fix schematic tests
1 parent 989e006 commit 96ec375

File tree

39 files changed

+380
-267
lines changed

39 files changed

+380
-267
lines changed

modules/component-store/schematics-core/utility/find-module.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@ export function findModuleFromOptions(
5454
return normalize(modulePath + '.module.ts');
5555
} else if (host.exists(modulePath + '/' + moduleBaseName + '.module.ts')) {
5656
return normalize(modulePath + '/' + moduleBaseName + '.module.ts');
57+
} else if (host.exists(modulePath + '-module.ts')) {
58+
return normalize(modulePath + '-module.ts');
59+
} else if (host.exists(modulePath + '/' + moduleBaseName + '-module.ts')) {
60+
return normalize(modulePath + '/' + moduleBaseName + '-module.ts');
5761
} else {
5862
throw new Error(`Specified module path ${modulePath} does not exist`);
5963
}
@@ -66,8 +70,8 @@ export function findModuleFromOptions(
6670
export function findModule(host: Tree, generateDir: string): Path {
6771
let dir: DirEntry | null = host.getDir('/' + generateDir);
6872

69-
const moduleRe = /\.module\.ts$/;
70-
const routingModuleRe = /-routing\.module\.ts/;
73+
const moduleRe = /(\.|-)module\.ts$/;
74+
const routingModuleRe = /-routing(\.|-)module\.ts/;
7175

7276
while (dir) {
7377
const matches = dir.subfiles.filter(

modules/component/schematics-core/utility/find-module.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@ export function findModuleFromOptions(
5454
return normalize(modulePath + '.module.ts');
5555
} else if (host.exists(modulePath + '/' + moduleBaseName + '.module.ts')) {
5656
return normalize(modulePath + '/' + moduleBaseName + '.module.ts');
57+
} else if (host.exists(modulePath + '-module.ts')) {
58+
return normalize(modulePath + '-module.ts');
59+
} else if (host.exists(modulePath + '/' + moduleBaseName + '-module.ts')) {
60+
return normalize(modulePath + '/' + moduleBaseName + '-module.ts');
5761
} else {
5862
throw new Error(`Specified module path ${modulePath} does not exist`);
5963
}
@@ -66,8 +70,8 @@ export function findModuleFromOptions(
6670
export function findModule(host: Tree, generateDir: string): Path {
6771
let dir: DirEntry | null = host.getDir('/' + generateDir);
6872

69-
const moduleRe = /\.module\.ts$/;
70-
const routingModuleRe = /-routing\.module\.ts/;
73+
const moduleRe = /(\.|-)module\.ts$/;
74+
const routingModuleRe = /-routing(\.|-)module\.ts/;
7175

7276
while (dir) {
7377
const matches = dir.subfiles.filter(

modules/data/schematics-core/utility/find-module.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@ export function findModuleFromOptions(
5454
return normalize(modulePath + '.module.ts');
5555
} else if (host.exists(modulePath + '/' + moduleBaseName + '.module.ts')) {
5656
return normalize(modulePath + '/' + moduleBaseName + '.module.ts');
57+
} else if (host.exists(modulePath + '-module.ts')) {
58+
return normalize(modulePath + '-module.ts');
59+
} else if (host.exists(modulePath + '/' + moduleBaseName + '-module.ts')) {
60+
return normalize(modulePath + '/' + moduleBaseName + '-module.ts');
5761
} else {
5862
throw new Error(`Specified module path ${modulePath} does not exist`);
5963
}
@@ -66,8 +70,8 @@ export function findModuleFromOptions(
6670
export function findModule(host: Tree, generateDir: string): Path {
6771
let dir: DirEntry | null = host.getDir('/' + generateDir);
6872

69-
const moduleRe = /\.module\.ts$/;
70-
const routingModuleRe = /-routing\.module\.ts/;
73+
const moduleRe = /(\.|-)module\.ts$/;
74+
const routingModuleRe = /-routing(\.|-)module\.ts/;
7175

7276
while (dir) {
7377
const matches = dir.subfiles.filter(
Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,45 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

33
exports[`Data ng-add Schematic Migration of ngrx-data Data ng-add Schematic for standalone application provides data without effects 1`] = `
4-
"import { ApplicationConfig, provideZoneChangeDetection } from '@angular/core';
4+
"import { ApplicationConfig, provideBrowserGlobalErrorListeners, provideZoneChangeDetection } from '@angular/core';
55
import { provideEntityData } from '@ngrx/data';
66
import { entityConfig } from './entity-metadata';
77
88
export const appConfig: ApplicationConfig = {
9-
providers: [provideZoneChangeDetection({ eventCoalescing: true }), provideEntityData(entityConfig)]
9+
providers: [
10+
provideBrowserGlobalErrorListeners(),
11+
provideZoneChangeDetection({ eventCoalescing: true }),
12+
provideEntityData(entityConfig)
13+
]
1014
};
1115
"
1216
`;
1317

1418
exports[`Data ng-add Schematic Migration of ngrx-data Data ng-add Schematic for standalone application provides data without entityConfig 1`] = `
15-
"import { ApplicationConfig, provideZoneChangeDetection } from '@angular/core';
19+
"import { ApplicationConfig, provideBrowserGlobalErrorListeners, provideZoneChangeDetection } from '@angular/core';
1620
import { provideEntityData, withEffects } from '@ngrx/data';
1721
1822
export const appConfig: ApplicationConfig = {
19-
providers: [provideZoneChangeDetection({ eventCoalescing: true }), provideEntityData({}, withEffects())]
23+
providers: [
24+
provideBrowserGlobalErrorListeners(),
25+
provideZoneChangeDetection({ eventCoalescing: true }),
26+
provideEntityData({}, withEffects())
27+
]
2028
};
2129
"
2230
`;
2331

2432
exports[`Data ng-add Schematic Migration of ngrx-data Data ng-add Schematic for standalone application provides default data setup 1`] = `
25-
"import { ApplicationConfig, provideZoneChangeDetection } from '@angular/core';
33+
"import { ApplicationConfig, provideBrowserGlobalErrorListeners, provideZoneChangeDetection } from '@angular/core';
2634
import { provideEntityData, withEffects } from '@ngrx/data';
2735
import { entityConfig } from './entity-metadata';
2836
2937
export const appConfig: ApplicationConfig = {
30-
providers: [provideZoneChangeDetection({ eventCoalescing: true }), provideEntityData(entityConfig, withEffects())]
38+
providers: [
39+
provideBrowserGlobalErrorListeners(),
40+
provideZoneChangeDetection({ eventCoalescing: true }),
41+
provideEntityData(entityConfig, withEffects())
42+
]
3143
};
3244
"
3345
`;

modules/data/schematics/ng-add/index.spec.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -47,17 +47,17 @@ describe('Data ng-add Schematic', () => {
4747
});
4848

4949
it('should import into a specified module', async () => {
50-
const options = { ...defaultOptions, module: 'app.module.ts' };
50+
const options = { ...defaultOptions, module: 'app-module.ts' };
5151

5252
const tree = await schematicRunner.runSchematic('ng-add', options, appTree);
53-
const content = tree.readContent(`${projectPath}/src/app/app.module.ts`);
53+
const content = tree.readContent(`${projectPath}/src/app/app-module.ts`);
5454
expect(content).toMatch(/import { EntityDataModule } from '@ngrx\/data'/);
5555
});
5656

5757
it('should fail if specified module does not exist', async () => {
5858
const options = {
5959
...defaultOptions,
60-
module: `${projectPath}/src/app/app.moduleXXX.ts`,
60+
module: `${projectPath}/src/app/app-moduleXXX.ts`,
6161
};
6262
let thrownError: Error | null = null;
6363
try {
@@ -72,7 +72,7 @@ describe('Data ng-add Schematic', () => {
7272
const options = { ...defaultOptions, effects: false, entityConfig: true };
7373

7474
const tree = await schematicRunner.runSchematic('ng-add', options, appTree);
75-
const content = tree.readContent(`${projectPath}/src/app/app.module.ts`);
75+
const content = tree.readContent(`${projectPath}/src/app/app-module.ts`);
7676
expect(content).toMatch(
7777
/import { entityConfig } from '.\/entity-metadata'/
7878
);
@@ -94,7 +94,7 @@ describe('Data ng-add Schematic', () => {
9494
const options = { ...defaultOptions, entityConfig: true };
9595

9696
const tree = await schematicRunner.runSchematic('ng-add', options, appTree);
97-
const content = tree.readContent(`${projectPath}/src/app/app.module.ts`);
97+
const content = tree.readContent(`${projectPath}/src/app/app-module.ts`);
9898
expect(content).toMatch(
9999
/import { entityConfig } from '.\/entity-metadata'/
100100
);
@@ -104,13 +104,13 @@ describe('Data ng-add Schematic', () => {
104104
it('should import EntityDataModuleWithoutEffects into a specified module', async () => {
105105
const options = {
106106
...defaultOptions,
107-
module: 'app.module.ts',
107+
module: 'app-module.ts',
108108
effects: false,
109109
entityConfig: false,
110110
};
111111

112112
const tree = await schematicRunner.runSchematic('ng-add', options, appTree);
113-
const content = tree.readContent(`${projectPath}/src/app/app.module.ts`);
113+
const content = tree.readContent(`${projectPath}/src/app/app-module.ts`);
114114
expect(content).toMatch(
115115
/import { EntityDataModuleWithoutEffects } from '@ngrx\/data'/
116116
);
@@ -120,15 +120,15 @@ describe('Data ng-add Schematic', () => {
120120
const options = { ...defaultOptions, entityConfig: false };
121121

122122
const tree = await schematicRunner.runSchematic('ng-add', options, appTree);
123-
const content = tree.readContent(`${projectPath}/src/app/app.module.ts`);
123+
const content = tree.readContent(`${projectPath}/src/app/app-module.ts`);
124124
expect(content).toMatch(/EntityDataModule/);
125125
});
126126

127127
it('should register EntityDataModuleWithoutEffects in the provided module', async () => {
128128
const options = { ...defaultOptions, effects: false, entityConfig: false };
129129

130130
const tree = await schematicRunner.runSchematic('ng-add', options, appTree);
131-
const content = tree.readContent(`${projectPath}/src/app/app.module.ts`);
131+
const content = tree.readContent(`${projectPath}/src/app/app-module.ts`);
132132
expect(content).toMatch(/EntityDataModuleWithoutEffects/);
133133
});
134134

modules/effects/schematics-core/utility/find-module.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@ export function findModuleFromOptions(
5454
return normalize(modulePath + '.module.ts');
5555
} else if (host.exists(modulePath + '/' + moduleBaseName + '.module.ts')) {
5656
return normalize(modulePath + '/' + moduleBaseName + '.module.ts');
57+
} else if (host.exists(modulePath + '-module.ts')) {
58+
return normalize(modulePath + '-module.ts');
59+
} else if (host.exists(modulePath + '/' + moduleBaseName + '-module.ts')) {
60+
return normalize(modulePath + '/' + moduleBaseName + '-module.ts');
5761
} else {
5862
throw new Error(`Specified module path ${modulePath} does not exist`);
5963
}
@@ -66,8 +70,8 @@ export function findModuleFromOptions(
6670
export function findModule(host: Tree, generateDir: string): Path {
6771
let dir: DirEntry | null = host.getDir('/' + generateDir);
6872

69-
const moduleRe = /\.module\.ts$/;
70-
const routingModuleRe = /-routing\.module\.ts/;
73+
const moduleRe = /(\.|-)module\.ts$/;
74+
const routingModuleRe = /-routing(\.|-)module\.ts/;
7175

7276
while (dir) {
7377
const matches = dir.subfiles.filter(
Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,30 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

33
exports[`Effects ng-add Schematic Effects ng-add Schematic for standalone application provides full effects setup 1`] = `
4-
"import { ApplicationConfig, provideZoneChangeDetection } from '@angular/core';
4+
"import { ApplicationConfig, provideBrowserGlobalErrorListeners, provideZoneChangeDetection } from '@angular/core';
55
import { provideEffects } from '@ngrx/effects';
66
import { FooEffects } from './foo/foo.effects';
77
88
export const appConfig: ApplicationConfig = {
9-
providers: [provideZoneChangeDetection({ eventCoalescing: true }), provideEffects(FooEffects)]
9+
providers: [
10+
provideBrowserGlobalErrorListeners(),
11+
provideZoneChangeDetection({ eventCoalescing: true }),
12+
provideEffects(FooEffects)
13+
]
1014
};
1115
"
1216
`;
1317

1418
exports[`Effects ng-add Schematic Effects ng-add Schematic for standalone application provides minimal effects setup 1`] = `
15-
"import { ApplicationConfig, provideZoneChangeDetection } from '@angular/core';
19+
"import { ApplicationConfig, provideBrowserGlobalErrorListeners, provideZoneChangeDetection } from '@angular/core';
1620
import { provideEffects } from '@ngrx/effects';
1721
1822
export const appConfig: ApplicationConfig = {
19-
providers: [provideZoneChangeDetection({ eventCoalescing: true }), provideEffects()]
23+
providers: [
24+
provideBrowserGlobalErrorListeners(),
25+
provideZoneChangeDetection({ eventCoalescing: true }),
26+
provideEffects()
27+
]
2028
};
2129
"
2230
`;

modules/effects/schematics/ng-add/index.spec.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ describe('Effects ng-add Schematic', () => {
2020
name: 'foo',
2121
skipPackageJson: false,
2222
project: 'bar',
23-
module: 'app',
23+
module: 'app-module',
2424
flat: false,
2525
group: false,
2626
minimal: false,
@@ -70,7 +70,7 @@ describe('Effects ng-add Schematic', () => {
7070

7171
const tree = await schematicRunner.runSchematic('ng-add', options, appTree);
7272
const files = tree.files;
73-
const content = tree.readContent(`${projectPath}/src/app/app.module.ts`);
73+
const content = tree.readContent(`${projectPath}/src/app/app-module.ts`);
7474

7575
expect(content).toMatch(/EffectsModule\.forRoot\(\[\]\)/);
7676
expect(
@@ -83,11 +83,11 @@ describe('Effects ng-add Schematic', () => {
8383
const options = {
8484
...defaultOptions,
8585
minimal: true,
86-
module: 'app.module.ts',
86+
module: 'app-module.ts',
8787
};
8888

8989
const tree = await schematicRunner.runSchematic('ng-add', options, appTree);
90-
const content = tree.readContent(`${projectPath}/src/app/app.module.ts`);
90+
const content = tree.readContent(`${projectPath}/src/app/app-module.ts`);
9191
expect(content).not.toMatch(
9292
/import { FooEffects } from '.\/foo\/foo.effects'/
9393
);
@@ -97,22 +97,22 @@ describe('Effects ng-add Schematic', () => {
9797
const options = { ...defaultOptions };
9898

9999
const tree = await schematicRunner.runSchematic('ng-add', options, appTree);
100-
const content = tree.readContent(`${projectPath}/src/app/app.module.ts`);
100+
const content = tree.readContent(`${projectPath}/src/app/app-module.ts`);
101101
expect(content).toMatch(/import { FooEffects } from '.\/foo\/foo.effects'/);
102102
});
103103

104104
it('should import into a specified module', async () => {
105-
const options = { ...defaultOptions, module: 'app.module.ts' };
105+
const options = { ...defaultOptions, module: 'app-module.ts' };
106106

107107
const tree = await schematicRunner.runSchematic('ng-add', options, appTree);
108-
const content = tree.readContent(`${projectPath}/src/app/app.module.ts`);
108+
const content = tree.readContent(`${projectPath}/src/app/app-module.ts`);
109109
expect(content).toMatch(/import { FooEffects } from '.\/foo\/foo.effects'/);
110110
});
111111

112112
it('should fail if specified module does not exist', async () => {
113113
const options = {
114114
...defaultOptions,
115-
module: `${projectPath}/src/app/app.moduleXXX.ts`,
115+
module: `${projectPath}/src/app/app-moduleXXX.ts`,
116116
};
117117
let thrownError: Error | null = null;
118118
try {
@@ -140,7 +140,7 @@ describe('Effects ng-add Schematic', () => {
140140
const options = { ...defaultOptions };
141141

142142
const tree = await schematicRunner.runSchematic('ng-add', options, appTree);
143-
const content = tree.readContent(`${projectPath}/src/app/app.module.ts`);
143+
const content = tree.readContent(`${projectPath}/src/app/app-module.ts`);
144144

145145
expect(content).toMatch(/EffectsModule\.forRoot\(\[FooEffects\]\)/);
146146
});

modules/entity/schematics-core/utility/find-module.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@ export function findModuleFromOptions(
5454
return normalize(modulePath + '.module.ts');
5555
} else if (host.exists(modulePath + '/' + moduleBaseName + '.module.ts')) {
5656
return normalize(modulePath + '/' + moduleBaseName + '.module.ts');
57+
} else if (host.exists(modulePath + '-module.ts')) {
58+
return normalize(modulePath + '-module.ts');
59+
} else if (host.exists(modulePath + '/' + moduleBaseName + '-module.ts')) {
60+
return normalize(modulePath + '/' + moduleBaseName + '-module.ts');
5761
} else {
5862
throw new Error(`Specified module path ${modulePath} does not exist`);
5963
}
@@ -66,8 +70,8 @@ export function findModuleFromOptions(
6670
export function findModule(host: Tree, generateDir: string): Path {
6771
let dir: DirEntry | null = host.getDir('/' + generateDir);
6872

69-
const moduleRe = /\.module\.ts$/;
70-
const routingModuleRe = /-routing\.module\.ts/;
73+
const moduleRe = /(\.|-)module\.ts$/;
74+
const routingModuleRe = /-routing(\.|-)module\.ts/;
7175

7276
while (dir) {
7377
const matches = dir.subfiles.filter(

modules/operators/schematics-core/utility/find-module.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@ export function findModuleFromOptions(
5454
return normalize(modulePath + '.module.ts');
5555
} else if (host.exists(modulePath + '/' + moduleBaseName + '.module.ts')) {
5656
return normalize(modulePath + '/' + moduleBaseName + '.module.ts');
57+
} else if (host.exists(modulePath + '-module.ts')) {
58+
return normalize(modulePath + '-module.ts');
59+
} else if (host.exists(modulePath + '/' + moduleBaseName + '-module.ts')) {
60+
return normalize(modulePath + '/' + moduleBaseName + '-module.ts');
5761
} else {
5862
throw new Error(`Specified module path ${modulePath} does not exist`);
5963
}
@@ -66,8 +70,8 @@ export function findModuleFromOptions(
6670
export function findModule(host: Tree, generateDir: string): Path {
6771
let dir: DirEntry | null = host.getDir('/' + generateDir);
6872

69-
const moduleRe = /\.module\.ts$/;
70-
const routingModuleRe = /-routing\.module\.ts/;
73+
const moduleRe = /(\.|-)module\.ts$/;
74+
const routingModuleRe = /-routing(\.|-)module\.ts/;
7175

7276
while (dir) {
7377
const matches = dir.subfiles.filter(

0 commit comments

Comments
 (0)